Who does *really* do Test-Driven Development? Probably only a small minority. The presentation shows what code leads to complex tests and what you have to consider to make writing tests much easier - because not doing TDD is no excuse for not having tests at all.
34. Singleton with DI framework $binder->bind('Session') ->to('PhpSession')
35. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') Configure the binding
36. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance
37. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance
38. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection
39. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection Tell DI framework to inject required parameters on creation of Processor
40. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection Piece of cake to test: independent of PhpSession Tell DI framework to inject required parameters on creation of Processor