public function testHasParameter() { $sc = new Container(array('foo' => 'bar')); $this->assertTrue($sc->hasParameter('foo'), '->hasParameter() returns true if a parameter is defined'); $this->assertTrue($sc->hasParameter('Foo'), '->hasParameter() converts the key to lowercase'); $this->assertTrue(isset($sc['Foo']), '->offsetExists() converts the key to lowercase'); $this->assertFalse($sc->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined'); $this->assertTrue(isset($sc['foo']), '->offsetExists() returns true if a parameter is defined'); $this->assertFalse(isset($sc['bar']), '->offsetExists() returns false if a parameter is not defined'); }
try { $sc->getParameter('baba'); $t->fail('->getParameter() thrown an \\InvalidArgumentException if the key does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getParameter() thrown an \\InvalidArgumentException if the key does not exist'); } try { $sc['baba']; $t->fail('->offsetGet() thrown an \\InvalidArgumentException if the key does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->offsetGet() thrown an \\InvalidArgumentException if the key does not exist'); } // ->hasParameter() $t->diag('->hasParameter()'); $sc = new Container(array('foo' => 'bar')); $t->ok($sc->hasParameter('foo'), '->hasParameter() returns true if a parameter is defined'); $t->ok($sc->hasParameter('Foo'), '->hasParameter() converts the key to lowercase'); $t->ok(isset($sc['Foo']), '->offsetExists() converts the key to lowercase'); $t->ok(!$sc->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined'); $t->ok(isset($sc['foo']), '->offsetExists() returns true if a parameter is defined'); $t->ok(!isset($sc['bar']), '->offsetExists() returns false if a parameter is not defined'); // ->addParameters() $t->diag('->addParameters()'); $sc = new Container(array('foo' => 'bar')); $sc->addParameters(array('bar' => 'foo')); $t->is($sc->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->addParameters() adds parameters to the existing ones'); $sc->addParameters(array('Bar' => 'fooz')); $t->is($sc->getParameters(), array('foo' => 'bar', 'bar' => 'fooz'), '->addParameters() converts keys to lowercase'); // ->setService() ->hasService() ->getService() $t->diag('->setService() ->hasService() ->getService()'); $sc = new Container();