TraceableEventDispatcherTest.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Tests\Debug;
  11. use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\Debug\TraceableEventDispatcher;
  13. class TraceableEventDispatcherTest extends TestCase
  14. {
  15. /**
  16. * @expectedException \RuntimeException
  17. */
  18. public function testThrowsAnExceptionWhenAListenerMethodIsNotCallable()
  19. {
  20. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  21. $dispatcher = new TraceableEventDispatcher($container);
  22. $dispatcher->addListener('onFooEvent', new \stdClass());
  23. }
  24. public function testStaticCallable()
  25. {
  26. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  27. $dispatcher = new TraceableEventDispatcher($container);
  28. $dispatcher->addListener('onFooEvent', array(__NAMESPACE__.'\StaticClassFixture', 'staticListener'));
  29. $dispatcher->dispatch('onFooEvent');
  30. $this->assertTrue(StaticClassFixture::$called);
  31. }
  32. }
  33. class StaticClassFixture
  34. {
  35. static public $called = false;
  36. static public function staticListener($event)
  37. {
  38. self::$called = true;
  39. }
  40. }