public function testGetSetParameter()
 {
     $sc = new Container(array('foo' => 'bar'));
     $sc->setParameter('bar', 'foo');
     $this->assertEquals('foo', $sc->getParameter('bar'), '->setParameter() sets the value of a new parameter');
     $this->assertEquals('foo', $sc['bar'], '->offsetGet() gets the value of a parameter');
     $sc['bar1'] = 'foo1';
     $this->assertEquals('foo1', $sc['bar1'], '->offsetset() sets the value of a parameter');
     unset($sc['bar1']);
     $this->assertFalse(isset($sc['bar1']), '->offsetUnset() removes a parameter');
     $sc->setParameter('foo', 'baz');
     $this->assertEquals('baz', $sc->getParameter('foo'), '->setParameter() overrides previously set parameter');
     $sc->setParameter('Foo', 'baz1');
     $this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase');
     $this->assertEquals('baz1', $sc->getParameter('FOO'), '->getParameter() converts the key to lowercase');
     $this->assertEquals('baz1', $sc['FOO'], '->offsetGet() converts the key to lowercase');
     try {
         $sc->getParameter('baba');
         $this->fail('->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
         $this->assertEquals('The parameter "baba" must be defined.', $e->getMessage(), '->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
     }
     try {
         $sc['baba'];
         $this->fail('->offsetGet() thrown an \\InvalidArgumentException if the key does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->offsetGet() thrown an \\InvalidArgumentException if the key does not exist');
         $this->assertEquals('The parameter "baba" must be defined.', $e->getMessage(), '->offsetGet() thrown an \\InvalidArgumentException if the key does not exist');
     }
 }
 public function testGetSetParameter()
 {
     $sc = new Container(array('foo' => 'bar'));
     $sc->setParameter('bar', 'foo');
     $this->assertEquals($sc->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter');
     $this->assertEquals($sc['bar'], 'foo', '->offsetGet() gets the value of a parameter');
     $sc['bar1'] = 'foo1';
     $this->assertEquals($sc['bar1'], 'foo1', '->offsetset() sets the value of a parameter');
     unset($sc['bar1']);
     $this->assertTrue(!isset($sc['bar1']), '->offsetUnset() removes a parameter');
     $sc->setParameter('foo', 'baz');
     $this->assertEquals($sc->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter');
     $sc->setParameter('Foo', 'baz1');
     $this->assertEquals($sc->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase');
     $this->assertEquals($sc->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase');
     $this->assertEquals($sc['FOO'], 'baz1', '->offsetGet() converts the key to lowercase');
     try {
         $sc->getParameter('baba');
         $this->fail('->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
     } catch (\InvalidArgumentException $e) {
     }
     try {
         $sc['baba'];
         $this->fail('->offsetGet() thrown an \\InvalidArgumentException if the key does not exist');
     } catch (\InvalidArgumentException $e) {
     }
 }
Exemple #3
0
$t->is($sc->getParameters(), array('foo' => 'bar'), '__construct() takes an array of parameters as its first argument');
// ->setParameters() ->getParameters()
$t->diag('->setParameters() ->getParameters()');
$sc = new Container();
$t->is($sc->getParameters(), array(), '->getParameters() returns an empty array if no parameter has been defined');
$sc->setParameters(array('foo' => 'bar'));
$t->is($sc->getParameters(), array('foo' => 'bar'), '->setParameters() sets the parameters');
$sc->setParameters(array('bar' => 'foo'));
$t->is($sc->getParameters(), array('bar' => 'foo'), '->setParameters() overrides the previous defined parameters');
$sc->setParameters(array('Bar' => 'foo'));
$t->is($sc->getParameters(), array('bar' => 'foo'), '->setParameters() converts the key to lowercase');
// ->setParameter() ->getParameter()
$t->diag('->setParameter() ->getParameter() ');
$sc = new Container(array('foo' => 'bar'));
$sc->setParameter('bar', 'foo');
$t->is($sc->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter');
$t->is($sc['bar'], 'foo', '->offsetGet() gets the value of a parameter');
$sc['bar1'] = 'foo1';
$t->is($sc['bar1'], 'foo1', '->offsetset() sets the value of a parameter');
unset($sc['bar1']);
$t->ok(!isset($sc['bar1']), '->offsetUnset() removes a parameter');
$sc->setParameter('foo', 'baz');
$t->is($sc->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter');
$sc->setParameter('Foo', 'baz1');
$t->is($sc->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase');
$t->is($sc->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase');
$t->is($sc['FOO'], 'baz1', '->offsetGet() converts the key to lowercase');
try {
    $sc->getParameter('baba');
    $t->fail('->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
} catch (\InvalidArgumentException $e) {