Пример #1
0
 public function testMagicCall()
 {
     $sc = new Container();
     $sc->setService('foo_bar.foo', $foo = new \stdClass());
     $this->assertEquals($foo, $sc->getFooBar_FooService(), '__call() finds services is the method is getXXXService()');
     try {
         $sc->getFooBar_Foo();
         $this->fail('__call() throws a \\BadMethodCallException exception if the method is not a service method');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\BadMethodCallException', $e, '__call() throws a \\BadMethodCallException exception if the method is not a service method');
         $this->assertEquals('Call to undefined method Symfony\\Components\\DependencyInjection\\Container::getFooBar_Foo.', $e->getMessage(), '__call() throws a \\BadMethodCallException exception if the method is not a service method');
     }
 }
Пример #2
0
try {
    $sc->getService('baba');
    $t->fail('->getService() thrown an \\InvalidArgumentException if the service does not exist');
} catch (\InvalidArgumentException $e) {
    $t->pass('->getService() thrown an \\InvalidArgumentException if the service does not exist');
}
try {
    $sc->baba;
    $t->fail('->__get() thrown an \\InvalidArgumentException if the service does not exist');
} catch (\InvalidArgumentException $e) {
    $t->pass('->__get() thrown an \\InvalidArgumentException if the service does not exist');
}
try {
    unset($sc->baba);
    $t->fail('->__unset() thrown an LogicException if you try to remove a service');
} catch (LogicException $e) {
    $t->pass('->__unset() thrown an LogicException if you try to remove a service');
}
$t->is(spl_object_hash($sc->getService('foo_bar')), spl_object_hash($sc->__foo_bar), '->getService() camelizes the service id when looking for a method');
$t->is(spl_object_hash($sc->getService('foo.baz')), spl_object_hash($sc->__foo_baz), '->getService() camelizes the service id when looking for a method');
// __call()
$t->diag('__call()');
$sc = new Container();
$sc->setService('foo_bar.foo', $foo = new stdClass());
$t->is($sc->getFooBar_FooService(), $foo, '__call() finds services is the method is getXXXService()');
try {
    $sc->getFooBar_Foo();
    $t->fail('__call() throws a \\RuntimeException exception if the method is not a service method');
} catch (\RuntimeException $e) {
    $t->pass('__call() throws a \\RuntimeException exception if the method is not a service method');
}
Пример #3
0
 public function testMagicCall()
 {
     $sc = new Container();
     $sc->setService('foo_bar.foo', $foo = new \stdClass());
     $this->assertEquals($sc->getFooBar_FooService(), $foo, '__call() finds services is the method is getXXXService()');
     try {
         $sc->getFooBar_Foo();
         $this->fail('__call() throws a \\RuntimeException exception if the method is not a service method');
     } catch (\RuntimeException $e) {
     }
 }