EventDispatcherTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. class EventDispatcherTest extends TestCase
  16. {
  17. /**
  18. * @expectedException RuntimeException
  19. */
  20. public function testListenerExceptionsAreCaught()
  21. {
  22. $io = $this->getMock('Composer\IO\IOInterface');
  23. $dispatcher = $this->getDispatcherStubForListenersTest(array(
  24. "Composer\Test\Script\EventDispatcherTest::call"
  25. ), $io);
  26. $io->expects($this->once())
  27. ->method('write')
  28. ->with('<error>Script Composer\Test\Script\EventDispatcherTest::call handling the post-install-cmd event terminated with an exception</error>');
  29. $dispatcher->dispatchCommandEvent("post-install-cmd");
  30. }
  31. private function getDispatcherStubForListenersTest($listeners, $io)
  32. {
  33. $dispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')
  34. ->setConstructorArgs(array(
  35. $this->getMock('Composer\Composer'),
  36. $io,
  37. ))
  38. ->setMethods(array('getListeners'))
  39. ->getMock();
  40. $dispatcher->expects($this->atLeastOnce())
  41. ->method('getListeners')
  42. ->will($this->returnValue($listeners));
  43. return $dispatcher;
  44. }
  45. public static function call()
  46. {
  47. throw new \RuntimeException();
  48. }
  49. }