1
0
Fork 0

Fix shell command output, fixes #1295

pull/1399/head
Jordi Boggiano 2012-12-06 09:56:27 +01:00
parent 04c6670f0c
commit 7d7eb3b2e8
2 changed files with 50 additions and 2 deletions

View File

@ -105,8 +105,8 @@ class EventDispatcher
throw $e; throw $e;
} }
} else { } else {
if (0 !== $this->process->execute($callable, $callback)) { if (0 !== $this->process->execute($callable)) {
$event->getIO()->write(sprintf('<error>Script %s handling the %s event returned with an error: %s</script>', $callable, $event->getName(), $this->process->getErrorOutput())); $event->getIO()->write(sprintf('<error>Script %s handling the %s event returned with an error: %s</error>', $callable, $event->getName(), $this->process->getErrorOutput()));
} }
} }
} }

View File

@ -15,6 +15,7 @@ namespace Composer\Test\Script;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Script\Event; use Composer\Script\Event;
use Composer\Script\EventDispatcher; use Composer\Script\EventDispatcher;
use Composer\Util\ProcessExecutor;
class EventDispatcherTest extends TestCase 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('<error>Script '.$code.' handling the post-install-cmd event returned with an error: bar '.PHP_EOL.'</error>'));
ob_start();
$dispatcher->dispatchCommandEvent("post-install-cmd", false);
$this->assertEquals('bar', trim(ob_get_clean()));
}
public static function call() public static function call()
{ {
throw new \RuntimeException(); throw new \RuntimeException();