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
930
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
100分で本番デプロイ!Laravelで作るWebアプリケーション作成/100min_web_app_cicd
hanhan1978
1
60
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
6
1.9k
集中して作業する技術/how_to_work_deeply
hanhan1978
62
46k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
11
9.7k
ADRを一年運用してみた/adr_after_a_year
hanhan1978
8
3.8k
B+木入門:PHPで理解する データベースインデックスの仕組み/b-plus-tree-101
hanhan1978
5
4.9k
ADRを一年運用してみた/our_story_about_adr
hanhan1978
5
2.1k
PHPで学ぶ Session の基本と応用 / web-app-session-101-2024
hanhan1978
13
5.7k
レガシー回避のPHP開発術/avoid_php_legacy
hanhan1978
17
13k
Other Decks in Programming
See All in Programming
Rubyと自由とAIと
yotii23
3
560
楽しく向き合う例外対応
okutsu
0
580
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
150
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
950
メンテが命: PHPフレームワークのコンテナ化とアップグレード戦略
shunta27
0
290
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
5
930
Unity Android XR入門
sakutama_11
0
180
もう少しテストを書きたいんじゃ〜 #phpstudy
o0h
PRO
14
2k
負債になりにくいCSSをデザイナとつくるには?
fsubal
10
2.5k
GAEログのコスト削減
mot_techtalk
0
130
From the Wild into the Clouds - Laravel Meetup Talk
neverything
0
110
Code smarter, not harder - How AI Coding Tools Boost Your Productivity | Angular Meetup Berlin
danielsogl
0
100
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.2k
Building Applications with DynamoDB
mza
93
6.2k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
Embracing the Ebb and Flow
colly
84
4.6k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
How to train your dragon (web standard)
notwaldorf
91
5.9k
Thoughts on Productivity
jonyablonski
69
4.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
Documentation Writing (for coders)
carmenintech
67
4.6k
Done Done
chrislema
182
16k
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