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
8
13k
どうすると生き残れないのか/how-not-to-survive
hanhan1978
17
14k
100分で本番デプロイ!Laravelで作るWebアプリケーション作成/100min_web_app_cicd
hanhan1978
1
200
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
3.1k
集中して作業する技術/how_to_work_deeply
hanhan1978
65
51k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
11
11k
ADRを一年運用してみた/adr_after_a_year
hanhan1978
8
4.4k
B+木入門:PHPで理解する データベースインデックスの仕組み/b-plus-tree-101
hanhan1978
5
5.6k
ADRを一年運用してみた/our_story_about_adr
hanhan1978
5
2.4k
Other Decks in Programming
See All in Programming
大規模アプリのDIフレームワーク刷新戦略 ~過去最大規模の並行開発を止めずにアプリ全体に導入するまで~
mot_techtalk
1
470
Building, Deploying, and Monitoring Ruby Web Applications with Falcon (Kaigi on Rails 2025)
ioquatix
4
2.3k
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
170
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
15
5.7k
タスクの特性や不確実性に応じた最適な作業スタイルの選択(ペアプロ・モブプロ・ソロプロ)と実践 / Optimal Work Style Selection: Pair, Mob, or Solo Programming.
honyanya
3
180
フロントエンド開発のためのブラウザ組み込みAI入門
masashi
5
2.2k
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
700
Six and a half ridiculous things to do with Quarkus
hollycummins
0
180
Devvox Belgium - Agentic AI Patterns
kdubois
1
130
Leading Effective Engineering Teams in the AI Era
addyosmani
7
470
XP, Testing and ninja testing ZOZ5
m_seki
3
720
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
200
Featured
See All Featured
Speed Design
sergeychernyshev
32
1.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
The Language of Interfaces
destraynor
162
25k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
910
Site-Speed That Sticks
csswizardry
13
910
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Agile that works and the tools we love
rasmusluckow
331
21k
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