Esempio n. 1
0
 public function testDefinitions()
 {
     $builder = new Builder();
     $definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
     $builder->setDefinitions($definitions);
     $this->assertEquals($builder->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
     $this->assertTrue($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
     $this->assertTrue(!$builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
     $builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
     $this->assertEquals($builder->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
     $this->assertTrue($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
     $builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
     $this->assertEquals($builder->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
     try {
         $builder->getDefinition('baz');
         $this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
     } catch (\InvalidArgumentException $e) {
     }
 }
Esempio n. 2
0
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\BuilderConfiguration;
use Symfony\Components\DependencyInjection\Definition;
use Symfony\Components\DependencyInjection\Reference;
$fixturesPath = __DIR__ . '/../../../../fixtures/Symfony/Components/DependencyInjection/';
$t = new LimeTest(61);
// ->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()
$t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()');
$builder = new Builder();
$definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
$builder->setDefinitions($definitions);
$t->is($builder->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
$t->ok($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$t->ok(!$builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$t->is($builder->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$t->ok($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
$builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$t->is($builder->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
try {
    $builder->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');
}
// ->register()