From 691042e2549995178fe7528cccd1b90d4629c204 Mon Sep 17 00:00:00 2001
From: Chuck Hagenbuch
Date: Sun, 16 May 2010 22:00:39 -0400
Subject: [PATCH] Replace the ImplementationWithSetters binder with an
AnnotatedSetters binder that can be stacked on any other binder.
Also add examples for the annotated setters and closure binders.
---
framework/Injector/doc/Horde/Injector/Readme.html | 19 ----
.../examples/Horde/Injector/annotatedsetters.php | 39 ++++++++
.../Injector/examples/Horde/Injector/binder.php | 2 +-
.../Injector/examples/Horde/Injector/closure.php | 42 +++++++++
.../Injector/examples/Horde/Injector/factory.php | 2 +-
.../examples/Horde/Injector/implementation.php | 4 +-
.../Injector/examples/Horde/Injector/setget.php | 2 +-
.../lib/Horde/Injector/Binder/AnnotatedSetters.php | 103 +++++++++++++++++++++
.../Injector/lib/Horde/Injector/Binder/Closure.php | 1 -
.../lib/Horde/Injector/Binder/Implementation.php | 69 ++------------
.../Injector/Binder/ImplementationWithSetters.php | 56 -----------
.../lib/Horde/Injector/DependencyFinder.php | 43 +++++++++
framework/Injector/lib/Horde/Injector/TopLevel.php | 4 +-
framework/Injector/package.xml | 8 +-
.../Horde/Injector/Binder/AnnotatedSettersTest.php | 56 +++++++++++
.../Horde/Injector/Binder/ImplementationTest.php | 70 +++++---------
.../Injector/test/Horde/Injector/BinderTest.php | 13 +--
.../Injector/test/Horde/Injector/InjectorTest.php | 5 +-
18 files changed, 337 insertions(+), 201 deletions(-)
create mode 100644 framework/Injector/examples/Horde/Injector/annotatedsetters.php
create mode 100644 framework/Injector/examples/Horde/Injector/closure.php
create mode 100644 framework/Injector/lib/Horde/Injector/Binder/AnnotatedSetters.php
delete mode 100644 framework/Injector/lib/Horde/Injector/Binder/ImplementationWithSetters.php
create mode 100644 framework/Injector/lib/Horde/Injector/DependencyFinder.php
create mode 100644 framework/Injector/test/Horde/Injector/Binder/AnnotatedSettersTest.php
diff --git a/framework/Injector/doc/Horde/Injector/Readme.html b/framework/Injector/doc/Horde/Injector/Readme.html
index bcee617fb..730983857 100644
--- a/framework/Injector/doc/Horde/Injector/Readme.html
+++ b/framework/Injector/doc/Horde/Injector/Readme.html
@@ -497,25 +497,6 @@ class DataSourceX $injector->bindImplementation('DataSourceInteface', 'DataSourceX')
- ->bindSetter('setLogger');
-
-class DataSourceX {
- public function __construct(DependencyY $dependencyY) {
- ...
- }
-
- public function setLogger(Logger $logger) {
- ...
- }
-}
-
-
-
-
Choosing a binder
Use a factory binder if:
diff --git a/framework/Injector/examples/Horde/Injector/annotatedsetters.php b/framework/Injector/examples/Horde/Injector/annotatedsetters.php
new file mode 100644
index 000000000..67a2ee9d2
--- /dev/null
+++ b/framework/Injector/examples/Horde/Injector/annotatedsetters.php
@@ -0,0 +1,39 @@
+
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * @link http://pear.horde.org/index.php?package=Injector
+ */
+
+require 'Horde/Autoloader.php';
+
+class Worker
+{
+ public $helper;
+
+ /**
+ * @inject
+ */
+ public function setHelper(Helper $h)
+ {
+ $this->helper = $h;
+ }
+}
+
+class Helper
+{
+ public function __toString()
+ {
+ return 'helper';
+ }
+}
+
+$a = new Horde_Injector(new Horde_Injector_TopLevel());
+$b = $a->getInstance('Worker');
+echo "$b->helper\n";
diff --git a/framework/Injector/examples/Horde/Injector/binder.php b/framework/Injector/examples/Horde/Injector/binder.php
index 5058aaf83..c7691ef00 100644
--- a/framework/Injector/examples/Horde/Injector/binder.php
+++ b/framework/Injector/examples/Horde/Injector/binder.php
@@ -12,7 +12,7 @@
* @link http://pear.horde.org/index.php?package=Injector
*/
-require_once 'Horde/Autoloader.php';
+require 'Horde/Autoloader.php';
/**
* A dummy binder.
diff --git a/framework/Injector/examples/Horde/Injector/closure.php b/framework/Injector/examples/Horde/Injector/closure.php
new file mode 100644
index 000000000..a00ce4e55
--- /dev/null
+++ b/framework/Injector/examples/Horde/Injector/closure.php
@@ -0,0 +1,42 @@
+
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * @link http://pear.horde.org/index.php?package=Injector
+ */
+
+if (version_compare(PHP_VERSION, '5.3', 'lt')) {
+ echo "PHP 5.3+ is required for the closure binder\n";
+ exit(1);
+}
+
+require 'Horde/Autoloader.php';
+
+class ClosureCreated
+{
+ public function __construct($msg)
+ {
+ $this->msg = $msg;
+ }
+ public function __toString()
+ {
+ return 'Foo: ' . $this->msg;
+ }
+}
+
+$closure = function(Horde_Injector $i) {
+ return new ClosureCreated('created by closure');
+};
+$binder = new Horde_Injector_Binder_Closure($closure);
+
+$a = new Horde_Injector(new Horde_Injector_TopLevel());
+$a->bindClosure('CC', $closure);
+
+$b = $a->getInstance('CC');
+echo "$b\n";
diff --git a/framework/Injector/examples/Horde/Injector/factory.php b/framework/Injector/examples/Horde/Injector/factory.php
index a4bd4e71c..f510fd289 100644
--- a/framework/Injector/examples/Horde/Injector/factory.php
+++ b/framework/Injector/examples/Horde/Injector/factory.php
@@ -11,7 +11,7 @@
* @link http://pear.horde.org/index.php?package=Injector
*/
-require_once 'Horde/Autoloader.php';
+require 'Horde/Autoloader.php';
class Greet
{
diff --git a/framework/Injector/examples/Horde/Injector/implementation.php b/framework/Injector/examples/Horde/Injector/implementation.php
index eb488eb5e..9e0afd1cb 100644
--- a/framework/Injector/examples/Horde/Injector/implementation.php
+++ b/framework/Injector/examples/Horde/Injector/implementation.php
@@ -1,6 +1,6 @@
setInstance('a', 'a');
diff --git a/framework/Injector/lib/Horde/Injector/Binder/AnnotatedSetters.php b/framework/Injector/lib/Horde/Injector/Binder/AnnotatedSetters.php
new file mode 100644
index 000000000..eb8e0ce3b
--- /dev/null
+++ b/framework/Injector/lib/Horde/Injector/Binder/AnnotatedSetters.php
@@ -0,0 +1,103 @@
+
+ * @author James Pepin
+ * @author Chuck Hagenbuch
+ * @category Horde
+ * @package Horde_Injector
+ */
+class Horde_Injector_Binder_AnnotatedSetters implements Horde_Injector_Binder
+{
+ /**
+ * @var Horde_Injector_Binder
+ */
+ private $_binder;
+
+ /**
+ * @var Horde_Injector_DependencyFinder
+ */
+ private $_dependencyFinder;
+
+ private $_setters = array();
+
+ /**
+ *
+ */
+ public function __construct(Horde_Injector_Binder $binder, Horde_Injector_DependencyFinder $dependencyFinder)
+ {
+ $this->_binder = $binder;
+ $this->_dependencyFinder = $dependencyFinder;
+ }
+
+ /**
+ * TODO
+ */
+ public function equals(Horde_Injector_Binder $otherBinder)
+ {
+ return false;
+ }
+
+ /**
+ * TODO
+ */
+ public function create(Horde_Injector $injector)
+ {
+ $instance = $this->_binder->create($injector);
+
+ $reflectionClass = new ReflectionClass(get_class($instance));
+ $this->_bindAnnotatedSetters($reflectionClass);
+ $this->_callSetters($injector, $instance);
+
+ return $instance;
+ }
+
+ /**
+ */
+ private function _bindAnnotatedSetters(ReflectionClass $reflectionClass)
+ {
+ foreach ($this->_findAnnotatedSetters($reflectionClass) as $setter) {
+ $this->_setters[] = $setter;
+ }
+ }
+
+ /**
+ * Find all public methods in $reflectionClass that are annotated with
+ * @inject.
+ *
+ * @param ReflectionClass $reflectionClass
+ *
+ * @return array
+ */
+ private function _findAnnotatedSetters(ReflectionClass $reflectionClass)
+ {
+ $setters = array();
+ foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
+ $docBlock = $reflectionMethod->getDocComment();
+ if ($docBlock) {
+ if (strpos($docBlock, '@inject') !== false) {
+ $setters[] = $reflectionMethod->name;
+ }
+ }
+ }
+
+ return $setters;
+ }
+
+ /**
+ * TODO
+ */
+ protected function _callSetters(Horde_Injector $injector, $instance)
+ {
+ foreach ($this->_setters as $setter) {
+ $reflectionMethod = new ReflectionMethod($instance, $setter);
+ $reflectionMethod->invokeArgs(
+ $instance,
+ $this->_dependencyFinder->getMethodDependencies($injector, $reflectionMethod)
+ );
+ }
+ }
+}
diff --git a/framework/Injector/lib/Horde/Injector/Binder/Closure.php b/framework/Injector/lib/Horde/Injector/Binder/Closure.php
index 29fa10d6b..9a528e42d 100644
--- a/framework/Injector/lib/Horde/Injector/Binder/Closure.php
+++ b/framework/Injector/lib/Horde/Injector/Binder/Closure.php
@@ -68,7 +68,6 @@ class Horde_Injector_Binder_Closure implements Horde_Injector_Binder
*/
public function create(Horde_Injector $injector)
{
-
$childInjector = $injector->createChildInjector();
$closure = $this->_closure;
return $closure($childInjector);
diff --git a/framework/Injector/lib/Horde/Injector/Binder/Implementation.php b/framework/Injector/lib/Horde/Injector/Binder/Implementation.php
index f188e3816..56f4b6fbb 100644
--- a/framework/Injector/lib/Horde/Injector/Binder/Implementation.php
+++ b/framework/Injector/lib/Horde/Injector/Binder/Implementation.php
@@ -12,20 +12,20 @@ class Horde_Injector_Binder_Implementation implements Horde_Injector_Binder
/**
* TODO
*/
- protected $_implementation;
+ private $_implementation;
/**
- * TODO
+ * @var Horde_Injector_DependencyFinder
*/
- protected $_setters;
+ private $_dependencyFinder;
/**
* TODO
*/
- public function __construct($implementation)
+ public function __construct($implementation, Horde_Injector_DependencyFinder $dependencyFinder)
{
$this->_implementation = $implementation;
- $this->_setters = array();
+ $this->_dependencyFinder = $dependencyFinder;
}
/**
@@ -39,15 +39,6 @@ class Horde_Injector_Binder_Implementation implements Horde_Injector_Binder
/**
* TODO
*/
- public function bindSetter($method)
- {
- $this->_setters[] = $method;
- return $this;
- }
-
- /**
- * TODO
- */
public function equals(Horde_Injector_Binder $otherBinder)
{
return (($otherBinder instanceof Horde_Injector_Binder_Implementation) &&
@@ -61,9 +52,7 @@ class Horde_Injector_Binder_Implementation implements Horde_Injector_Binder
{
$reflectionClass = new ReflectionClass($this->_implementation);
$this->_validateImplementation($reflectionClass);
- $instance = $this->_getInstance($injector, $reflectionClass);
- $this->_callSetters($injector, $instance);
- return $instance;
+ return $this->_getInstance($injector, $reflectionClass);
}
/**
@@ -82,51 +71,7 @@ class Horde_Injector_Binder_Implementation implements Horde_Injector_Binder
protected function _getInstance(Horde_Injector $injector, ReflectionClass $class)
{
return $class->getConstructor()
- ? $class->newInstanceArgs($this->_getMethodDependencies($injector, $class->getConstructor()))
+ ? $class->newInstanceArgs($this->_dependencyFinder->getMethodDependencies($injector, $class->getConstructor()))
: $class->newInstance();
}
-
- /**
- * TODO
- */
- protected function _callSetters(Horde_Injector $injector, $instance)
- {
- foreach ($this->_setters as $setter) {
- $reflectionMethod = new ReflectionMethod($instance, $setter);
- $reflectionMethod->invokeArgs(
- $instance,
- $this->_getMethodDependencies($injector, $reflectionMethod)
- );
- }
- }
-
- /**
- */
- protected function _getMethodDependencies(Horde_Injector $injector, ReflectionMethod $method)
- {
- $dependencies = array();
-
- try {
- foreach ($method->getParameters() as $parameter) {
- $dependencies[] = $this->_getParameterDependency($injector, $parameter);
- }
- } catch (Horde_Injector_Exception $e) {
- throw new Horde_Injector_Exception("$method has unfulfilled dependencies ($parameter)", 0, $e);
- }
-
- return $dependencies;
- }
-
- /**
- */
- protected function _getParameterDependency(Horde_Injector $injector, ReflectionParameter $parameter)
- {
- if ($parameter->getClass()) {
- return $injector->getInstance($parameter->getClass()->getName());
- } elseif ($parameter->isOptional()) {
- return $parameter->getDefaultValue();
- }
-
- throw new Horde_Injector_Exception("Untyped parameter \$" . $parameter->getName() . "can't be fulfilled");
- }
}
diff --git a/framework/Injector/lib/Horde/Injector/Binder/ImplementationWithSetters.php b/framework/Injector/lib/Horde/Injector/Binder/ImplementationWithSetters.php
deleted file mode 100644
index 5457877b7..000000000
--- a/framework/Injector/lib/Horde/Injector/Binder/ImplementationWithSetters.php
+++ /dev/null
@@ -1,56 +0,0 @@
-
- * @author James Pepin
- * @category Horde
- * @package Horde_Injector
- */
-class Horde_Injector_Binder_ImplementationWithSetters extends Horde_Injector_Binder_Implementation
-{
- /**
- * TODO
- */
- public function create(Horde_Injector $injector)
- {
- $reflectionClass = new ReflectionClass($this->_implementation);
- $this->_validateImplementation($reflectionClass);
- $instance = $this->_getInstance($injector, $reflectionClass);
- $this->_bindAnnotatedSetters($reflectionClass);
- $this->_callSetters($injector, $instance);
- return $instance;
- }
-
- /**
- */
- private function _bindAnnotatedSetters(ReflectionClass $reflectionClass)
- {
- foreach ($this->_findSetters($reflectionClass) as $setter) {
- $this->bindSetter($setter);
- }
- }
-
- /**
- * Find all public methods in $reflectionClass that are annotated with
- * @inject.
- *
- * @param ReflectionClass $reflectionClass
- *
- * @return array
- */
- private function _findSetters(ReflectionClass $reflectionClass)
- {
- $setters = array();
- foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
- $docBlock = $reflectionMethod->getDocComment();
- if ($docBlock) {
- if (strpos($docBlock, '@inject') !== false) {
- $setters[] = $reflectionMethod->name;
- }
- }
- }
-
- return $setters;
- }
-}
diff --git a/framework/Injector/lib/Horde/Injector/DependencyFinder.php b/framework/Injector/lib/Horde/Injector/DependencyFinder.php
new file mode 100644
index 000000000..2ac3bbe2c
--- /dev/null
+++ b/framework/Injector/lib/Horde/Injector/DependencyFinder.php
@@ -0,0 +1,43 @@
+
+ * @author James Pepin
+ * @author Chuck Hagenbuch
+ * @category Horde
+ * @package Horde_Injector
+ */
+class Horde_Injector_DependencyFinder
+{
+ /**
+ */
+ public function getMethodDependencies(Horde_Injector $injector, ReflectionMethod $method)
+ {
+ $dependencies = array();
+
+ try {
+ foreach ($method->getParameters() as $parameter) {
+ $dependencies[] = $this->getParameterDependency($injector, $parameter);
+ }
+ } catch (Horde_Injector_Exception $e) {
+ throw new Horde_Injector_Exception("$method has unfulfilled dependencies ($parameter)", 0, $e);
+ }
+
+ return $dependencies;
+ }
+
+ /**
+ */
+ public function getParameterDependency(Horde_Injector $injector, ReflectionParameter $parameter)
+ {
+ if ($parameter->getClass()) {
+ return $injector->getInstance($parameter->getClass()->getName());
+ } elseif ($parameter->isOptional()) {
+ return $parameter->getDefaultValue();
+ }
+
+ throw new Horde_Injector_Exception("Untyped parameter \$" . $parameter->getName() . "can't be fulfilled");
+ }
+}
diff --git a/framework/Injector/lib/Horde/Injector/TopLevel.php b/framework/Injector/lib/Horde/Injector/TopLevel.php
index 130d3f8ad..31c4d31b3 100644
--- a/framework/Injector/lib/Horde/Injector/TopLevel.php
+++ b/framework/Injector/lib/Horde/Injector/TopLevel.php
@@ -22,7 +22,9 @@ class Horde_Injector_TopLevel implements Horde_Injector_Scope
*/
public function getBinder($interface)
{
- return new Horde_Injector_Binder_ImplementationWithSetters($interface, $interface);
+ $dependencyFinder = new Horde_Injector_DependencyFinder();
+ $implementationBinder = new Horde_Injector_Binder_Implementation($interface, $dependencyFinder);
+ return new Horde_Injector_Binder_AnnotatedSetters($implementationBinder, $dependencyFinder);
}
/**
diff --git a/framework/Injector/package.xml b/framework/Injector/package.xml
index 93651eb43..3939df352 100644
--- a/framework/Injector/package.xml
+++ b/framework/Injector/package.xml
@@ -48,7 +48,9 @@
+
+
@@ -59,12 +61,13 @@
+
-
+
@@ -104,13 +107,14 @@
+
+
-
diff --git a/framework/Injector/test/Horde/Injector/Binder/AnnotatedSettersTest.php b/framework/Injector/test/Horde/Injector/Binder/AnnotatedSettersTest.php
new file mode 100644
index 000000000..6dd128985
--- /dev/null
+++ b/framework/Injector/test/Horde/Injector/Binder/AnnotatedSettersTest.php
@@ -0,0 +1,56 @@
+assertNull($instance->dep);
+ $newInstance = $annotatedSettersBinder->create($injector);
+ $this->assertType('Horde_Injector_Binder_AnnotatedSettersTest__NoDependencies', $newInstance->dep);
+ }
+}
+
+/**
+ * Used by preceeding tests!!!
+ */
+
+class Horde_Injector_Binder_AnnotatedSettersTest__EmptyBinder implements Horde_Injector_Binder
+{
+ public $instance;
+ public function __construct($instance)
+ {
+ $this->instance = $instance;
+ }
+
+ public function create(Horde_Injector $injector)
+ {
+ return $this->instance;
+ }
+
+ public function equals(Horde_Injector_Binder $otherBinder)
+ {
+ return false;
+ }
+}
+
+class Horde_Injector_Binder_AnnotatedSettersTest__NoDependencies
+{
+}
+
+class Horde_Injector_Binder_AnnotatedSettersTest__TypedSetterDependency
+{
+ public $dep;
+
+ /**
+ * @inject
+ */
+ public function setDep(Horde_Injector_Binder_AnnotatedSettersTest__NoDependencies $dep)
+ {
+ $this->dep = $dep;
+ }
+}
diff --git a/framework/Injector/test/Horde/Injector/Binder/ImplementationTest.php b/framework/Injector/test/Horde/Injector/Binder/ImplementationTest.php
index ee219fd40..84ffd66f4 100644
--- a/framework/Injector/test/Horde/Injector/Binder/ImplementationTest.php
+++ b/framework/Injector/test/Horde/Injector/Binder/ImplementationTest.php
@@ -1,10 +1,16 @@
df = new Horde_Injector_DependencyFinder();
+ }
+
public function testShouldReturnBindingDetails()
{
$implBinder = new Horde_Injector_Binder_Implementation(
- 'IMPLEMENTATION'
+ 'IMPLEMENTATION',
+ $this->df
);
$this->assertEquals('IMPLEMENTATION', $implBinder->getImplementation());
@@ -13,7 +19,8 @@ class Horde_Injector_Binder_ImplementationTest extends Horde_Test_Case
public function testShouldCreateInstanceOfClassWithNoDependencies()
{
$implBinder = new Horde_Injector_Binder_Implementation(
- 'Horde_Injector_Binder_ImplementationTest__NoDependencies'
+ 'Horde_Injector_Binder_ImplementationTest__NoDependencies',
+ $this->df
);
$this->assertType(
@@ -25,7 +32,8 @@ class Horde_Injector_Binder_ImplementationTest extends Horde_Test_Case
public function testShouldCreateInstanceOfClassWithTypedDependencies()
{
$implBinder = new Horde_Injector_Binder_Implementation(
- 'Horde_Injector_Binder_ImplementationTest__TypedDependency'
+ 'Horde_Injector_Binder_ImplementationTest__TypedDependency',
+ $this->df
);
$createdInstance = $implBinder->create($this->_getInjectorReturnsNoDependencyObject());
@@ -47,7 +55,8 @@ class Horde_Injector_Binder_ImplementationTest extends Horde_Test_Case
public function testShouldThrowExceptionWhenTryingToCreateInstanceOfClassWithUntypedDependencies()
{
$implBinder = new Horde_Injector_Binder_Implementation(
- 'Horde_Injector_Binder_ImplementationTest__UntypedDependency'
+ 'Horde_Injector_Binder_ImplementationTest__UntypedDependency',
+ $this->df
);
$implBinder->create($this->_getInjectorNeverCallMock());
@@ -56,7 +65,8 @@ class Horde_Injector_Binder_ImplementationTest extends Horde_Test_Case
public function testShouldUseDefaultValuesFromUntypedOptionalParameters()
{
$implBinder = new Horde_Injector_Binder_Implementation(
- 'Horde_Injector_Binder_ImplementationTest__UntypedOptionalDependency'
+ 'Horde_Injector_Binder_ImplementationTest__UntypedOptionalDependency',
+ $this->df
);
$createdInstance = $implBinder->create($this->_getInjectorNeverCallMock());
@@ -70,7 +80,8 @@ class Horde_Injector_Binder_ImplementationTest extends Horde_Test_Case
public function testShouldThrowExceptionIfRequestedClassIsNotDefined()
{
$implBinder = new Horde_Injector_Binder_Implementation(
- 'CLASS_DOES_NOT_EXIST'
+ 'CLASS_DOES_NOT_EXIST',
+ $this->df
);
$implBinder->create($this->_getInjectorNeverCallMock());
@@ -79,10 +90,11 @@ class Horde_Injector_Binder_ImplementationTest extends Horde_Test_Case
/**
* @expectedException Horde_Injector_Exception
*/
- public function testShouldThrowExcpetionIfImplementationIsAnInterface()
+ public function testShouldThrowExceptionIfImplementationIsAnInterface()
{
$implBinder = new Horde_Injector_Binder_Implementation(
- 'Horde_Injector_Binder_ImplementationTest__Interface'
+ 'Horde_Injector_Binder_ImplementationTest__Interface',
+ $this->df
);
$implBinder->create($this->_getInjectorNeverCallMock());
@@ -91,52 +103,16 @@ class Horde_Injector_Binder_ImplementationTest extends Horde_Test_Case
/**
* @expectedException Horde_Injector_Exception
*/
- public function testShouldThrowExcpetionIfImplementationIsAnAbstractClass()
+ public function testShouldThrowExceptionIfImplementationIsAnAbstractClass()
{
$implBinder = new Horde_Injector_Binder_Implementation(
- 'Horde_Injector_Binder_ImplementationTest__AbstractClass'
+ 'Horde_Injector_Binder_ImplementationTest__AbstractClass',
+ $this->df
);
$implBinder->create($this->_getInjectorNeverCallMock());
}
- public function testShouldCallSetterMethodsWithNoDependenciesIfRequested()
- {
- $implBinder = new Horde_Injector_Binder_Implementation(
- 'Horde_Injector_Binder_ImplementationTest__SetterNoDependencies'
- );
- $implBinder->bindSetter('setDependency');
-
- $instance = $implBinder->create($this->_getInjectorNeverCallMock());
-
- $this->assertType(
- 'Horde_Injector_Binder_ImplementationTest__SetterNoDependencies',
- $instance
- );
-
- $this->assertEquals('CALLED', $instance->setterDep);
- }
-
- public function testShouldCallSetterMethodsWithDependenciesIfRequested()
- {
- $implBinder = new Horde_Injector_Binder_Implementation(
- 'Horde_Injector_Binder_ImplementationTest__SetterHasDependencies'
- );
- $implBinder->bindSetter('setDependency');
-
- $instance = $implBinder->create($this->_getInjectorReturnsNoDependencyObject());
-
- $this->assertType(
- 'Horde_Injector_Binder_ImplementationTest__SetterHasDependencies',
- $instance
- );
-
- $this->assertType(
- 'Horde_Injector_Binder_ImplementationTest__NoDependencies',
- $instance->setterDep
- );
- }
-
private function _getInjectorNeverCallMock()
{
$injector = $this->getMockSkipConstructor('Horde_Injector', array('getInstance'));
diff --git a/framework/Injector/test/Horde/Injector/BinderTest.php b/framework/Injector/test/Horde/Injector/BinderTest.php
index 1564e30a5..cfcc2dd28 100644
--- a/framework/Injector/test/Horde/Injector/BinderTest.php
+++ b/framework/Injector/test/Horde/Injector/BinderTest.php
@@ -6,25 +6,26 @@ class Horde_Injector_BinderTest extends Horde_Test_Case
*/
public function binderIsEqualProvider()
{
+ $df = new Horde_Injector_DependencyFinder();
return array(
array(
- new Horde_Injector_Binder_Implementation('foobar'),
+ new Horde_Injector_Binder_Implementation('foobar', $df),
new Horde_Injector_Binder_Factory('factory', 'method'),
false, "Implementation_Binder should not equal Factory binder"
),
array(
- new Horde_Injector_Binder_Implementation('foobar'),
- new Horde_Injector_Binder_Implementation('foobar'),
+ new Horde_Injector_Binder_Implementation('foobar', $df),
+ new Horde_Injector_Binder_Implementation('foobar', $df),
true, "Implementation Binders both reference concrete class foobar"
),
array(
- new Horde_Injector_Binder_Implementation('foobar'),
- new Horde_Injector_Binder_Implementation('otherimpl'),
+ new Horde_Injector_Binder_Implementation('foobar', $df),
+ new Horde_Injector_Binder_Implementation('otherimpl', $df),
false, "Implementation Binders do not have same implementation set"
),
array(
new Horde_Injector_Binder_Factory('factory', 'method'),
- new Horde_Injector_Binder_Implementation('foobar'),
+ new Horde_Injector_Binder_Implementation('foobar', $df),
false, "Implementation_Binder should not equal Factory binder"
),
array(
diff --git a/framework/Injector/test/Horde/Injector/InjectorTest.php b/framework/Injector/test/Horde/Injector/InjectorTest.php
index 3ec68fbd4..b76958bdc 100644
--- a/framework/Injector/test/Horde/Injector/InjectorTest.php
+++ b/framework/Injector/test/Horde/Injector/InjectorTest.php
@@ -138,14 +138,15 @@ class Horde_Injector_InjectorTest extends PHPUnit_Framework_TestCase
{
// we need to set a class for an instance on the parent
$injector = new Horde_Injector(new Horde_Injector_TopLevel());
- $injector->addBinder('FooBarInterface', new Horde_Injector_Binder_Implementation('StdClass'));
+ $df = new Horde_Injector_DependencyFinder();
+ $injector->addBinder('FooBarInterface', new Horde_Injector_Binder_Implementation('StdClass', $df));
// getInstance will save $returnedObject and return it again later when FooBarInterface is requested
$returnedObject = $injector->getInstance('FooBarInterface');
$childInjector = $injector->createChildInjector();
// add same binding again to child
- $childInjector->addBinder('FooBarInterface', new Horde_Injector_Binder_Implementation('StdClass'));
+ $childInjector->addBinder('FooBarInterface', new Horde_Injector_Binder_Implementation('StdClass', $df));
$this->assertSame($returnedObject, $childInjector->getInstance('FooBarInterface'),
"Child should have returned object reference from parent because added binder was identical to the parent binder");
--
2.11.0