Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Encourage TDD with PHP-VCR
Search
Ryo Tomidokoro
February 27, 2019
Programming
1.2k
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
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
2.3k
あるアーキテクチャ決定と その結果/architecture-decision-and-its-result
hanhan1978
2
1.8k
開発者が知っておきたい複雑さの正体/where-the-complexity-comes-from
hanhan1978
8
3.8k
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
300
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
3.9k
集中して作業する技術/how_to_work_deeply
hanhan1978
69
61k
Other Decks in Programming
See All in Programming
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
150
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
110
Building an Out-of-Order CPU
latte72
1
760
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
150
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
480
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
140
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
240
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
330
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
150
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
960
Foundry Localでエージェント開発
seosoft
0
190
Featured
See All Featured
Exploring anti-patterns in Rails
aemeredith
3
500
Building Applications with DynamoDB
mza
96
7.2k
Embracing the Ebb and Flow
colly
88
5.2k
Prompt Engineering for Job Search
mfonobong
0
450
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
YesSQL, Process and Tooling at Scale
rocio
174
15k
The Invisible Side of Design
smashingmag
301
52k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
640
Technical Leadership for Architectural Decision Making
baasie
3
560
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
GraphQLとの向き合い方2022年版
quramy
50
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