+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Appetite comes with testing
1. 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
Change begins with awareness
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 don't really want to
go this way (it will also make it more likely to introduce
bugs).”
...a delusion
Change begins with awareness
11. But...
In Symfony2, all core classes use the service container,
so it is easy to extend, configure and use any object
...a hope
Change begins with awareness
12. Service Container
Dependency Injection Container
use AcmeHelloBundleMailer;
$mailer = new Mailer('sendmail');
$mailer->send('info@netmeans.net', ... );
Change begins with awareness
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. 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. FOSUserBundle
fos_user:
db_driver: orm
firewall_name: main
user_class: AcmeUserBundleEntityUser
Change begins with awareness
16. FOSUserBundle
fos_user:
db_driver: orm
firewall_name: main
user_class: AcmeUserBundleEntityUser
service:
user_manager: custom_user_manager
Change begins with awareness
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 solution
Change begins with awareness
18. First of all: test
We start writing some functional
tests to check correct integration
of FOSUserBundle
Change begins with awareness
19. Now we feel good
We can extends FOSUser without pain
improving changes step by step
Change begins with awareness
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. UserDiscriminator
public function getClass()
{
return 'Acme/UserBundle/Entity/UserOne';
}
Change begins with awareness
22. 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
Change begins with awareness
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
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 don't
think the surgeons should have to defend hand-washing, and I don't
think programmers should have to defend TDD
Change begins with awareness
28. Some Books
Extreme Programming Explained
Embrace Change
Beck, Kent
In software development, “perfect” is a verb, not an adjective
In XP, testing is as important as programming
Change begins with awareness
29. Some Books
The Grumpy Programmer's Guide To Building
Testable Applications in PHP
Hartjes, Chris
Building testable applications is Hard
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
Change begins with awareness