1
0
Fork 0

Merge pull request #5708 from alcohol/issue-5701

test cases for #5701
pull/5688/merge
Jordi Boggiano 2016-09-23 13:33:28 +02:00 committed by GitHub
commit 73a8e2c1ab
3 changed files with 82 additions and 62 deletions

View File

@ -39,64 +39,76 @@ class ClassMapGeneratorTest extends TestCase
$this->markTestSkipped('Test segfaults on travis 5.3.3 due to ClassMap\LongString'); $this->markTestSkipped('Test segfaults on travis 5.3.3 due to ClassMap\LongString');
} }
$classmap = array(
'Foo\\Bar\\A' => realpath(__DIR__) . '/Fixtures/classmap/sameNsMultipleClasses.php',
'Foo\\Bar\\B' => realpath(__DIR__) . '/Fixtures/classmap/sameNsMultipleClasses.php',
'Alpha\\A' => realpath(__DIR__) . '/Fixtures/classmap/multipleNs.php',
'Alpha\\B' => realpath(__DIR__) . '/Fixtures/classmap/multipleNs.php',
'A' => realpath(__DIR__) . '/Fixtures/classmap/multipleNs.php',
'Be\\ta\\A' => realpath(__DIR__) . '/Fixtures/classmap/multipleNs.php',
'Be\\ta\\B' => realpath(__DIR__) . '/Fixtures/classmap/multipleNs.php',
'ClassMap\\SomeInterface' => realpath(__DIR__) . '/Fixtures/classmap/SomeInterface.php',
'ClassMap\\SomeParent' => realpath(__DIR__) . '/Fixtures/classmap/SomeParent.php',
'ClassMap\\SomeClass' => realpath(__DIR__) . '/Fixtures/classmap/SomeClass.php',
'ClassMap\\LongString' => realpath(__DIR__) . '/Fixtures/classmap/LongString.php',
'Foo\\LargeClass' => realpath(__DIR__) . '/Fixtures/classmap/LargeClass.php',
'Foo\\LargeGap' => realpath(__DIR__) . '/Fixtures/classmap/LargeGap.php',
'Foo\\MissingSpace' => realpath(__DIR__) . '/Fixtures/classmap/MissingSpace.php',
'Foo\\StripNoise' => realpath(__DIR__) . '/Fixtures/classmap/StripNoise.php',
'Foo\\SlashedA' => realpath(__DIR__) . '/Fixtures/classmap/BackslashLineEndingString.php',
'Foo\\SlashedB' => realpath(__DIR__) . '/Fixtures/classmap/BackslashLineEndingString.php',
'Unicode\\↑\\↑' => realpath(__DIR__) . '/Fixtures/classmap/Unicode.php',
'ShortOpenTag' => realpath(__DIR__) . '/Fixtures/classmap/ShortOpenTag.php',
'ShortOpenTagDocblock' => realpath(__DIR__) . '/Fixtures/classmap/ShortOpenTagDocblock.php',
);
/**
* @wontfix If short_open_tag is not enabled, we end up parsing the docblock because
* php_strip_whitespace won't recognize the file. Funky edge-case (does not apply to HHVM).
*/
if (!defined('HHVM_VERSION') && !ini_get('short_open_tag')) {
$classmap['description'] = realpath(__DIR__) . '/Fixtures/classmap/ShortOpenTagDocblock.php';
}
$data = array( $data = array(
array(__DIR__.'/Fixtures/Namespaced', array( array(__DIR__ . '/Fixtures/Namespaced', array(
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.inc', 'Namespaced\\Bar' => realpath(__DIR__) . '/Fixtures/Namespaced/Bar.inc',
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php', 'Namespaced\\Foo' => realpath(__DIR__) . '/Fixtures/Namespaced/Foo.php',
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php', 'Namespaced\\Baz' => realpath(__DIR__) . '/Fixtures/Namespaced/Baz.php',
)), )),
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array( array(__DIR__ . '/Fixtures/beta/NamespaceCollision', array(
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php', 'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__) . '/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Foo.php', 'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__) . '/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
)), )),
array(__DIR__.'/Fixtures/Pearlike', array( array(__DIR__ . '/Fixtures/Pearlike', array(
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php', 'Pearlike_Foo' => realpath(__DIR__) . '/Fixtures/Pearlike/Foo.php',
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php', 'Pearlike_Bar' => realpath(__DIR__) . '/Fixtures/Pearlike/Bar.php',
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php', 'Pearlike_Baz' => realpath(__DIR__) . '/Fixtures/Pearlike/Baz.php',
)), )),
array(__DIR__.'/Fixtures/classmap', array( array(__DIR__ . '/Fixtures/classmap', $classmap),
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php', array(__DIR__ . '/Fixtures/template', array()),
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Be\\ta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'Be\\ta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
'ClassMap\\LongString' => realpath(__DIR__).'/Fixtures/classmap/LongString.php',
'Foo\\LargeClass' => realpath(__DIR__).'/Fixtures/classmap/LargeClass.php',
'Foo\\LargeGap' => realpath(__DIR__).'/Fixtures/classmap/LargeGap.php',
'Foo\\MissingSpace' => realpath(__DIR__).'/Fixtures/classmap/MissingSpace.php',
'Foo\\StripNoise' => realpath(__DIR__).'/Fixtures/classmap/StripNoise.php',
'Foo\\SlashedA' => realpath(__DIR__).'/Fixtures/classmap/BackslashLineEndingString.php',
'Foo\\SlashedB' => realpath(__DIR__).'/Fixtures/classmap/BackslashLineEndingString.php',
'Unicode\\↑\\↑' => realpath(__DIR__).'/Fixtures/classmap/Unicode.php',
)),
array(__DIR__.'/Fixtures/template', array()),
); );
if (PHP_VERSION_ID >= 50400) { if (PHP_VERSION_ID >= 50400) {
$data[] = array(__DIR__.'/Fixtures/php5.4', array( $data[] = array(__DIR__ . '/Fixtures/php5.4', array(
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php', 'TFoo' => __DIR__ . '/Fixtures/php5.4/traits.php',
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php', 'CFoo' => __DIR__ . '/Fixtures/php5.4/traits.php',
'Foo\\TBar' => __DIR__.'/Fixtures/php5.4/traits.php', 'Foo\\TBar' => __DIR__ . '/Fixtures/php5.4/traits.php',
'Foo\\IBar' => __DIR__.'/Fixtures/php5.4/traits.php', 'Foo\\IBar' => __DIR__ . '/Fixtures/php5.4/traits.php',
'Foo\\TFooBar' => __DIR__.'/Fixtures/php5.4/traits.php', 'Foo\\TFooBar' => __DIR__ . '/Fixtures/php5.4/traits.php',
'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php', 'Foo\\CBar' => __DIR__ . '/Fixtures/php5.4/traits.php',
)); ));
} }
if (PHP_VERSION_ID >= 70000) { if (PHP_VERSION_ID >= 70000) {
$data[] = array(__DIR__.'/Fixtures/php7.0', array( $data[] = array(__DIR__ . '/Fixtures/php7.0', array(
'Dummy\Test\AnonClassHolder' => __DIR__.'/Fixtures/php7.0/anonclass.php', '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',
'Foo\BarEnum' => __DIR__.'/Fixtures/hhvm3.3/NamespacedHackEnum.php', 'Foo\BarEnum' => __DIR__ . '/Fixtures/hhvm3.3/NamespacedHackEnum.php',
'GenericsClass' => __DIR__.'/Fixtures/hhvm3.3/Generics.php', 'GenericsClass' => __DIR__ . '/Fixtures/hhvm3.3/Generics.php',
)); ));
} }
@ -111,8 +123,8 @@ class ClassMapGeneratorTest extends TestCase
$finder->files()->in(__DIR__ . '/Fixtures/beta/NamespaceCollision'); $finder->files()->in(__DIR__ . '/Fixtures/beta/NamespaceCollision');
$this->assertEqualsNormalized(array( $this->assertEqualsNormalized(array(
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php', 'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__) . '/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Foo.php', 'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__) . '/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
), ClassMapGenerator::createMap($finder)); ), ClassMapGenerator::createMap($finder));
} }
@ -126,7 +138,7 @@ class ClassMapGeneratorTest extends TestCase
$find = $r->getMethod('findClasses'); $find = $r->getMethod('findClasses');
$find->setAccessible(true); $find->setAccessible(true);
$find->invoke(null, __DIR__.'/no-file'); $find->invoke(null, __DIR__ . '/no-file');
} }
public function testAmbiguousReference() public function testAmbiguousReference()
@ -134,7 +146,7 @@ class ClassMapGeneratorTest extends TestCase
$this->checkIfFinderIsAvailable(); $this->checkIfFinderIsAvailable();
$tempDir = $this->getUniqueTmpDirectory(); $tempDir = $this->getUniqueTmpDirectory();
$this->ensureDirectoryExistsAndClear($tempDir.'/other'); $this->ensureDirectoryExistsAndClear($tempDir . '/other');
$finder = new Finder(); $finder = new Finder();
$finder->files()->in($tempDir); $finder->files()->in($tempDir);
@ -143,11 +155,11 @@ class ClassMapGeneratorTest extends TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
file_put_contents($tempDir.'/A.php', "<?php\nclass A {}"); file_put_contents($tempDir . '/A.php', "<?php\nclass A {}");
file_put_contents($tempDir.'/other/A.php', "<?php\nclass A {}"); file_put_contents($tempDir . '/other/A.php', "<?php\nclass A {}");
$a = realpath($tempDir.'/A.php'); $a = realpath($tempDir . '/A.php');
$b = realpath($tempDir.'/other/A.php'); $b = realpath($tempDir . '/other/A.php');
$msg = ''; $msg = '';
$io->expects($this->once()) $io->expects($this->once())
@ -157,13 +169,13 @@ class ClassMapGeneratorTest extends TestCase
})); }));
$messages = array( $messages = array(
'<warning>Warning: Ambiguous class resolution, "A" was found in both "'.$a.'" and "'.$b.'", the first will be used.</warning>', '<warning>Warning: Ambiguous class resolution, "A" was found in both "' . $a . '" and "' . $b . '", the first will be used.</warning>',
'<warning>Warning: Ambiguous class resolution, "A" was found in both "'.$b.'" and "'.$a.'", the first will be used.</warning>', '<warning>Warning: Ambiguous class resolution, "A" was found in both "' . $b . '" and "' . $a . '", the first will be used.</warning>',
); );
ClassMapGenerator::createMap($finder, null, $io); ClassMapGenerator::createMap($finder, null, $io);
$this->assertTrue(in_array($msg, $messages, true), $msg.' not found in expected messages ('.var_export($messages, true).')'); $this->assertTrue(in_array($msg, $messages, true), $msg . ' not found in expected messages (' . var_export($messages, true) . ')');
$fs = new Filesystem(); $fs = new Filesystem();
$fs->removeDirectory($tempDir); $fs->removeDirectory($tempDir);
@ -177,9 +189,9 @@ class ClassMapGeneratorTest extends TestCase
{ {
$tempDir = $this->getUniqueTmpDirectory(); $tempDir = $this->getUniqueTmpDirectory();
file_put_contents($tempDir.'/A.php', "<?php\nclass A {}"); file_put_contents($tempDir . '/A.php', "<?php\nclass A {}");
file_put_contents( file_put_contents(
$tempDir.'/B.php', $tempDir . '/B.php',
"<?php "<?php
if (true) { if (true) {
interface B {} interface B {}
@ -190,10 +202,10 @@ class ClassMapGeneratorTest extends TestCase
); );
foreach (array('test', 'fixture', 'example') as $keyword) { foreach (array('test', 'fixture', 'example') as $keyword) {
if (!is_dir($tempDir.'/'.$keyword)) { if (!is_dir($tempDir . '/' . $keyword)) {
mkdir($tempDir.'/'.$keyword, 0777, true); mkdir($tempDir . '/' . $keyword, 0777, true);
} }
file_put_contents($tempDir.'/'.$keyword.'/A.php', "<?php\nclass A {}"); file_put_contents($tempDir . '/' . $keyword . '/A.php', "<?php\nclass A {}");
} }
$io = $this->getMockBuilder('Composer\IO\ConsoleIO') $io = $this->getMockBuilder('Composer\IO\ConsoleIO')
@ -215,7 +227,7 @@ class ClassMapGeneratorTest extends TestCase
*/ */
public function testCreateMapThrowsWhenDirectoryDoesNotExist() public function testCreateMapThrowsWhenDirectoryDoesNotExist()
{ {
ClassMapGenerator::createMap(__DIR__.'/no-file.no-foler'); ClassMapGenerator::createMap(__DIR__ . '/no-file.no-foler');
} }
public function testDump() public function testDump()

View File

@ -0,0 +1,3 @@
<?
class ShortOpenTag {}

View File

@ -0,0 +1,5 @@
<?
/**
* Some class description here.
*/
class ShortOpenTagDocblock {}