From 4d1fb059d1192cccdd4bf69bc67d1afc3c0dd6ce Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Tue, 13 Aug 2013 13:14:03 +0200 Subject: [PATCH] Tests reproducing #96 Handle optional parameters for constructor/method injection --- src/DI/Factory.php | 1 + tests/IntegrationTests/DI/Fixtures/Class1.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/DI/Factory.php b/src/DI/Factory.php index 14fedbb52..5b70899e0 100644 --- a/src/DI/Factory.php +++ b/src/DI/Factory.php @@ -116,6 +116,7 @@ private function injectConstructor(ReflectionClass $classReflection, MethodInjec . "' of the constructor of '{$classReflection->name}' has no type defined or guessable"); } + // TODO handle lazy injections! $args[] = $this->container->get($entryName); } diff --git a/tests/IntegrationTests/DI/Fixtures/Class1.php b/tests/IntegrationTests/DI/Fixtures/Class1.php index 4ae186749..8c6acbce0 100644 --- a/tests/IntegrationTests/DI/Fixtures/Class1.php +++ b/tests/IntegrationTests/DI/Fixtures/Class1.php @@ -62,20 +62,30 @@ class Class1 /** * @param Class2 $param1 * @param Interface1 $param2 + * @throws \Exception */ - public function __construct(Class2 $param1, Interface1 $param2) + public function __construct(Class2 $param1, Interface1 $param2, $optional = true) { $this->constructorParam1 = $param1; $this->constructorParam2 = $param2; + + if ($optional !== true) { + throw new \Exception("Expected optional parameter to not be defined"); + } } /** * @Inject * @param Class2 $param1 + * @throws \Exception */ - public function method1(Class2 $param1) + public function method1(Class2 $param1, $optional = true) { $this->method1Param1 = $param1; + + if ($optional !== true) { + throw new \Exception("Expected optional parameter to not be defined"); + } } /**