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
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.2k
あるアーキテクチャ決定と その結果/architecture-decision-and-its-result
hanhan1978
2
1.7k
開発者が知っておきたい複雑さの正体/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
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.5k
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
130
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
3
340
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
340
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
170
What We Talk About When We Talk About XP
m_seki
2
380
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
500
ALB ログから Trace を気合で繋げる技術
fohte
7
880
初めての模倣学習とVLA
natsutan
0
490
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
590
Seeing Through Serverless: Observability for AWS Lambda with ADOT and CloudWatch Application Signals
seike460
PRO
1
120
PyO3 で既存 Python 評価器を Rust core 化する ー wasm-bindgen でブラウザにも配るための設計
kdash
1
490
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.8k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
290
Navigating Team Friction
lara
192
16k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
250
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
410
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
400
The agentic SEO stack - context over prompts
schlessera
0
900
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
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