public function testGetSetParameters()
 {
     $sc = new Container();
     $this->assertEquals(array(), $sc->getParameters(), '->getParameters() returns an empty array if no parameter has been defined');
     $sc->setParameters(array('foo' => 'bar'));
     $this->assertEquals(array('foo' => 'bar'), $sc->getParameters(), '->setParameters() sets the parameters');
     $sc->setParameters(array('bar' => 'foo'));
     $this->assertEquals(array('bar' => 'foo'), $sc->getParameters(), '->setParameters() overrides the previous defined parameters');
     $sc->setParameters(array('Bar' => 'foo'));
     $this->assertEquals(array('bar' => 'foo'), $sc->getParameters(), '->setParameters() converts the key to lowercase');
 }
Example #2
0
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Container;
$fixturesPath = __DIR__ . '/../../../../fixtures/Symfony/Components/DependencyInjection/';
$t = new LimeTest(42);
// __construct()
$t->diag('__construct()');
$sc = new Container();
$t->is(spl_object_hash($sc->getService('service_container')), spl_object_hash($sc), '__construct() automatically registers itself as a service');
$sc = new Container(array('foo' => 'bar'));
$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');