Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Encourage TDD with PHP-VCR
Search
Ryo Tomidokoro
February 27, 2019
Programming
2
790
Encourage TDD with PHP-VCR
Test First Approach with PHP-VCR
Ryo Tomidokoro
February 27, 2019
Tweet
Share
More Decks by Ryo Tomidokoro
See All by Ryo Tomidokoro
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.2k
B+木入門:PHPで理解する データベースインデックスの仕組み/b-plus-tree-101
hanhan1978
5
3.2k
ADRを一年運用してみた/our_story_about_adr
hanhan1978
4
1.3k
PHPで学ぶ Session の基本と応用 / web-app-session-101-2024
hanhan1978
12
4.7k
レガシー回避のPHP開発術/avoid_php_legacy
hanhan1978
14
11k
Laravel Collectionの計算量を調べてみた2023/laravel_collection_time_complexity_2023
hanhan1978
0
850
PHP で学ぶ Cache の距離の話 / study_cache_with_php
hanhan1978
7
1.8k
Laravel を低速化する技術 / how to slow laravel
hanhan1978
1
3k
俺の Laravel がこんなに速いわけがない! / My Laravel Too Fast
hanhan1978
0
1.6k
Other Decks in Programming
See All in Programming
コードレビューで学ぶ!Kotlinオブジェクト指向デザインパターン
akkie76
2
180
Front-end application development, Symfony-style(s)
dunglas
2
1.9k
雑に思考を整理する技術と効能
konifar
55
25k
Folding Cheat Sheet #1
philipschwarz
PRO
0
210
Ruby GitHub Packages
bkuhlmann
0
620
二郎系ラーメンのコールで学ぶ AST 解析
memory1994
PRO
7
1.7k
CircleCIを活用して AWSへの継続的デリバリーを 実践する
coconala_engineer
1
230
Folding Cheat Sheet #3
philipschwarz
PRO
0
110
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
3
270
ONE WEDGE_company_guide
1wedge_one
0
380
チーム力を高めるスクラム実践法:カンバン公開と課題攻略について - ニフティのスクラムトーク Vol. 2 - NIFTY Tech Talk #18
niftycorp
PRO
1
110
脱・初心者!脱・マネコン!AWS CDKを使ってみませんか!?
har1101
0
300
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
Gamification - CAS2011
davidbonilla
76
4.6k
A Modern Web Designer's Workflow
chriscoyier
688
190k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
For a Future-Friendly Web
brad_frost
171
8.9k
A better future with KSS
kneath
231
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
1
3.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
13
1.5k
Designing for humans not robots
tammielis
247
25k
Building Adaptive Systems
keathley
30
1.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
39
4.4k
The Pragmatic Product Professional
lauravandoore
24
5.8k
Transcript
Encourage TDD With PHP-VCR Ryo Tomidokoro PHP Study 2019/2/27 @hanhan1978
PHP-VCR?
https://php-vcr.github.io/
VCR?
Video Casset Recorder
How to Use
PHP-VCR | Record HTTP interactions while testing https://php-vcr.github.io/
Record Response
Request & Response Recorded as YML
Replace API-Request to PHP-VCR -> Easy way to tests HTTP
Request. -> Faster than actual HTTP Request.
When to Use
Let’s say you have a legacy app
Legacy App
Replace external API with PHP-VCR
Legacy App now becomes testable
But, wait
Shouldn’t we use mock?
Desired Architecture
Of course we prefer mock
A chiken or egg situation - Loosely coupled architecture is
desirable - Legacy app have a long way to achieve it
No tests until good architecture?
Yes
Test First
Create tests for the legacy app with PHP-VCR It’s will
support your refactoring until you achive your desirable architecture.
How to Bent Wood | Ahoy! http://www.ventspleen.com/how-to-bend-wood/ It’s a jig
for a legacy app
When refactoring ends - You can choose wheather to use
Mock or PHP-VCR - PHP-VCR is a great tool guiding you to achieve a better software architecture.
Precaution
Needs soap extension Example setup for CircleCI 2.0
Headers match may be too strict Development environment & CI
environment might use slightly diffrent version of UserAgent. Ignore strict headers match at this situation.
curl_getinfo is not recorded (yet) https://github.com/php-vcr/php-vcr/pull/210 It’s in PR, but
not yet merged. Using curl_getinfo, PHP-VCR will not work.
How PHP-VCR record Requests?
stream_wapper_register http://php.net/manual/en/function.stream-wrapper-register.php
Example
HTTP Request
HTTP Response
Capture HTTP Request & Replace Response
None
Replaced Response
Summary PHP-VCR allows you to write tests for legacy Apps.
Use ‘Test Fast’ approach to improve the software architecture
Thanks!! @hanhan1978 https://blog.hanhans.net Ryo Tomidokoro