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->hasMethod('Foo', 'setBar')); $this->assertTrue($builder->hasMethod('Foo', 'setConfig')); $this->assertEquals(array('Foo::setBar:0' => array('bar', 'Bar', true)), $builder->getMethodParameters('Foo', 'setBar')); $this->assertEquals(array('Foo::setConfig:0' => array('config', null, true)), $builder->getMethodParameters('Foo', 'setConfig')); }