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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
980
開発者が知っておきたい複雑さの正体/where-the-complexity-comes-from
hanhan1978
8
3.6k
Spec Driven Development入門/spec_driven_development_for_learners
hanhan1978
2
1.9k
フロントエンドが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
270
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
3.7k
集中して作業する技術/how_to_work_deeply
hanhan1978
65
57k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
11
11k
Other Decks in Programming
See All in Programming
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
390
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
390
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
140
iOS26時代の新規アプリ開発
yuukiw00w
0
210
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
310
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.2k
Migrations : C'est une question d'hygiène !
vinceamstoutz
0
2.4k
分析エージェント精度向上における データアナリストの役割
oura_shoya
0
130
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.3k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3k
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
170
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
4
940
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
140
Bash Introduction
62gerente
615
210k
Odyssey Design
rkendrick25
PRO
2
640
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
150
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
370
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
170
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
We Have a Design System, Now What?
morganepeng
55
8.2k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
710
First, design no harm
axbom
PRO
2
1.2k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
70
39k
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