Slide 1

Slide 1 text

Behat Layered Cake KaunasPHP edition Kaunas, 14 Jan 2015

Slide 2

Slide 2 text

Labas vakaras!

Slide 3

Slide 3 text

@super_marek Marek Matulka

Slide 4

Slide 4 text

at SensioLabsUK Software Engineer

Slide 5

Slide 5 text

part of Inviqa Group SensioLabsUK

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

a tool that makes BDD possible

Slide 8

Slide 8 text

With Behat you can...

Slide 9

Slide 9 text

With Behat you can... ...write human-readable stories that describe behaviour of your application.

Slide 10

Slide 10 text

With Behat you can... ...automate testing of your application’s behaviour with human-readable examples.

Slide 11

Slide 11 text

With Behat you can... ...change behaviour of your application with confidence.

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Typical dev stack - Vagrant VM - Symfony framework - mysql or mongodb storage - Linux/OS X host - scrutiniser-ci

Slide 14

Slide 14 text

A project

Slide 15

Slide 15 text

That’s sloooow!

Slide 16

Slide 16 text

Should I get a faster computer?

Slide 17

Slide 17 text

What is the problem?

Slide 18

Slide 18 text

Where’s the problem? it takes too much time

Slide 19

Slide 19 text

Where’s the problem? Guest VM

Slide 20

Slide 20 text

Where’s the problem? MySQL

Slide 21

Slide 21 text

Where’s the problem? MySQL inside Guest VM

Slide 22

Slide 22 text

Let’s try it on the host!

Slide 23

Slide 23 text

A project

Slide 24

Slide 24 text

(63 scenarios in 320 steps) vs

Slide 25

Slide 25 text

But!

Slide 26

Slide 26 text

What if... my project grows and I’ll have 3000+ steps?

Slide 27

Slide 27 text

What if I had 3000+ steps? 300 steps took over 10 minutes 3000 steps will take over 100 minutes! (inside guest VM)

Slide 28

Slide 28 text

What if I had 3000+ steps? 300 steps took over 1 minute 3000 steps will take over 10 minutes! (on host)

Slide 29

Slide 29 text

How to make it faster?

Slide 30

Slide 30 text

Disable xdebug extension 30-40% improvement

Slide 31

Slide 31 text

Replace slow modules with... Replace slow DB with fast in-memory or file-system persistent storage

Slide 32

Slide 32 text

Example Controller

Slide 33

Slide 33 text

Example Controller

Slide 34

Slide 34 text

(short introduction to) Layered Architecture

Slide 35

Slide 35 text

Layered Architecture User Interface Application Domain Infrastructure

Slide 36

Slide 36 text

Dependency Inversion “High level modules should not depend on lower level implementation” – Good old Uncle Bob

Slide 37

Slide 37 text

Dependency Inversion Policy Layer Policy Service Mechanism Layer Mechanism Service Utility Layer

Slide 38

Slide 38 text

(short introduction to) Hexagonal Architecture

Slide 39

Slide 39 text

Hexagonal Architecture Browser Logs Database Auth Domain

Slide 40

Slide 40 text

Hexagonal Architecture UI Adapter Log Adapter Data Storage Adapter External Data Adapter Domain

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

Hexagonal Architecture UI Adapter Log Adapter Test Adapter Test Adapter Data Storage Adapter Test Adapter Domain External Data Adapter Test Adapter

Slide 43

Slide 43 text

How to do that?

Slide 44

Slide 44 text

Repository Interface Acme\Learning\Conference Acme\Learning\ConferenceRepository

Slide 45

Slide 45 text

Repository Interface Acme\Learning\Conference Acme\Learning\ConferenceRepository Domain Port

Slide 46

Slide 46 text

Describe Communication

Slide 47

Slide 47 text

Your controller

Slide 48

Slide 48 text

Spec Controller to use Interface

Slide 49

Slide 49 text

Spec Controller to use Interface Port

Slide 50

Slide 50 text

Implement your repository

Slide 51

Slide 51 text

Implement your repository Port Adapter

Slide 52

Slide 52 text

Register repository as a Service!

Slide 53

Slide 53 text

Add another Adapter

Slide 54

Slide 54 text

Implement your repository

Slide 55

Slide 55 text

Implement your repository Port Adapter

Slide 56

Slide 56 text

Register repository as a Service!

Slide 57

Slide 57 text

Configure the Test env

Slide 58

Slide 58 text

Prepare Test Infrastructure config_test.yml:

Slide 59

Slide 59 text

Configure dependency injection

Slide 60

Slide 60 text

How fast can it be?

Slide 61

Slide 61 text

MySql Inside Guest VM

Slide 62

Slide 62 text

MySql On Host

Slide 63

Slide 63 text

Mocked Storage Inside Guest VM

Slide 64

Slide 64 text

Mocked Storage On Host

Slide 65

Slide 65 text

Things to remember

Slide 66

Slide 66 text

Hexagonal Architecture UI Adapter Log Adapter Test Adapter Test Adapter Data Storage Adapter Test Adapter Domain External Data Adapter Test Adapter

Slide 67

Slide 67 text

Integration tests Don’t forget to test your adapters! Use PhpUnit for that.

Slide 68

Slide 68 text

Talk to me after presentation! Demo

Slide 69

Slide 69 text

Questions?

Slide 70

Slide 70 text

Thank you! https://speakerdeck.com/super_marek @super_marek