[FrameworkBundle] Added a test for listener services not available in the current scope
This commit is contained in:
parent
a4c41179e0
commit
b4df0ea9ed
@ -72,6 +72,8 @@ class ContainerAwareEventDispatcher extends EventDispatcher
|
||||
*
|
||||
* Lazily loads listeners for this event from the dependency injection
|
||||
* container.
|
||||
*
|
||||
* @throws \InvalidArgumentException if the service is not defined
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Bundle\FrameworkBundle\ContainerAwareEventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\DependencyInjection\Scope;
|
||||
|
||||
class ContainerAwareEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@ -51,6 +52,26 @@ class ContainerAwareEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$dispatcher->dispatch('onEvent', $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testTriggerAListenerServiceOutOfScope()
|
||||
{
|
||||
$service = $this->getMock('Symfony\Bundle\FrameworkBundle\Tests\Service');
|
||||
|
||||
$scope = new Scope('scope');
|
||||
|
||||
$container = new Container();
|
||||
$container->addScope($scope);
|
||||
$container->enterScope('scope');
|
||||
$container->set('service.listener', $service, 'scope');
|
||||
|
||||
$dispatcher = new ContainerAwareEventDispatcher($container);
|
||||
$dispatcher->addListenerService('onEvent', 'service.listener');
|
||||
|
||||
$container->leaveScope('scope');
|
||||
$dispatcher->dispatch('onEvent');
|
||||
}
|
||||
}
|
||||
|
||||
class Service
|
||||
|
Reference in New Issue
Block a user