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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Ryo Tomidokoro
February 27, 2019
Programming
2
1.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
開発者が知っておきたい複雑さの正体/where-the-complexity-comes-from
hanhan1978
8
3.4k
Spec Driven Development入門/spec_driven_development_for_learners
hanhan1978
2
1.7k
フロントエンドが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
250
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
3.5k
集中して作業する技術/how_to_work_deeply
hanhan1978
65
55k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
11
11k
ADRを一年運用してみた/adr_after_a_year
hanhan1978
8
4.8k
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
940
API Platformを活用したPHPによる本格的なWeb API開発 / api-platform-book-intro
ttskch
1
150
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
1.1k
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
140
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
160
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
140
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
140
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
380
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
3
410
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
500
飯MCP
yusukebe
0
220
Pythonデータ分析コトハジメinFukuoka
kanan
0
100
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
110
GraphQLとの向き合い方2022年版
quramy
50
14k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
91
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Skip the Path - Find Your Career Trail
mkilby
1
88
What's in a price? How to price your products and services
michaelherold
247
13k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Evolving SEO for Evolving Search Engines
ryanjones
0
170
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
260
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The Curse of the Amulet
leimatthew05
1
10k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
320
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