CS fixes & do not replace the exception since that removes the stack trace
parent
b68eb3317b
commit
d3cec0399a
|
@ -91,11 +91,9 @@ class EventDispatcher
|
||||||
try {
|
try {
|
||||||
$className::$methodName($event);
|
$className::$methodName($event);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$message = "%s terminated with an exception.\n[%s] %s";
|
$message = "Script %s handling the %s event terminated with an exception";
|
||||||
throw new \RuntimeException(sprintf($message,
|
$this->io->write('<error>'.sprintf($message, $callable, $event->getName()).'</error>');
|
||||||
$callable,
|
throw $e;
|
||||||
get_class($e),
|
|
||||||
$e->getMessage()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of Composer.
|
* This file is part of Composer.
|
||||||
*
|
*
|
||||||
|
@ -15,48 +16,44 @@ use Composer\Test\TestCase;
|
||||||
use Composer\Script\Event;
|
use Composer\Script\Event;
|
||||||
use Composer\Script\EventDispatcher;
|
use Composer\Script\EventDispatcher;
|
||||||
|
|
||||||
/**
|
|
||||||
* Event Dispatcher Test Case
|
|
||||||
*
|
|
||||||
* @group event-dispatcher
|
|
||||||
* @ticket #693
|
|
||||||
* @author Andrea Turso <turso@officinesoftware.co.uk>
|
|
||||||
*/
|
|
||||||
class EventDispatcherTest extends TestCase
|
class EventDispatcherTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test the doDispatch method properly catches any exception
|
* @expectedException RuntimeException
|
||||||
* thrown from the listener invocation, i.e., <code>$className::$methodName($event)</code>,
|
|
||||||
* and replaces it with a \RuntimeException.
|
|
||||||
*
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
*/
|
*/
|
||||||
public function testListenerExceptionsAreSuppressed()
|
public function testListenerExceptionsAreCaught()
|
||||||
{
|
{
|
||||||
|
$io = $this->getMock('Composer\IO\IOInterface');
|
||||||
$dispatcher = $this->getDispatcherStubForListenersTest(array(
|
$dispatcher = $this->getDispatcherStubForListenersTest(array(
|
||||||
"Composer\Test\Script\EventDispatcherTest::call"
|
"Composer\Test\Script\EventDispatcherTest::call"
|
||||||
));
|
), $io);
|
||||||
|
|
||||||
|
$io->expects($this->once())
|
||||||
|
->method('write')
|
||||||
|
->with('<error>Script Composer\Test\Script\EventDispatcherTest::call handling the post-install-cmd event terminated with an exception</error>');
|
||||||
|
|
||||||
$dispatcher->dispatchCommandEvent("post-install-cmd");
|
$dispatcher->dispatchCommandEvent("post-install-cmd");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDispatcherStubForListenersTest($listeners)
|
private function getDispatcherStubForListenersTest($listeners, $io)
|
||||||
{
|
{
|
||||||
$dispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')
|
$dispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')
|
||||||
->setConstructorArgs(array(
|
->setConstructorArgs(array(
|
||||||
$this->getMock('Composer\Composer'),
|
$this->getMock('Composer\Composer'),
|
||||||
$this->getMock('Composer\IO\IOInterface')))
|
$io,
|
||||||
->setMethods(array('getListeners'))
|
))
|
||||||
->getMock();
|
->setMethods(array('getListeners'))
|
||||||
|
->getMock();
|
||||||
|
|
||||||
$dispatcher->expects($this->atLeastOnce())
|
$dispatcher->expects($this->atLeastOnce())
|
||||||
->method('getListeners')
|
->method('getListeners')
|
||||||
->will($this->returnValue($listeners));
|
->will($this->returnValue($listeners));
|
||||||
|
|
||||||
return $dispatcher;
|
return $dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function call()
|
public static function call()
|
||||||
{
|
{
|
||||||
throw new \Exception();
|
throw new \RuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue