EventDispatcherTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Script;
  12. use Composer\Test\TestCase;
  13. use Composer\Script\Event;
  14. use Composer\Script\EventDispatcher;
  15. /**
  16. * Event Dispatcher Test Case
  17. *
  18. * @group event-dispatcher
  19. * @ticket #693
  20. * @author Andrea Turso <turso@officinesoftware.co.uk>
  21. */
  22. class EventDispatcherTest extends TestCase
  23. {
  24. /**
  25. * Test the doDispatch method properly catches any exception
  26. * thrown from the listener invocation, i.e., <code>$className::$methodName($event)</code>,
  27. * and replaces it with a \RuntimeException.
  28. *
  29. * @expectedException \RuntimeException
  30. */
  31. public function testListenerExceptionsAreSuppressed()
  32. {
  33. $dispatcher = $this->getDispatcherStubForListenersTest(array(
  34. "Composer\Test\Script\EventDispatcherTest::call"
  35. ));
  36. $dispatcher->dispatchCommandEvent("post-install-cmd");
  37. }
  38. private function getDispatcherStubForListenersTest($listeners)
  39. {
  40. $dispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')
  41. ->setConstructorArgs(array(
  42. $this->getMock('Composer\Composer'),
  43. $this->getMock('Composer\IO\IOInterface')))
  44. ->setMethods(array('getListeners'))
  45. ->getMock();
  46. $dispatcher->expects($this->atLeastOnce())
  47. ->method('getListeners')
  48. ->will($this->returnValue($listeners));
  49. return $dispatcher;
  50. }
  51. public static function call()
  52. {
  53. throw new \Exception();
  54. }
  55. }