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
1.1k
2
Share
Encourage TDD with PHP-VCR
Test First Approach with PHP-VCR
Ryo Tomidokoro
February 27, 2019
More Decks by Ryo Tomidokoro
See All by Ryo Tomidokoro
あるアーキテクチャ決定と その結果/architecture-decision-and-its-result
hanhan1978
2
620
開発者が知っておきたい複雑さの正体/where-the-complexity-comes-from
hanhan1978
8
3.5k
Spec Driven Development入門/spec_driven_development_for_learners
hanhan1978
2
1.8k
フロントエンドがTypeScriptなら、バックエンドはPHPでもいいじゃない/php-is-not-bad
hanhan1978
8
14k
どうすると生き残れないのか/how-not-to-survive
hanhan1978
17
15k
100分で本番デプロイ!Laravelで作るWebアプリケーション作成/100min_web_app_cicd
hanhan1978
1
260
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
3.6k
集中して作業する技術/how_to_work_deeply
hanhan1978
65
56k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
11
11k
Other Decks in Programming
See All in Programming
How Swift's Type System Guides AI Agents
koher
0
260
Running Swift without an OS
kishikawakatsumi
0
840
2026-03-27 #terminalnight 変数展開とコマンド展開でターミナル作業をスマートにする方法
masasuzu
0
330
実践ハーネスエンジニアリング #MOSHTech
kajitack
7
6.5k
Don't Prompt Harder, Structure Better
kitasuke
0
760
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
6
3.4k
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
2
420
レガシーPHP転生 〜父がドメインエキスパートだったのでDDD+Claude Codeでチート開発します〜
panda_program
0
920
t *testing.T は どこからやってくるの?
otakakot
1
600
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
240
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
140
煩雑なSkills管理をSoC(関心の分離)により解決する――関心を分離し、プロンプトを部品として育てるためのOSSを作った話 / Solving Complex Skills Management Through SoC (Separation of Concerns)
nrslib
4
930
Featured
See All Featured
KATA
mclloyd
PRO
35
15k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
Paper Plane (Part 1)
katiecoart
PRO
0
6.6k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
GitHub's CSS Performance
jonrohan
1032
470k
The browser strikes back
jonoalderson
0
970
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.4k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
120
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
440
A better future with KSS
kneath
240
18k
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