1
0
Fork 0

Fix classmap generator over anonymous classes extending/implementing something, fixes #5239

pull/5245/head
Jordi Boggiano 2016-04-24 14:40:51 +01:00
parent ec933398c4
commit f0d67923a5
3 changed files with 52 additions and 0 deletions

View File

@ -188,6 +188,10 @@ class ClassMapGenerator
$namespace = str_replace(array(' ', "\t", "\r", "\n"), '', $matches['nsname'][$i]) . '\\'; $namespace = str_replace(array(' ', "\t", "\r", "\n"), '', $matches['nsname'][$i]) . '\\';
} else { } else {
$name = $matches['name'][$i]; $name = $matches['name'][$i];
// skip anon classes extending/implementing
if ($name === 'extends' || $name === 'implements') {
continue;
}
if ($name[0] === ':') { if ($name[0] === ':') {
// This is an XHP class, https://github.com/facebook/xhp // This is an XHP class, https://github.com/facebook/xhp
$name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1); $name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);

View File

@ -87,6 +87,11 @@ class ClassMapGeneratorTest extends TestCase
'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php', 'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php',
)); ));
} }
if (PHP_VERSION_ID >= 70000) {
$data[] = array(__DIR__.'/Fixtures/php7.0', array(
'Dummy\Test\AnonClassHolder' => __DIR__.'/Fixtures/php7.0/anonclass.php',
));
}
if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) { if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) {
$data[] = array(__DIR__.'/Fixtures/hhvm3.3', array( $data[] = array(__DIR__.'/Fixtures/hhvm3.3', array(
'FooEnum' => __DIR__.'/Fixtures/hhvm3.3/HackEnum.php', 'FooEnum' => __DIR__.'/Fixtures/hhvm3.3/HackEnum.php',

View File

@ -0,0 +1,43 @@
<?php
declare(strict_types = 1);
namespace Dummy\Test;
use Dummy\Common\TestCase;
class AnonClassHolder extends TestCase
{
protected function getTest(): ClassAvailability
{
return new class extends ClassAvailability
{
};
}
protected function getTest2(): ClassAvailability
{
return new class(2) extends ClassAvailability
{
};
}
protected function getTest3(): ClassAvailability
{
return new class(2, 3) extends ClassAvailability
{
};
}
protected function getTest4(): ClassAvailability
{
return new class(2, 3) {
};
}
protected function getTest5(): ClassAvailability
{
return new class implements FooInterface {
};
}
}