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
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
フロントエンドがTypeScriptなら、バックエンドはPHPでもいいじゃない/php-is-not-bad
hanhan1978
9
13k
どうすると生き残れないのか/how-not-to-survive
hanhan1978
17
14k
100分で本番デプロイ!Laravelで作るWebアプリケーション作成/100min_web_app_cicd
hanhan1978
1
180
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
2.9k
集中して作業する技術/how_to_work_deeply
hanhan1978
65
49k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
11
10k
ADRを一年運用してみた/adr_after_a_year
hanhan1978
8
4.3k
B+木入門:PHPで理解する データベースインデックスの仕組み/b-plus-tree-101
hanhan1978
5
5.3k
ADRを一年運用してみた/our_story_about_adr
hanhan1978
5
2.4k
Other Decks in Programming
See All in Programming
リッチエディターを安全に開発・運用するために
unachang113
1
310
[Codecon - 2025] Como não odiar seus testes
camilacampos
0
100
[DevinMeetupTokyo2025] コード書かせないDevinの使い方
takumiyoshikawa
2
230
Android 16KBページサイズ対応をはじめからていねいに
mine2424
0
810
NEWT Backend Evolution
xpromx
1
170
プロダクトという一杯を作る - プロダクトチームが味の責任を持つまでの煮込み奮闘記
hiliteeternal
0
300
Claude Code派?Gemini CLI派? みんなで比較LT会!_20250716
junholee
1
760
抽象化という思考のツール - 理解と活用 - / Abstraction-as-a-Tool-for-Thinking
shin1x1
1
890
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
720
DataformでPythonする / dataform-de-python
snhryt
0
110
AWS Summit Japan 2024と2025の比較/はじめてのKiro、今あなたは岐路に立つ
satoshi256kbyte
1
260
iOS開発スターターキットの作り方
akidon0000
0
230
Featured
See All Featured
The Language of Interfaces
destraynor
158
25k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
1k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
A Modern Web Designer's Workflow
chriscoyier
695
190k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Gamification - CAS2011
davidbonilla
81
5.4k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.1k
Fireside Chat
paigeccino
37
3.6k
How to Think Like a Performance Engineer
csswizardry
25
1.8k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Building an army of robots
kneath
306
45k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
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