'bar' =>
new Definition('BarClass'
),
];
$builder->
setDefinitions($definitions);
$this->
assertEquals($definitions,
$builder->
getDefinitions(), '->setDefinitions() sets the service definitions'
);
$this->
assertTrue($builder->
hasDefinition('foo'
), '->hasDefinition() returns true if a service definition exists'
);
$this->
assertFalse($builder->
hasDefinition('foobar'
), '->hasDefinition() returns false if a service definition does not exist'
);
$builder->
setDefinition('foobar',
$foo =
new Definition('FooBarClass'
));
$this->
assertEquals($foo,
$builder->
getDefinition('foobar'
), '->getDefinition() returns a service definition if defined'
);
$this->
assertSame($builder->
setDefinition('foobar',
$foo =
new Definition('FooBarClass'
)),
$foo, '->setDefinition() implements a fluid interface by returning the service reference'
);
$builder->
addDefinitions($defs =
['foobar' =>
new Definition('FooBarClass'
)]);
$this->
assertEquals(array_merge($definitions,
$defs),
$builder->
getDefinitions(), '->addDefinitions() adds the service definitions'
);
try { $builder->
getDefinition('baz'
);
$this->
fail('->getDefinition() throws a ServiceNotFoundException if the service definition does not exist'
);
} catch (ServiceNotFoundException
$e) { $this->
assertEquals('You have requested a non-existent service "baz".',
$e->
getMessage(), '->getDefinition() throws a ServiceNotFoundException if the service definition does not exist'
);
} } /**
* The test should be kept in the group as it always expects a deprecation.
*
* @group legacy
*/