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
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
1.3k
開発者が知っておきたい複雑さの正体/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
280
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
3.7k
集中して作業する技術/how_to_work_deeply
hanhan1978
65
58k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
11
11k
Other Decks in Programming
See All in Programming
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
120
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
250
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.3k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
880
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
360
CSC307 Lecture 17
javiergs
PRO
0
320
Vite+ Unified Toolchain for the Web
naokihaba
0
320
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
The NotImplementedError Problem in Ruby
koic
1
830
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
180
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
6.7k
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
860
Paper Plane (Part 1)
katiecoart
PRO
0
9.1k
Into the Great Unknown - MozCon
thekraken
41
2.6k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
330
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
440
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
My Coaching Mixtape
mlcsv
0
150
エンジニアに許された特別な時間の終わり
watany
107
250k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
Mind Mapping
helmedeiros
PRO
1
250
WCS-LA-2024
lcolladotor
0
650
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
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