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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ryo Tomidokoro
February 27, 2019
Programming
2
1.1k
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
開発者が知っておきたい複雑さの正体/where-the-complexity-comes-from
hanhan1978
8
3.3k
Spec Driven Development入門/spec_driven_development_for_learners
hanhan1978
2
1.5k
フロントエンドがTypeScriptなら、バックエンドはPHPでもいいじゃない/php-is-not-bad
hanhan1978
8
13k
どうすると生き残れないのか/how-not-to-survive
hanhan1978
17
14k
100分で本番デプロイ!Laravelで作るWebアプリケーション作成/100min_web_app_cicd
hanhan1978
1
240
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
3.4k
集中して作業する技術/how_to_work_deeply
hanhan1978
65
54k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
11
11k
ADRを一年運用してみた/adr_after_a_year
hanhan1978
8
4.7k
Other Decks in Programming
See All in Programming
Data-Centric Kaggle
isax1015
2
780
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.6k
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.2k
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
390
Architectural Extensions
denyspoltorak
0
290
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
180
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
580
AI巻き込み型コードレビューのススメ
nealle
2
350
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
130
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
3.9k
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
290
Featured
See All Featured
BBQ
matthewcrist
89
10k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
440
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
The Cult of Friendly URLs
andyhume
79
6.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
The Invisible Side of Design
smashingmag
302
51k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.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