if ($reflectionClass->getConstructor()) {
$this->_addBinder($interface, $reflectionClass->newInstanceArgs($args));
+ } else {
+ $this->_addBinder($interface, $reflectionClass->newInstance());
}
- $this->_addBinder($interface, $reflectionClass->newInstance());
return $this->_getBinder($interface);
}
$this->assertType('Horde_Injector_Binder_Mock', $injector->bindMock('BOUND_INTERFACE'));
$this->assertType('Horde_Injector_Binder_Mock', $injector->getBinder('BOUND_INTERFACE'));
}
+
+ public function testShouldProvideMagicFactoryMethodForBinderAdditionWhereBinderHasDependencies()
+ {
+ $injector = new Horde_Injector(new Horde_Injector_TopLevel());
+
+ // binds a Horde_Injector_Binder_Mock object
+ $this->assertType('Horde_Injector_Binder_MockWithDependencies',
+ $injector->bindMockWithDependencies('BOUND_INTERFACE', 'PARAMETER1'));
+ $this->assertType('Horde_Injector_Binder_MockWithDependencies',
+ $injector->getBinder('BOUND_INTERFACE'));
+ }
/**
* @expectedException BadMethodCallException
return $otherBinder === $this;
}
}
+
+class Horde_Injector_Binder_MockWithDependencies implements Horde_Injector_Binder
+{
+ private $_interface;
+
+ public function __construct($parameter1) {}
+
+ public function create(Horde_Injector $injector)
+ {
+ return $injector;
+ }
+
+ public function equals(Horde_Injector_Binder $otherBinder)
+ {
+ return $otherBinder === $this;
+ }
+}