class RegisterListenersPassTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/event-dispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php \Symfony\Component\EventDispatcher\Tests\DependencyInjection\RegisterListenersPassTest
Hierarchy
- class \Symfony\Component\EventDispatcher\Tests\DependencyInjection\RegisterListenersPassTest extends \Symfony\Component\EventDispatcher\Tests\DependencyInjection\PHPUnit_Framework_TestCase
Expanded class hierarchy of RegisterListenersPassTest
File
- vendor/
symfony/ event-dispatcher/ Tests/ DependencyInjection/ RegisterListenersPassTest.php, line 17
Namespace
Symfony\Component\EventDispatcher\Tests\DependencyInjectionView source
class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase {
/**
* Tests that event subscribers not implementing EventSubscriberInterface
* trigger an exception.
*
* @expectedException \InvalidArgumentException
*/
public function testEventSubscriberWithoutInterface() {
// one service, not implementing any interface
$services = array(
'my_event_subscriber' => array(
0 => array(),
),
);
$definition = $this
->getMock('Symfony\\Component\\DependencyInjection\\Definition');
$definition
->expects($this
->atLeastOnce())
->method('isPublic')
->will($this
->returnValue(true));
$definition
->expects($this
->atLeastOnce())
->method('getClass')
->will($this
->returnValue('stdClass'));
$builder = $this
->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder', array(
'hasDefinition',
'findTaggedServiceIds',
'getDefinition',
));
$builder
->expects($this
->any())
->method('hasDefinition')
->will($this
->returnValue(true));
// We don't test kernel.event_listener here
$builder
->expects($this
->atLeastOnce())
->method('findTaggedServiceIds')
->will($this
->onConsecutiveCalls(array(), $services));
$builder
->expects($this
->atLeastOnce())
->method('getDefinition')
->will($this
->returnValue($definition));
$registerListenersPass = new RegisterListenersPass();
$registerListenersPass
->process($builder);
}
public function testValidEventSubscriber() {
$services = array(
'my_event_subscriber' => array(
0 => array(),
),
);
$definition = $this
->getMock('Symfony\\Component\\DependencyInjection\\Definition');
$definition
->expects($this
->atLeastOnce())
->method('isPublic')
->will($this
->returnValue(true));
$definition
->expects($this
->atLeastOnce())
->method('getClass')
->will($this
->returnValue('Symfony\\Component\\EventDispatcher\\Tests\\DependencyInjection\\SubscriberService'));
$builder = $this
->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder', array(
'hasDefinition',
'findTaggedServiceIds',
'getDefinition',
'findDefinition',
));
$builder
->expects($this
->any())
->method('hasDefinition')
->will($this
->returnValue(true));
// We don't test kernel.event_listener here
$builder
->expects($this
->atLeastOnce())
->method('findTaggedServiceIds')
->will($this
->onConsecutiveCalls(array(), $services));
$builder
->expects($this
->atLeastOnce())
->method('getDefinition')
->will($this
->returnValue($definition));
$builder
->expects($this
->atLeastOnce())
->method('findDefinition')
->will($this
->returnValue($definition));
$registerListenersPass = new RegisterListenersPass();
$registerListenersPass
->process($builder);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The service "foo" must be public as event listeners are lazy-loaded.
*/
public function testPrivateEventListener() {
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setPublic(false)
->addTag('kernel.event_listener', array());
$container
->register('event_dispatcher', 'stdClass');
$registerListenersPass = new RegisterListenersPass();
$registerListenersPass
->process($container);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The service "foo" must be public as event subscribers are lazy-loaded.
*/
public function testPrivateEventSubscriber() {
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setPublic(false)
->addTag('kernel.event_subscriber', array());
$container
->register('event_dispatcher', 'stdClass');
$registerListenersPass = new RegisterListenersPass();
$registerListenersPass
->process($container);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The service "foo" must not be abstract as event listeners are lazy-loaded.
*/
public function testAbstractEventListener() {
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setAbstract(true)
->addTag('kernel.event_listener', array());
$container
->register('event_dispatcher', 'stdClass');
$registerListenersPass = new RegisterListenersPass();
$registerListenersPass
->process($container);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded.
*/
public function testAbstractEventSubscriber() {
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setAbstract(true)
->addTag('kernel.event_subscriber', array());
$container
->register('event_dispatcher', 'stdClass');
$registerListenersPass = new RegisterListenersPass();
$registerListenersPass
->process($container);
}
public function testEventSubscriberResolvableClassName() {
$container = new ContainerBuilder();
$container
->setParameter('subscriber.class', 'Symfony\\Component\\EventDispatcher\\Tests\\DependencyInjection\\SubscriberService');
$container
->register('foo', '%subscriber.class%')
->addTag('kernel.event_subscriber', array());
$container
->register('event_dispatcher', 'stdClass');
$registerListenersPass = new RegisterListenersPass();
$registerListenersPass
->process($container);
$definition = $container
->getDefinition('event_dispatcher');
$expected_calls = array(
array(
'addSubscriberService',
array(
'foo',
'Symfony\\Component\\EventDispatcher\\Tests\\DependencyInjection\\SubscriberService',
),
),
);
$this
->assertSame($expected_calls, $definition
->getMethodCalls());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage You have requested a non-existent parameter "subscriber.class"
*/
public function testEventSubscriberUnresolvableClassName() {
$container = new ContainerBuilder();
$container
->register('foo', '%subscriber.class%')
->addTag('kernel.event_subscriber', array());
$container
->register('event_dispatcher', 'stdClass');
$registerListenersPass = new RegisterListenersPass();
$registerListenersPass
->process($container);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RegisterListenersPassTest:: |
public | function | @expectedException \InvalidArgumentException @expectedExceptionMessage The service "foo" must not be abstract as event listeners are lazy-loaded. | |
RegisterListenersPassTest:: |
public | function | @expectedException \InvalidArgumentException @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded. | |
RegisterListenersPassTest:: |
public | function | ||
RegisterListenersPassTest:: |
public | function | @expectedException \InvalidArgumentException @expectedExceptionMessage You have requested a non-existent parameter "subscriber.class" | |
RegisterListenersPassTest:: |
public | function | Tests that event subscribers not implementing EventSubscriberInterface trigger an exception. | |
RegisterListenersPassTest:: |
public | function | @expectedException \InvalidArgumentException @expectedExceptionMessage The service "foo" must be public as event listeners are lazy-loaded. | |
RegisterListenersPassTest:: |
public | function | @expectedException \InvalidArgumentException @expectedExceptionMessage The service "foo" must be public as event subscribers are lazy-loaded. | |
RegisterListenersPassTest:: |
public | function |