Merge pull request #3547 from alcohol/fix-reflection
fix reflection implementation in EventDispatcherpull/3549/head
commit
89a7202399
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue