class RegisterListenersPassTest

Hierarchy

  • class \Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterListenersPassTest extends \Symfony\Component\HttpKernel\Tests\DependencyInjection\PHPUnit_Framework_TestCase

Expanded class hierarchy of RegisterListenersPassTest

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterListenersPassTest.php, line 18

Namespace

Symfony\Component\HttpKernel\Tests\DependencyInjection
View 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('getClass')
      ->will($this
      ->returnValue('stdClass'));
    $builder = $this
      ->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder');
    $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('getClass')
      ->will($this
      ->returnValue('Symfony\\Component\\HttpKernel\\Tests\\DependencyInjection\\SubscriberService'));
    $builder = $this
      ->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder');
    $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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RegisterListenersPassTest::testEventSubscriberWithoutInterface public function Tests that event subscribers not implementing EventSubscriberInterface trigger an exception.
RegisterListenersPassTest::testValidEventSubscriber public function