Testing and symfony2

Post on 18-Jan-2017

1.045 views 0 download

Transcript of Testing and symfony2

Testing and Symfony2Tomasz Łopusiewicz

Tomasz Łopusiewicz

tabbi_89

tabbi89

tom@tabbi89.com

About me

AgendaThis talk will be about

The tools ExampleWhy Layers

Dlaczego chce powiedzieć o testach i 2 lataDoodad logo tshNa 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 codeThe 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

phpspecThe tools

“specing” getters and setters

“specing" getters and setters

What is wrongThe 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 YouThe 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 appTools 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 architectureLayers

Rozprzężenie aplikacji zawsze jest ważne dla utrzymywania kodu, stąd dla nietrywialnych aplikacji jest to zasadne.

Layered testsLayers

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 wayExample

Good wayExample

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 scenariosExample

Logowanie, transakcyjność

Start with planning processExample

Testing service layer

Spec behaviourExample

ResultExample

The endExample

Use listeners for additional processesExample

Integration testExample

Requirements - transactions, loggersExample

Yes, I should test my application not framework

Questions ?

Thanks for coming