Change begins with awareness
Appetite comes with testing
“It's a dangerous business, Frodo, going out
your door. You step ...
Change begins with awareness
Defect Cost Increase
Change begins with awareness
Defect Cost Increase
Change begins with awareness
Stress cycle
Change begins with awareness
Testing as...
documentation
Change begins with awareness
Testing as...
instrument for
cooperation
Change begins with awareness
Testing as...
instrument for
open source
cooperation
Change begins with awareness
Pair programming
Change begins with awareness
All begins with...
...a need
Change begins with awareness
And...
“Supporting multiple user classes is not easy at all. It would
make the bundle code fa...
Change begins with awareness
But...
In Symfony2, all core classes use the service container,
so it is easy to extend, conf...
Change begins with awareness
Service Container
Dependency Injection Container
use AcmeHelloBundleMailer;
$mailer = new Mai...
Change begins with awareness
Service Container
Dependency Injection Container
class Mailer
{
private $mailerType;
public f...
Change begins with awareness
Service Container
Dependency Injection Container
class HelloController extends Controller
{
p...
Change begins with awareness
FOSUserBundle
fos_user:
db_driver: orm
firewall_name: main
user_class: AcmeUserBundleEntityUs...
Change begins with awareness
FOSUserBundle
fos_user:
db_driver: orm
firewall_name: main
user_class: AcmeUserBundleEntityUs...
Change begins with awareness
So ...
...a solution
We have to create our custom
UserManager that accepts in the
constructor...
Change begins with awareness
First of all: test
We start writing some functional
tests to check correct integration
of FOS...
Change begins with awareness
Custom UserManager
Class UserManager extends FOSUserBundleEntityUserManager
{
protected $user...
Change begins with awareness
UserDiscriminator
public function getClass()
{
return 'Acme/UserBundle/Entity/UserOne';
}
Change begins with awareness
From here it's all smooth
With little iterations, we improve
UserManager and UserDiscriminato...
Change begins with awareness
NmnMultiUserBundle
fos_user:
db_driver: orm
firewall_name: main
user_class: AcmeUserBundleEnt...
Change begins with awareness
NmnMultiUserBundle
parameters:
nmn_user_discriminator_parameters:
classes:
user_one:
entity: ...
Change begins with awareness
NmnMultiUserBundle
Ok, it is an hack :)
A lazy way to use for free most of the
functionality ...
Change begins with awareness
NmnMultiUserBundle
github.com/netmeansnet/NmnMultiUserBundle
github.com/netmeansnet/NmnMultiU...
Change begins with awareness
Some Books
I know this sounds strident and unilateral, but given the record I don't
think the...
Some Books
In software development, “perfect” is a verb, not an adjective
Extreme Programming Explained
Embrace Change
Bec...
Change begins with awareness
Some Books
Building testable applications is Hard
The Grumpy Programmer's Guide To Building
T...
Upcoming SlideShare
Loading in …5
×

Appetite comes with testing

431 views
330 views

Published on

Slides of a talk at PUG Roma of few years ago.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
431
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Appetite comes with testing

  1. 1. Change begins with awareness Appetite comes with testing “It's a dangerous business, Frodo, going out your door. You step onto the road, and if you don't keep your feet, there's no knowing where you might be swept off to.” J.R.R. Tolkien, The Lord of the Rings
  2. 2. Change begins with awareness Defect Cost Increase
  3. 3. Change begins with awareness Defect Cost Increase
  4. 4. Change begins with awareness Stress cycle
  5. 5. Change begins with awareness Testing as... documentation
  6. 6. Change begins with awareness Testing as... instrument for cooperation
  7. 7. Change begins with awareness Testing as... instrument for open source cooperation
  8. 8. Change begins with awareness Pair programming
  9. 9. Change begins with awareness All begins with... ...a need
  10. 10. Change 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 basically need to change all places interacting with the user to be able to handle all user classes. I don't really want to go this way (it will also make it more likely to introduce bugs).” ...a delusion
  11. 11. Change begins with awareness But... In Symfony2, all core classes use the service container, so it is easy to extend, configure and use any object ...a hope
  12. 12. Change begins with awareness Service Container Dependency Injection Container use AcmeHelloBundleMailer; $mailer = new Mailer('sendmail'); $mailer->send('info@netmeans.net', ... );
  13. 13. Change begins with awareness 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]
  14. 14. Change begins with awareness Service Container Dependency Injection Container class HelloController extends Controller { public function sendEmailAction() { $mailer = $this->get('my_mailer'); $mailer->send('info@netmeans.net', ... ); } }
  15. 15. Change begins with awareness FOSUserBundle fos_user: db_driver: orm firewall_name: main user_class: AcmeUserBundleEntityUser
  16. 16. Change begins with awareness FOSUserBundle fos_user: db_driver: orm firewall_name: main user_class: AcmeUserBundleEntityUser service: user_manager: custom_user_manager
  17. 17. Change begins with awareness So ... ...a solution We have to create our custom UserManager that accepts in the constructor an object that have the responsibility to discriminate user types
  18. 18. Change begins with awareness First of all: test We start writing some functional tests to check correct integration of FOSUserBundle
  19. 19. Change begins with awareness Custom UserManager Class UserManager extends FOSUserBundleEntityUserManager { protected $userDiscriminator; public function __construct(..., UserDiscriminator $userDiscriminator) public function getClass() { return $this->userDiscriminator->getClass(); } }
  20. 20. Change begins with awareness UserDiscriminator public function getClass() { return 'Acme/UserBundle/Entity/UserOne'; }
  21. 21. Change begins with awareness From here it's all smooth With little iterations, we improve UserManager and UserDiscriminator with unit and functional tests, passing from a dirty code to a more elegant one
  22. 22. Change begins with awareness 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_handler
  23. 23. Change begins with awareness 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:
  24. 24. Change begins with awareness 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.
  25. 25. Change begins with awareness NmnMultiUserBundle github.com/netmeansnet/NmnMultiUserBundle github.com/netmeansnet/NmnMultiUserBundleSandbox travis-ci.org/#!/netmeansnet/NmnMultiUserBundle @leonardo_nmn @euxpom
  26. 26. Change begins with awareness Some Books I know this sounds strident and unilateral, but given the record I don't think the surgeons should have to defend hand-washing, and I don't think programmers should have to defend TDD The Clean Coder A code of Conduct for Professional Programmers Martin, Robert C.
  27. 27. Some Books In software development, “perfect” is a verb, not an adjective Extreme Programming Explained Embrace Change Beck, Kent Change begins with awareness In XP, testing is as important as programming
  28. 28. Change begins with awareness Some Books Building testable applications is Hard The Grumpy Programmer's Guide To Building Testable Applications in PHP Hartjes, Chris The reason for investing in automated testing is obvious: any bugs you catch before your application makes it into production cost less in terms of resources (money, developer time) to fix than fixing it into production

×