Merge remote branch 'vicb/fix-dbg-evt-mgr'

* vicb/fix-dbg-evt-mgr:
  [FrameworkBundle] Fix an issue when adding a scoped service as an event listener
This commit is contained in:
Fabien Potencier 2011-04-13 23:24:04 +02:00
commit 56a4f0463a
2 changed files with 0 additions and 75 deletions

View File

@ -65,40 +65,6 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements
parent::addListener($eventNames, $listener, $priority);
}
/**
* {@inheritDoc}
*
* @throws \RuntimeException if the service does not exist
* @throws \RuntimeException if the listener service method is not callable
*/
public function addListenerService($eventNames, $serviceId, $priority = 0)
{
$error = null;
if (!$this->container->has($serviceId)) {
$error = sprintf('The container has no service "%s".', $serviceId);
} else {
$listener = $this->container->get($serviceId);
if (!$listener instanceof \Closure) {
foreach ((array) $eventNames as $method) {
if (!is_callable(array($listener, $method))) {
$error = sprintf('The event method "%s()" is not callable on the service "%s".', $method, $serviceId);
break;
}
}
}
}
if (null !== $error) {
if (null !== $this->logger) {
$this->logger->err($error);
}
throw new \RuntimeException($error);
}
parent::addListenerService($eventNames, $serviceId, $priority);
}
/**
* {@inheritDoc}
*/

View File

@ -26,45 +26,4 @@ class TraceableEventDispactherTest extends TestCase
$dispatcher = new TraceableEventDispatcher($container);
$dispatcher->addListener('onFooEvent', new \stdClass());
}
/**
* @expectedException \RuntimeException
*/
public function testThrowsAnExceptionWhenAListenerServiceIsNotFound()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container
->expects($this->once())
->method('has')
->with($this->equalTo('listener.service'))
->will($this->returnValue(false))
;
$dispatcher = new TraceableEventDispatcher($container);
$dispatcher->addListenerService('onFooEvent', 'listener.service');
}
/**
* @expectedException \RuntimeException
*/
public function testThrowsAnExceptionWhenAListenerServiceMethodIsNotCallable()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container
->expects($this->once())
->method('has')
->with($this->equalTo('listener.service'))
->will($this->returnValue(true))
;
$container
->expects($this->once())
->method('get')
->with($this->equalTo('listener.service'))
->will($this->returnValue(new \stdClass()))
;
$dispatcher = new TraceableEventDispatcher($container);
$dispatcher->addListenerService('onFooEvent', 'listener.service');
}
}