Php day2010

Embed Size (px)

Citation preview

Architettura e testabilit(Architecture and testability)Listen to your tests on steroids Giorgio Sironi

Who am I

PHP freelancer from 2005

Writer for php|architect, DZone

Perito informatico, undergraduate in Engineering at Politecnico di Milano

This talk

Maintainability, and why testing

Various techniques to favor ease of testing AND maintainability

Slides in English (test d'unit, Legge di Demetra...)

Other talks

Dependency Injection

Testare l'ignoto

Agile software lifecycle

What is maintainability?

Being ready to change!but not too much

Taking the first bullet

Favored by maintainability

New requirements

Evolving requirements

Iterative development

Long-term maintenance

Kinds of tests

Unit tests

Integration tests

Acceptance (end-to-end) tests and functional tests

Maintainability (1 of 2)

SOLID principles (not all of them)Single responsibility

Open/closed

Dependency Inversion

Maintainability (2 of 2)

Loose couplingHigh cohesionInformation hidingOrthogonality...needed from day 1, like readability and testability

Good but...

Good buzzwords, but how do I apply that in practice?

Testing first

Testing first Testable code

Testable code Maintainable code

Problems with tests

A test is slow?

A test is brittle?

A test is difficult to write?

Solution to problems with tests

Change the design to ease testing (listen to your tests)

Test must change too

Good: test suite

Bad: no test suite

Worse: unmaintainable test suite

Examples of listening to the tests

Small tests => high cohesion

Unit tests => loose coupling4 pillars...

1. Dependency injection

No new operator outside of Factories

Easy to change lifecycles and implementations

1. Dependency Injection (without)