You are here

public function RegisterListenersPassTest::testEventSubscriberWithoutInterface in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/event-dispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php \Symfony\Component\EventDispatcher\Tests\DependencyInjection\RegisterListenersPassTest::testEventSubscriberWithoutInterface()

Tests that event subscribers not implementing EventSubscriberInterface trigger an exception.

@expectedException \InvalidArgumentException

File

vendor/symfony/event-dispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php, line 25

Class

RegisterListenersPassTest

Namespace

Symfony\Component\EventDispatcher\Tests\DependencyInjection

Code

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);
}