Testing and symfony2

29
Testing and Symfony2 Tomasz Łopusiewicz

Transcript of Testing and symfony2

Page 1: Testing and symfony2

Testing and Symfony2Tomasz Łopusiewicz

Page 2: Testing and symfony2

Tomasz Łopusiewicz

tabbi_89

tabbi89

[email protected]

About me

Page 3: Testing and symfony2

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

Page 4: Testing and symfony2

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

Page 5: Testing and symfony2

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

Page 6: Testing and symfony2

Google “symfony2 testing”The tools

Page 7: Testing and symfony2

My codeThe tools

Legacy code :)

Page 8: Testing and symfony2

And my first test …The tools

PHPUnit + BrowserKit + DomCrawler

Page 9: Testing and symfony2

Google “behat+symfony2"The tools

Behat + MinkExtension

Page 10: Testing and symfony2

Google “codeception+symfony2"The tools

Codeception + Symfony2 module

Page 11: Testing and symfony2

phpspecThe tools

“specing” getters and setters

“specing" getters and setters

Page 12: Testing and symfony2

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 :)

Page 13: Testing and symfony2

Lets start from the very beginning

Page 14: Testing and symfony2

Framework should help YouThe tools

It is a controller for Your app Don’t spread your logic

through controller

Page 15: Testing and symfony2

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

Page 16: Testing and symfony2

Layered architectureLayers

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

Page 17: Testing and symfony2

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.

Page 18: Testing and symfony2

Bad wayExample

Page 19: Testing and symfony2

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

Page 20: Testing and symfony2

Our acceptance criteria in scenariosExample

Logowanie, transakcyjność

Page 21: Testing and symfony2

Start with planning processExample

Testing service layer

Page 22: Testing and symfony2

Spec behaviourExample

Page 23: Testing and symfony2

ResultExample

Page 24: Testing and symfony2

The endExample

Page 25: Testing and symfony2

Use listeners for additional processesExample

Page 26: Testing and symfony2

Integration testExample

Page 27: Testing and symfony2

Requirements - transactions, loggersExample

Page 28: Testing and symfony2

Yes, I should test my application not framework

Page 29: Testing and symfony2

Questions ?

Thanks for coming