The framework as an implementation detail

7,130 views

Published on

What would your application look like if it were written by the people who write the testing frameworks? If unit tests make classes more modular, by forcing you to test it in isolation, then what is the effect of expanding this to a less granular level, the acceptance and functional test. The more modern application architecture evolves, the more we hear the very old patterns being rediscovered and re-adopted. 1979 Trygve's MVC is a classic example, so are the SOLID principles. In this talk we will look on how Symfony allows for a really decoupled, easy to test application, by following on the footsteps of Alistair Cockburn's hexagonal architecture.

Published in: Technology, Health & Medicine

The framework as an implementation detail

  1. 1. The Framework as an Implementation Detail MarcelloDuarte/KonstantinKudryashov
  2. 2. @_md @everzet a SensioLabsEvent Aboutus @_md MarcelloDuarteHEAD OFTRAINING, INVIQA @everzet KonstantinKudryashovBDD PRACTICE MANAGER, INVIQA
  3. 3. @_md @everzet a SensioLabsEvent Thistalk [ Convenience ] [ Choices ] [ Future ]
  4. 4. @_md @everzet a SensioLabsEvent Choice Convenience http://www.flickr.com/photos/johnwinkelman/6200402992/
  5. 5. @_md @everzet a SensioLabsEvent We do love .
  6. 6. @_md @everzet a SensioLabsEvent Promise “A framework is‘just’one of the tools to help you develop better and faster” – Symfony documentation
  7. 7. @_md @everzet a SensioLabsEvent “The only way to go fast is to go well”– Uncle Bob FAST SLOW QUALITY SWITCH
  8. 8. @_md @everzet a SensioLabsEvent Relativecostofrepair analysis design code test support
  9. 9. @_md @everzet a SensioLabsEvent Convenient vs Maintainable
  10. 10. @_md @everzet a SensioLabsEvent A framework is“convenient” when it makes choices for you BookController extends Controller AuthorsController extends ContainerAwareController
  11. 11. @_md @everzet a SensioLabsEvent The code is maintainable when the framework lets you make the choices
  12. 12. @_md @everzet a SensioLabsEvent Instabilityandabstractness instability abstractness
  13. 13. @_md @everzet a SensioLabsEvent The “convenient”code is usually not very testable
  14. 14. @_md @everzet a SensioLabsEvent Symfonycanbeconvenient public function updateAction($id) { $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('AcmeStoreBundle:Product')->find($id); if (!$product) { throw $this->createNotFoundException( 'No product found for id '.$id ); } $product->setName('New product name!'); $em->flush(); return $this->redirect($this->generateUrl('homepage')); }
  15. 15. @_md @everzet a SensioLabsEvent The“convenient”Controller tends to ask for more IntegrationTests
  16. 16. @_md @everzet a SensioLabsEvent IntegrationTests stinks of coupling
  17. 17. @_md @everzet a SensioLabsEvent Feedback Outer Quality Inner Quality AcceptanceTests UnitTests
  18. 18. @_md @everzet a SensioLabsEvent Choice Choices http://www.flickr.com/photos/tmartin/32010732/
  19. 19. @_md @everzet a SensioLabsEvent Should we alwaysTDD? what the Start Up said what the Craftsmen said
  20. 20. @_md @everzet a SensioLabsEvent We do Test Driven Design
  21. 21. @_md @everzet a SensioLabsEvent Design is about choices
  22. 22. @_md @everzet a SensioLabsEvent Design is a professional activity
  23. 23. @_md @everzet a SensioLabsEvent TDD is about communication
  24. 24. @_md @everzet a SensioLabsEvent TDD is about your stakeholders
  25. 25. @_md @everzet a SensioLabsEvent The developers in the team are also stakeholders
  26. 26. @_md @everzet a SensioLabsEvent TDD is for long term relationships
  27. 27. @_md @everzet a SensioLabsEvent Howmanydependenciescanyouspot? public function updateAction($id) { $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('AcmeStoreBundle:Product')->find($id); if (!$product) { throw $this->createNotFoundException( 'No product found for id '.$id ); } $product->setName('New product name!'); $em->flush(); return $this->redirect($this->generateUrl('homepage')); }
  28. 28. @_md @everzet a SensioLabsEvent Howmanydependenciescanyouspot? public function updateAction($id) { $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('AcmeStoreBundle:Product')->find($id); if (!$product) { throw $this->createNotFoundException( 'No product found for id '.$id ); } $product->setName('New product name!'); $em->flush(); return $this->redirect($this->generateUrl('homepage')); } Doctrine Redirect Router Model
  29. 29. @_md @everzet a SensioLabsEvent HexagonalArchitecture “The hexagon is not a hexagon because the number six is important, but rather to allow the people doing the drawing to have room to insert ports and adapters as they need” :) [Cockburn 08]
  30. 30. @_md @everzet a SensioLabsEvent http://www.flickr.com/photos/10849858@N00/2696404813
  31. 31. @_md @everzet a SensioLabsEvent http://www.flickr.com/photos/mac_users_guide/3680586328/
  32. 32. @_md @everzet a SensioLabsEvent your application
  33. 33. @_md @everzet a SensioLabsEvent web gui app your application usersideports test adapter
  34. 34. @_md @everzet a SensioLabsEvent web gui app your application usersideports test adapter datasideports dbaccess service in memory db
  35. 35. @_md @everzet a SensioLabsEvent HexagonalArchitecture Db rest Logs
  36. 36. @_md @everzet a SensioLabsEvent DependencyInversion Higher level modules should not depend on lower level details [Martin 02]
  37. 37. @_md @everzet a SensioLabsEvent Naiveimplementation controller use case utility uses uses
  38. 38. @_md @everzet a SensioLabsEvent DependencyInversion use case service adapter utility adapter service utility
  39. 39. @_md @everzet a SensioLabsEvent Choice Let’sseesomecode
  40. 40. @_md @everzet a SensioLabsEvent Choice Future
  41. 41. @_md @everzet a SensioLabsEvent Choice Thanks! joind.in/9331 github.com/MarcelloDuarte/hexagonal-symfony

×