$t->ok(!$configuration->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined'); // ->addParameters() $t->diag('->addParameters()'); $configuration = new BuilderConfiguration(array(), array('foo' => 'bar')); $configuration->addParameters(array('bar' => 'foo')); $t->is($configuration->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->addParameters() adds parameters to the existing ones'); $configuration->addParameters(array('Bar' => 'fooz')); $t->is($configuration->getParameters(), array('foo' => 'bar', 'bar' => 'fooz'), '->addParameters() converts keys to lowercase'); // ->setAlias() ->getAlias() ->hasAlias() ->getAliases() ->addAliases() $t->diag('->setAlias() ->getAlias() ->hasAlias()'); $configuration = new BuilderConfiguration(); $configuration->setAlias('bar', 'foo'); $t->is($configuration->getAlias('bar'), 'foo', '->setAlias() defines a new alias'); $t->ok($configuration->hasAlias('bar'), '->hasAlias() returns true if the alias is defined'); $t->ok(!$configuration->hasAlias('baba'), '->hasAlias() returns false if the alias is not defined'); try { $configuration->getAlias('baba'); $t->fail('->getAlias() throws an \InvalidArgumentException if the alias does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getAlias() throws an \InvalidArgumentException if the alias does not exist'); } $configuration->setAlias('barbar', 'foofoo'); $t->is($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo'), '->getAliases() returns an array of all defined aliases');
public function testAliases() { $configuration = new BuilderConfiguration(); $configuration->setAlias('bar', 'foo'); $this->assertEquals('foo', $configuration->getAlias('bar'), '->setAlias() defines a new alias'); $this->assertTrue($configuration->hasAlias('bar'), '->hasAlias() returns true if the alias is defined'); $this->assertFalse($configuration->hasAlias('baba'), '->hasAlias() returns false if the alias is not defined'); try { $configuration->getAlias('baba'); $this->fail('->getAlias() throws an \\InvalidArgumentException if the alias does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getAlias() throws an \\InvalidArgumentException if the alias does not exist'); $this->assertEquals('The service alias "baba" does not exist.', $e->getMessage(), '->getAlias() throws an \\InvalidArgumentException if the alias does not exist'); } $configuration->setAlias('barbar', 'foofoo'); $this->assertEquals(array('bar' => 'foo', 'barbar' => 'foofoo'), $configuration->getAliases(), '->getAliases() returns an array of all defined aliases'); $configuration->addAliases(array('foo' => 'bar')); $this->assertEquals(array('bar' => 'foo', 'barbar' => 'foofoo', 'foo' => 'bar'), $configuration->getAliases(), '->addAliases() adds some aliases'); }