Skip to content

Commit

Permalink
Merge remote branch 'vicb/fix-dbg-evt-mgr'
Browse files Browse the repository at this point in the history
* vicb/fix-dbg-evt-mgr:
  [FrameworkBundle] Fix an issue when adding a scoped service as an event listener
  • Loading branch information
fabpot committed Apr 13, 2011
2 parents d2af468 + 3322cdb commit 56a4f04
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 75 deletions.
Expand Up @@ -65,40 +65,6 @@ public function addListener($eventNames, $listener, $priority = 0)
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}
*/
Expand Down
Expand Up @@ -26,45 +26,4 @@ public function testThrowsAnExceptionWhenAListenerMethodIsNotCallable()
$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');
}
}

0 comments on commit 56a4f04

Please sign in to comment.