1
0
Fork 0

Merge pull request #3547 from alcohol/fix-reflection

fix reflection implementation in EventDispatcher
pull/3549/head
Jordi Boggiano 2014-12-12 22:45:23 +00:00
commit 89a7202399
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;
}