1
0
Fork 0
Rob 2014-12-12 22:33:04 +01:00
parent 76c666e210
commit d9b8b3611b
2 changed files with 25 additions and 4 deletions

View File

@ -223,7 +223,13 @@ class EventDispatcher
return $event;
}
$expected = $reflected->getClass()->name;
$typehint = $reflected->getClass();
if (!$typehint instanceof \ReflectionClass) {
return $event;
}
$expected = $typehint->getName();
if (!$event instanceof $expected && $expected === 'Composer\Script\CommandEvent') {
$event = new CommandEvent($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments());

View File

@ -29,7 +29,7 @@ class EventDispatcherTest extends TestCase
{
$io = $this->getMock('Composer\IO\IOInterface');
$dispatcher = $this->getDispatcherStubForListenersTest(array(
"Composer\Test\EventDispatcher\EventDispatcherTest::call"
'Composer\Test\EventDispatcher\EventDispatcherTest::call'
), $io);
$io->expects($this->once())
@ -43,7 +43,17 @@ class EventDispatcherTest extends TestCase
{
$io = $this->getMock('Composer\IO\IOInterface');
$dispatcher = $this->getDispatcherStubForListenersTest(array(
"Composer\Test\EventDispatcher\EventDispatcherTest::convertEvent"
'Composer\Test\EventDispatcher\EventDispatcherTest::expectsCommandEvent'
), $io);
$this->assertEquals(1, $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false));
}
public function testDispatcherDoesNotAttemptConversionForListenerWithoutTypehint()
{
$io = $this->getMock('Composer\IO\IOInterface');
$dispatcher = $this->getDispatcherStubForListenersTest(array(
'Composer\Test\EventDispatcher\EventDispatcherTest::expectsVariableEvent'
), $io);
$this->assertEquals(1, $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false));
@ -216,7 +226,12 @@ class EventDispatcherTest extends TestCase
throw new \RuntimeException();
}
public static function convertEvent(CommandEvent $event)
public static function expectsCommandEvent(CommandEvent $event)
{
return false;
}
public static function expectsVariableEvent($event)
{
return false;
}