Testing and Symfony2
Tomasz Łopusiewicz
Tomasz Łopusiewicz
tabbi_89
tabbi89
tom@tabbi89.com
About me
Agenda
This talk will be about
The tools ExampleWhy Layers
Dlaczego chce powiedzieć o testach i 2 lata

Doodad logo tsh

Na samym koncu w example opisac legacy code z refaktorem
Should I test my application
Maybe
Will tests be
readable and
maintainable
Will
design
be betterWill code
be without
any bugs
Are there any
tools that will
help me
Will this
speed up my
development
New tools new techniques
The tools
BDD
TDD
Behat
phpspec
Codeception
layered architecture
domain model
…
Narzędzia pokażą nam drogę BDD tests
phpspec tests

Pojawiaja się znaki równa się
BEHAT=BDD
Google “symfony2 testing”
The tools
My code
The tools
Legacy code :)
And my first test …
The tools
PHPUnit + BrowserKit + DomCrawler
Google “behat+symfony2"
The tools
Behat + MinkExtension
Google “codeception+symfony2"
The tools
Codeception + Symfony2 module
phpspec
The tools
“specing” getters and setters
“specing" getters and setters
What is wrong
The tools
• We don’t know which tool we should use
• We use tools improperly
• We are too much focused on tools instead of business
values
• We are impatient (it takes time to write good test suites)
• Never stop learning :)
Lets start from the very beginning
Framework should help You
The tools
It is a controller for Your app
Don’t spread your logic
through controller
Each tool can be helpful in different level of You app
Tools summary
< Object level
Describing behaviour
< System level
Describing behaviour
System level
Object level
It is more about testing
System level
Object level
Describing with testing
Layered architecture
Layers
Rozprzężenie aplikacji zawsze jest ważne
dla utrzymywania kodu, stąd dla
nietrywialnych aplikacji jest to zasadne.
Layered tests
Layers
Production-like environment to verify the system as a whole.
This may include user interfaces, databases, web servers, logging etc.
Verifying that different units are working together.
It focuses on the interfaces between components.
Often integration tests ale slower than unit tests.
A unit test verifies a single behaviour of a single unit
A logical unit is something that can be reasoned about in isolation.
The test should omit the number of other units it touches on.
Should not touch any part outside of your own system.
Bad way
Example
Good way
Example
If you want to understand business and match their
expectations
• Start with conversation
• Prepare questions about system
• Use examples to correctly understand features
• After all write down all the scenarios You touched
during conversation
Our acceptance criteria in scenarios
Example
Logowanie, transakc
Start with planning process
Example
Testing service layer
Spec behaviour
Example
Result
Example
The end
Example
Use listeners for additional processes
Example
Integration test
Example
Requirements - transactions, loggers
Example
Yes, I should test my application not framework
Questions ?
Thanks for coming

Testing and symfony2