diff --git a/src/Composer/Script/EventDispatcher.php b/src/Composer/Script/EventDispatcher.php index f64e27ad3..48428a664 100644 --- a/src/Composer/Script/EventDispatcher.php +++ b/src/Composer/Script/EventDispatcher.php @@ -105,8 +105,8 @@ class EventDispatcher throw $e; } } else { - if (0 !== $this->process->execute($callable, $callback)) { - $event->getIO()->write(sprintf('Script %s handling the %s event returned with an error: %s', $callable, $event->getName(), $this->process->getErrorOutput())); + if (0 !== $this->process->execute($callable)) { + $event->getIO()->write(sprintf('Script %s handling the %s event returned with an error: %s', $callable, $event->getName(), $this->process->getErrorOutput())); } } } diff --git a/tests/Composer/Test/Script/EventDispatcherTest.php b/tests/Composer/Test/Script/EventDispatcherTest.php index 4da90ecee..46f8a2383 100644 --- a/tests/Composer/Test/Script/EventDispatcherTest.php +++ b/tests/Composer/Test/Script/EventDispatcherTest.php @@ -15,6 +15,7 @@ namespace Composer\Test\Script; use Composer\Test\TestCase; use Composer\Script\Event; use Composer\Script\EventDispatcher; +use Composer\Util\ProcessExecutor; class EventDispatcherTest extends TestCase { @@ -124,6 +125,53 @@ class EventDispatcherTest extends TestCase ); } + public function testDispatcherOutputsCommands() + { + $dispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher') + ->setConstructorArgs(array( + $this->getMock('Composer\Composer'), + $this->getMock('Composer\IO\IOInterface'), + new ProcessExecutor, + )) + ->setMethods(array('getListeners')) + ->getMock(); + + $listener = array('echo foo'); + $dispatcher->expects($this->atLeastOnce()) + ->method('getListeners') + ->will($this->returnValue($listener)); + + ob_start(); + $dispatcher->dispatchCommandEvent("post-install-cmd", false); + $this->assertEquals('foo', trim(ob_get_clean())); + } + + public function testDispatcherOutputsErrorOnFailedCommand() + { + $dispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher') + ->setConstructorArgs(array( + $this->getMock('Composer\Composer'), + $io = $this->getMock('Composer\IO\IOInterface'), + new ProcessExecutor, + )) + ->setMethods(array('getListeners')) + ->getMock(); + + $code = sprintf('echo bar>&2 %s exit 1', defined('PHP_WINDOWS_VERSION_BUILD') ? '&' : ';'); + $listener = array($code); + $dispatcher->expects($this->atLeastOnce()) + ->method('getListeners') + ->will($this->returnValue($listener)); + + $io->expects($this->once()) + ->method('write') + ->with($this->equalTo('Script '.$code.' handling the post-install-cmd event returned with an error: bar '.PHP_EOL.'')); + + ob_start(); + $dispatcher->dispatchCommandEvent("post-install-cmd", false); + $this->assertEquals('bar', trim(ob_get_clean())); + } + public static function call() { throw new \RuntimeException();