Your SlideShare is downloading. ×
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

PHP Barcelona 2010 - Architecture and testability

64,528

Published on

Slides for my talk at PHP Barcelona 2010 on October 29th

Slides for my talk at PHP Barcelona 2010 on October 29th

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
64,528
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
64
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Architecture and testability Listen to your tests on steroids Giorgio Sironi
  • 2. Who I am
    • PHP freelancer from 2005, software architect @ Allbus
    • 3. Writer for DZone[, php|architect]
    • 4. Bachelor of Computer Engineering @ PoliMi cum laude
  • 5. This talk
    • Maintainability, and why testing
    • 6. Various techniques to favor ease of testing AND maintainability
  • 7. What is maintainability?
    • Being ready to change!
    • 8. …but not too much
    • 9. Taking the first bullet
  • 10. Favored by maintainability
    • New requirements
    • 11. Evolving requirements
    • 12. Iterative development (Agile)
    • 13. Long-term maintenance
  • 14. Kinds of tests
    • Unit tests (1 object)
    • 15. Functional tests (N objects), end-to-end tests (All objects)
    • 16. Integration tests (external resources)
  • 17. Maintainability (1 of 2)
      SOLID principles (not all of them)
    • Single responsibility
    • 18. Open/closed
    • 19. Dependency Inversion
  • 20. Maintainability (2 of 2)
      Loose coupling High cohesion Information hiding ...needed from day 1, like readability and testability
  • 21.
      That was the boring part...
  • 22. Good but...
      Good buzzwords, but how do I apply that in practice?
  • 23. Testing first
    • Testing first -> Testable code
    • 24. Testable code -> Maintainable code
    • 25. Maintainable code -> Happy programmer
  • 26. Problems with tests
    • A test is slow?
    • 27. A test is brittle?
    • 28. A test is difficult to write?
  • 29. Solution to problems with tests
      Change the design to ease testing ( listen to your tests )
  • 30. Examples of listening to the tests
    • Small tests => high cohesion
    • 31. Unit tests => loose coupling
    • 32. Fast tests => in-memory isolation
    • 33. 4 pillars...
  • 34. 1. Dependency injection
    • No new operators outside of Factories
    • 35. Easy to change lifecycles and implementations
  • 36. 1. Dependency Injection (without) <?php class Ferrari { private $engine ; public function __construct () { $this ->engine = new Engine (); } }
  • 37. 1. Dependency Injection (with) <?php class Ferrari { private $engine ; public function __construct (Engine $engine ) { $this ->engine = $engine ; } }
  • 38. 2. Avoid static methods
    • Explicit concepts as objects
    • 39. Orthogonality of collaboration
  • 40. 2. Avoid static methods (before) <?php class Collection { public function find ( $key ) { Sorter:: sort ( $this ); // ..search stuff } }
  • 41. 2. Avoid using static methods (after) <?php class Collection { public function find ( $key ) { $this ->sorter-> sort ( $this ); // ..search stuff } }
  • 42. 3. Law of Demeter
    • Do not walk the... arrows
    • 43. Or: don't talk to strangers
  • 44. 3. Law of Demeter (without) <?php class PC { public function powerOn () { $this ->mobo->cpu->cache -> powerOn (); } }
  • 45. 3. Law of Demeter (with) <?php class PC { public function powerOn () { foreach ( $this ->powered as $item ) { /** @var Powered $item */ $item -> powerOn (); } } }
  • 46. 3. Law of Demeter (with) <?php class PC { public function powerOn () { $this ->mobo-> powerOn (); } }
  • 47. 4. Singleton vs. Factory
    • A Singleton is hard to mock
    • 48. Hidden dependency
    • 49. Global state
  • 50. 4. Singleton vs. Factory <?php class Authenticator { public function login ( $user , $pass ) { Db:: select (...); } }
  • 51. 4. Singleton vs. Factory <?php class Authenticator { public function __construct (Db $db ) { ... } public function login ( $user , $pass ) { $this ->db-> select (...); } }
  • 52. Be honest
    • If you need something, inject it (or inject its factory)
    • 53. Telling is better than looking around
    • 54. Tests are a recipe for clean code
  • 55. TDD is...
      Test-Driven Development Design
  • 56. References
    • Guide: Writing Testable Code (Misko Hevery)
    • 57. Growing Object-Oriented Software, Guided by Tests – Freeman, Price #goos
  • 58. Contacts
    • Personal blog: http://giorgiosironi.blogspot.com
    • 59. On Twitter: @giorgiosironi
  • 60. Questions? Q/A

×