Skip to content

Commit

Permalink
Tests reproducing #96 Handle optional parameters for constructor/meth…
Browse files Browse the repository at this point in the history
…od injection
  • Loading branch information
mnapoli committed Aug 13, 2013
1 parent 7a48aec commit 4d1fb05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/DI/Factory.php
Expand Up @@ -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);
}

Expand Down
14 changes: 12 additions & 2 deletions tests/IntegrationTests/DI/Fixtures/Class1.php
Expand Up @@ -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");
}
}

/**
Expand Down

0 comments on commit 4d1fb05

Please sign in to comment.