Beispiel #1
0
 public function testCustomObjectCreator()
 {
     $injector = new Injector();
     $injector->setObjectCreator(new SSObjectCreator());
     $config = array('OriginalRequirementsBackend', 'DummyRequirements' => array('class' => 'DummyRequirements(\'%$OriginalRequirementsBackend\')'));
     $injector->load($config);
     $requirements = $injector->get('DummyRequirements');
     $this->assertEquals('OriginalRequirementsBackend', get_class($requirements->backend));
 }
 /**
  * @expectedException InvalidArgumentException
  */
 public function testTooManyArrayValues()
 {
     $injector = new Injector();
     $config = array('TestService' => array('class' => 'TestObject', 'calls' => array(array('method', array('args'), 'what is this?'))));
     $injector->load($config);
     $item = $injector->get('TestService');
 }
Beispiel #3
0
 public function testConvertServicePropertyOnCreate()
 {
     // make sure convert service property is not called on direct calls to create, only on configured
     // declarations to avoid un-needed function calls
     $injector = new Injector();
     $item = $injector->create('ConstructableObject', '%$TestObject');
     $this->assertEquals('%$TestObject', $item->property);
     // do it again but have test object configured as a constructor dependency
     $injector = new Injector();
     $config = array('ConstructableObject' => array('constructor' => array('%$TestObject')));
     $injector->load($config);
     $item = $injector->get('ConstructableObject');
     $this->assertTrue($item->property instanceof TestObject);
     // and with a configured object defining TestObject to be something else!
     $injector = new Injector(array('locator' => 'InjectorTestConfigLocator'));
     $config = array('ConstructableObject' => array('constructor' => array('%$TestObject')));
     $injector->load($config);
     $item = $injector->get('ConstructableObject');
     $this->assertTrue($item->property instanceof ConstructableObject);
     $this->assertInstanceOf('OtherTestObject', $item->property->property);
 }