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
Behat Layered Cake - KaunasPHP
Search
Marek Matulka
January 14, 2015
Programming
2
300
Behat Layered Cake - KaunasPHP
Speed up Behat tests with a clever use of the layered architecture - KaunasPHP meetup edition!
Marek Matulka
January 14, 2015
Tweet
Share
More Decks by Marek Matulka
See All by Marek Matulka
Test Smarter, Not Harder
super_marek
0
41
Super Marek's Testing Strategy (LeedsPHP meetup)
super_marek
1
240
Applying DDD when building Drupal modules using Symfony components (DrupalCamp CS)
super_marek
1
1.1k
Mission (Im)possible: Quality Decoupled Code with Drupal 7 (PHP SW meetup)
super_marek
0
200
Mission (Im)possible: Quality Decoupled Code with Drupal 7 (Singapore PHP user group meetup)
super_marek
0
370
Flying in style without splashing out
super_marek
1
210
Mission (Im)possible: Quality Decoupled Code with Drupal 7 (DrupalCamp Scotland)
super_marek
0
140
Mission (Im)possible: Quality Decoupled Code with Drupal 7
super_marek
0
590
Modernising the Legacy (ZendCon)
super_marek
0
360
Other Decks in Programming
See All in Programming
Better Code Design in PHP
afilina
0
170
SwiftUI Viewの責務分離
elmetal
PRO
2
270
コミュニティ駆動 AWS CDK ライブラリ「Open Constructs Library」 / community-cdk-library
gotok365
2
240
楽しく向き合う例外対応
okutsu
0
660
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
200
DRFを少しずつ オニオンアーキテクチャに寄せていく DjangoCongress JP 2025
nealle
2
270
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
160
Jakarta EE meets AI
ivargrimstad
0
390
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
14
4.6k
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
3
1.2k
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
150
color-scheme: light dark; を完全に理解する
uhyo
7
490
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Building an army of robots
kneath
303
45k
Scaling GitHub
holman
459
140k
The Cult of Friendly URLs
andyhume
78
6.2k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.4k
Building Adaptive Systems
keathley
40
2.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
Navigating Team Friction
lara
183
15k
Agile that works and the tools we love
rasmusluckow
328
21k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Transcript
Behat Layered Cake KaunasPHP edition Kaunas, 14 Jan 2015
Labas vakaras!
@super_marek Marek Matulka
at SensioLabsUK Software Engineer
part of Inviqa Group SensioLabsUK
None
a tool that makes BDD possible
With Behat you can...
With Behat you can... ...write human-readable stories that describe behaviour
of your application.
With Behat you can... ...automate testing of your application’s behaviour
with human-readable examples.
With Behat you can... ...change behaviour of your application with
confidence.
None
Typical dev stack - Vagrant VM - Symfony framework -
mysql or mongodb storage - Linux/OS X host - scrutiniser-ci
A project
That’s sloooow!
Should I get a faster computer?
What is the problem?
Where’s the problem? it takes too much time
Where’s the problem? Guest VM
Where’s the problem? MySQL
Where’s the problem? MySQL inside Guest VM
Let’s try it on the host!
A project
(63 scenarios in 320 steps) vs
But!
What if... my project grows and I’ll have 3000+ steps?
What if I had 3000+ steps? 300 steps took over
10 minutes 3000 steps will take over 100 minutes! (inside guest VM)
What if I had 3000+ steps? 300 steps took over
1 minute 3000 steps will take over 10 minutes! (on host)
How to make it faster?
Disable xdebug extension 30-40% improvement
Replace slow modules with... Replace slow DB with fast in-memory
or file-system persistent storage
Example Controller
Example Controller
(short introduction to) Layered Architecture
Layered Architecture User Interface Application Domain Infrastructure
Dependency Inversion “High level modules should not depend on lower
level implementation” – Good old Uncle Bob
Dependency Inversion Policy Layer <interface> Policy Service Mechanism Layer <interface>
Mechanism Service Utility Layer
(short introduction to) Hexagonal Architecture
Hexagonal Architecture Browser Logs Database Auth Domain
Hexagonal Architecture UI Adapter Log Adapter Data Storage Adapter External
Data Adapter Domain
Hexagonal Architecture UI Adapter Log Adapter Data Storage Adapter Domain
UI client port log adapter port persistence layer port Data Provider Adapter data provider port
Hexagonal Architecture UI Adapter Log Adapter Test Adapter Test Adapter
Data Storage Adapter Test Adapter Domain External Data Adapter Test Adapter
How to do that?
Repository Interface Acme\Learning\Conference Acme\Learning\ConferenceRepository
Repository Interface Acme\Learning\Conference Acme\Learning\ConferenceRepository Domain Port
Describe Communication
Your controller
Spec Controller to use Interface
Spec Controller to use Interface Port
Implement your repository
Implement your repository Port Adapter
Register repository as a Service!
Add another Adapter
Implement your repository
Implement your repository Port Adapter
Register repository as a Service!
Configure the Test env
Prepare Test Infrastructure config_test.yml:
Configure dependency injection
How fast can it be?
MySql Inside Guest VM
MySql On Host
Mocked Storage Inside Guest VM
Mocked Storage On Host
Things to remember
Hexagonal Architecture UI Adapter Log Adapter Test Adapter Test Adapter
Data Storage Adapter Test Adapter Domain External Data Adapter Test Adapter
Integration tests Don’t forget to test your adapters! Use PhpUnit
for that.
Talk to me after presentation! Demo
Questions?
Thank you! https://speakerdeck.com/super_marek @super_marek