public function testDefinitions() { $configuration = new BuilderConfiguration(); $definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass')); $configuration->setDefinitions($definitions); $this->assertEquals($definitions, $configuration->getDefinitions(), '->setDefinitions() sets the service definitions'); $this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists'); $this->assertFalse($configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist'); $configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')); $this->assertEquals($foo, $configuration->getDefinition('foobar'), '->getDefinition() returns a service definition if defined'); $this->assertTrue($configuration->setDefinition('foobar', new Definition('FooBarClass')) === $configuration, '->setDefinition() implements a fuild interface'); $configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass'))); $this->assertEquals(array_merge($definitions, $defs), $configuration->getDefinitions(), '->addDefinitions() adds the service definitions'); try { $configuration->getDefinition('baz'); $this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getDefinition() throws an InvalidArgumentException if the service definition does not exist'); $this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist'); } }
$t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()'); $configuration = new BuilderConfiguration(); $definitions = array( 'foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'), ); $configuration->setDefinitions($definitions); $t->is($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions'); $t->ok($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists'); $t->ok(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist'); $configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')); $t->is($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined'); $t->ok($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference'); $configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass'))); $t->is($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions'); try { $configuration->getDefinition('baz'); $t->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->getDefinition() throws an InvalidArgumentException if the service definition does not exist'); } // ->findDefinition() $t->diag('->findDefinition()'); $configuration = new BuilderConfiguration(array('foo' => $definition = new Definition('FooClass')));
public function testDefinitions() { $configuration = new BuilderConfiguration(); $definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass')); $configuration->setDefinitions($definitions); $this->assertEquals($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions'); $this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists'); $this->assertTrue(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist'); $configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')); $this->assertEquals($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined'); $this->assertTrue($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference'); $configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass'))); $this->assertEquals($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions'); try { $configuration->getDefinition('baz'); $this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist'); } catch (\InvalidArgumentException $e) { } }