public function testBuilderCanBuildFromArray() { $ini = new \Zend\Config\Ini(__DIR__ . '/../_files/sample.ini', 'section-b'); $iniAsArray = $ini->toArray(); $definitionArray = $iniAsArray['di']['definitions'][1]; unset($definitionArray['class']); $definition = new BuilderDefinition(); $definition->createClassesFromArray($definitionArray); $this->assertTrue($definition->hasClass('My\DbAdapter')); $this->assertEquals('__construct', $definition->getInstantiator('My\DbAdapter')); $this->assertEquals( array('username' => null, 'password' => null), $definition->getInjectionMethodParameters('My\DbAdapter', '__construct') ); $this->assertTrue($definition->hasClass('My\Mapper')); $this->assertEquals('__construct', $definition->getInstantiator('My\Mapper')); $this->assertEquals( array('dbAdapter' => 'My\DbAdapter'), $definition->getInjectionMethodParameters('My\Mapper', '__construct') ); $this->assertTrue($definition->hasClass('My\Repository')); $this->assertEquals('__construct', $definition->getInstantiator('My\Repository')); $this->assertEquals( array('mapper' => 'My\Mapper'), $definition->getInjectionMethodParameters('My\Repository', '__construct') ); }
public function testCanCreateInjectionMethodsAndPopulateFromFluentInterface() { $builder = new BuilderDefinition(); $foo = $builder->createClass('Foo'); $foo->setName('Foo'); $foo->createInjectionMethod('setBar')->addParameter('bar', 'Bar'); $foo->createInjectionMethod('setConfig')->addParameter('config', null); $this->assertTrue($builder->hasClass('Foo')); $this->assertTrue($builder->hasInjectionMethod('Foo', 'setBar')); $this->assertTrue($builder->hasInjectionMethod('Foo', 'setConfig')); $this->assertEquals(array('bar' => array('Bar', false, true)), $builder->getInjectionMethodParameters('Foo', 'setBar')); $this->assertEquals(array('config' => array(null, false, null)), $builder->getInjectionMethodParameters('Foo', 'setConfig')); }