Your SlideShare is downloading. ×
0
Appetite comes with testing     “Its a dangerous business, Frodo, going out     your door. You step onto the road, and if ...
Defect Cost IncreaseChange begins with awareness
Defect Cost IncreaseChange begins with awareness
Stress cycleChange begins with awareness
Testing as...      documentationChange begins with awareness
Testing as...        instrument for          cooperationChange begins with awareness
Testing as...        instrument for         open source         cooperationChange begins with awareness
Pair programmingChange begins with awareness
All begins with...   ...a needChange begins with awareness
And... “Supporting multiple user classes is not easy at all. It would make the bundle code far more complex as we would ba...
But...  In Symfony2, all core classes use the service container,  so it is easy to extend, configure and use any object   ...
Service Container                  Dependency Injection Container          use AcmeHelloBundleMailer;          $mailer = n...
Service Container                  Dependency Injection Container          class Mailer          {              private $m...
Service Container                  Dependency Injection Container          class HelloController extends Controller       ...
FOSUserBundle             fos_user:                 db_driver: orm                 firewall_name: main                 use...
FOSUserBundle             fos_user:                 db_driver: orm                 firewall_name: main                 use...
So ...          We have to create our custom          UserManager that accepts in the          constructor an object that ...
First of all: test          We start writing some functional          tests to check correct integration          of FOSUs...
Now we feel good          We can extends FOSUser without pain          improving changes step by stepChange begins with aw...
Custom UserManager Class UserManager extends FOSUserBundleEntityUserManager {     protected $userDiscriminator;     public...
UserDiscriminator              public function getClass()              {                 return Acme/UserBundle/Entity/Use...
From here its all smooth          With little iterations, we improve          UserManager and UserDiscriminator          w...
NmnMultiUserBundle     fos_user:         db_driver: orm         firewall_name: main         user_class: AcmeUserBundleEnti...
NmnMultiUserBundle  parameters:    nmn_user_discriminator_parameters:      classes:          user_one:              entity...
NmnMultiUserBundle     Ok, it is an hack :)     A lazy way to use for free most of the     functionality of FOSUserBundle ...
NmnMultiUserBundle        github.com/netmeansnet/NmnMultiUserBundle        github.com/netmeansnet/NmnMultiUserBundleSandbo...
Some Books                       The Clean Coder                       A code of Conduct for Professional Programmers     ...
Some Books                       Extreme Programming Explained                       Embrace Change                       ...
Some Books                       The Grumpy Programmers Guide To Building                       Testable Applications in P...
Upcoming SlideShare
Loading in...5
×

Appetite comes with testing

513

Published on

An overview of the benefits of testing and a secure adventure: Test Driven Development of NmnMultiUserBundle

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

  • Be the first to like this

No Downloads
Views
Total Views
513
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Appetite comes with testing"

  1. 1. Appetite comes with testing “Its a dangerous business, Frodo, going out your door. You step onto the road, and if you dont keep your feet, theres no knowing where you might be swept off to.” J.R.R. Tolkien, The Lord of the RingsChange begins with awareness
  2. 2. Defect Cost IncreaseChange begins with awareness
  3. 3. Defect Cost IncreaseChange begins with awareness
  4. 4. Stress cycleChange begins with awareness
  5. 5. Testing as... documentationChange begins with awareness
  6. 6. Testing as... instrument for cooperationChange begins with awareness
  7. 7. Testing as... instrument for open source cooperationChange begins with awareness
  8. 8. Pair programmingChange begins with awareness
  9. 9. All begins with... ...a needChange begins with awareness
  10. 10. And... “Supporting multiple user classes is not easy at all. It would make the bundle code far more complex as we would basically need to change all places interacting with the user to be able to handle all user classes. I dont really want to go this way (it will also make it more likely to introduce bugs).” ...a delusionChange begins with awareness
  11. 11. But... In Symfony2, all core classes use the service container, so it is easy to extend, configure and use any object ...a hopeChange begins with awareness
  12. 12. Service Container Dependency Injection Container use AcmeHelloBundleMailer; $mailer = new Mailer(sendmail); $mailer->send(info@netmeans.net, ... );Change begins with awareness
  13. 13. Service Container Dependency Injection Container class Mailer { private $mailerType; public function __construct($mailerType) { $this->mailerType = $mailerType } public function send($to, ...) { ... } } services: my_mailer: class: AcmeHelloBundleMailer arguments: [sendmail]Change begins with awareness
  14. 14. Service Container Dependency Injection Container class HelloController extends Controller { public function sendEmailAction() { $mailer = $this->get(my_mailer); $mailer->send(info@netmeans.net, ... ); } }Change begins with awareness
  15. 15. FOSUserBundle fos_user: db_driver: orm firewall_name: main user_class: AcmeUserBundleEntityUserChange begins with awareness
  16. 16. FOSUserBundle fos_user: db_driver: orm firewall_name: main user_class: AcmeUserBundleEntityUser service: user_manager: custom_user_managerChange begins with awareness
  17. 17. So ... We have to create our custom UserManager that accepts in the constructor an object that have the responsibility to discriminate user types...a solutionChange begins with awareness
  18. 18. First of all: test We start writing some functional tests to check correct integration of FOSUserBundleChange begins with awareness
  19. 19. Now we feel good We can extends FOSUser without pain improving changes step by stepChange begins with awareness
  20. 20. Custom UserManager Class UserManager extends FOSUserBundleEntityUserManager { protected $userDiscriminator; public function __construct(..., UserDiscriminator $userDiscriminator) public function getClass() { return $this->userDiscriminator->getClass(); } }Change begins with awareness
  21. 21. UserDiscriminator public function getClass() { return Acme/UserBundle/Entity/UserOne; }Change begins with awareness
  22. 22. From here its all smooth With little iterations, we improve UserManager and UserDiscriminator with unit and functional tests, passing from a dirty code to a more elegant oneChange begins with awareness
  23. 23. NmnMultiUserBundle fos_user: db_driver: orm firewall_name: main user_class: AcmeUserBundleEntityUser service: user_manager: nmn_user_manager registration: form: handler: nmn_user_registration_form_handler profile: form: handler: nmn_user_profile_form_handlerChange begins with awareness
  24. 24. NmnMultiUserBundle parameters: nmn_user_discriminator_parameters: classes: user_one: entity: AcmeUserBundleEntityUserOne registration: AcmeUserBundleFormTypeRegistrationUserOneFormType profile: AcmeUserBundleFormTypeProfileUserOneFormType factory: user_two: entity: AcmeUserBundleEntityUserTwo registration: AcmeUserBundleFormTypeRegistrationUserTwoFormType profile: AcmeUserBundleFormTypeProfileUserTwoFormType factory:Change begins with awareness
  25. 25. NmnMultiUserBundle Ok, it is an hack :) A lazy way to use for free most of the functionality of FOSUserBundle ... ... but it is ready to be improved by anyone.Change begins with awareness
  26. 26. NmnMultiUserBundle github.com/netmeansnet/NmnMultiUserBundle github.com/netmeansnet/NmnMultiUserBundleSandbox travis-ci.org/#!/netmeansnet/NmnMultiUserBundle @leonardo_nmn @euxpomChange begins with awareness
  27. 27. Some Books The Clean Coder A code of Conduct for Professional Programmers Martin, Robert C.I know this sounds strident and unilateral, but given the record I dontthink the surgeons should have to defend hand-washing, and I dontthink programmers should have to defend TDDChange begins with awareness
  28. 28. Some Books Extreme Programming Explained Embrace Change Beck, KentIn software development, “perfect” is a verb, not an adjectiveIn XP, testing is as important as programmingChange begins with awareness
  29. 29. Some Books The Grumpy Programmers Guide To Building Testable Applications in PHP Hartjes, ChrisBuilding testable applications is HardThe reason for investing in automated testing is obvious: any bugs youcatch before your application makes it into production cost less in termsof resources (money, developer time) to fix than fixing it into productionChange begins with awareness
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×