commit
73a8e2c1ab
|
@ -39,64 +39,76 @@ class ClassMapGeneratorTest extends TestCase
|
|||
$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(
|
||||
array(__DIR__.'/Fixtures/Namespaced', array(
|
||||
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.inc',
|
||||
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
|
||||
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
|
||||
array(__DIR__ . '/Fixtures/Namespaced', array(
|
||||
'Namespaced\\Bar' => realpath(__DIR__) . '/Fixtures/Namespaced/Bar.inc',
|
||||
'Namespaced\\Foo' => realpath(__DIR__) . '/Fixtures/Namespaced/Foo.php',
|
||||
'Namespaced\\Baz' => realpath(__DIR__) . '/Fixtures/Namespaced/Baz.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
|
||||
'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',
|
||||
array(__DIR__ . '/Fixtures/beta/NamespaceCollision', array(
|
||||
'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',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/Pearlike', array(
|
||||
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php',
|
||||
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php',
|
||||
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php',
|
||||
array(__DIR__ . '/Fixtures/Pearlike', array(
|
||||
'Pearlike_Foo' => realpath(__DIR__) . '/Fixtures/Pearlike/Foo.php',
|
||||
'Pearlike_Bar' => realpath(__DIR__) . '/Fixtures/Pearlike/Bar.php',
|
||||
'Pearlike_Baz' => realpath(__DIR__) . '/Fixtures/Pearlike/Baz.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/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',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/template', array()),
|
||||
array(__DIR__ . '/Fixtures/classmap', $classmap),
|
||||
array(__DIR__ . '/Fixtures/template', array()),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
|
||||
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\IBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TFooBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
$data[] = array(__DIR__ . '/Fixtures/php5.4', array(
|
||||
'TFoo' => __DIR__ . '/Fixtures/php5.4/traits.php',
|
||||
'CFoo' => __DIR__ . '/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TBar' => __DIR__ . '/Fixtures/php5.4/traits.php',
|
||||
'Foo\\IBar' => __DIR__ . '/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TFooBar' => __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',
|
||||
$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', '>=')) {
|
||||
$data[] = array(__DIR__.'/Fixtures/hhvm3.3', array(
|
||||
'FooEnum' => __DIR__.'/Fixtures/hhvm3.3/HackEnum.php',
|
||||
'Foo\BarEnum' => __DIR__.'/Fixtures/hhvm3.3/NamespacedHackEnum.php',
|
||||
'GenericsClass' => __DIR__.'/Fixtures/hhvm3.3/Generics.php',
|
||||
$data[] = array(__DIR__ . '/Fixtures/hhvm3.3', array(
|
||||
'FooEnum' => __DIR__ . '/Fixtures/hhvm3.3/HackEnum.php',
|
||||
'Foo\BarEnum' => __DIR__ . '/Fixtures/hhvm3.3/NamespacedHackEnum.php',
|
||||
'GenericsClass' => __DIR__ . '/Fixtures/hhvm3.3/Generics.php',
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -111,8 +123,8 @@ class ClassMapGeneratorTest extends TestCase
|
|||
$finder->files()->in(__DIR__ . '/Fixtures/beta/NamespaceCollision');
|
||||
|
||||
$this->assertEqualsNormalized(array(
|
||||
'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\\Bar' => realpath(__DIR__) . '/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
|
||||
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__) . '/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
|
||||
), ClassMapGenerator::createMap($finder));
|
||||
}
|
||||
|
||||
|
@ -126,7 +138,7 @@ class ClassMapGeneratorTest extends TestCase
|
|||
$find = $r->getMethod('findClasses');
|
||||
$find->setAccessible(true);
|
||||
|
||||
$find->invoke(null, __DIR__.'/no-file');
|
||||
$find->invoke(null, __DIR__ . '/no-file');
|
||||
}
|
||||
|
||||
public function testAmbiguousReference()
|
||||
|
@ -134,7 +146,7 @@ class ClassMapGeneratorTest extends TestCase
|
|||
$this->checkIfFinderIsAvailable();
|
||||
|
||||
$tempDir = $this->getUniqueTmpDirectory();
|
||||
$this->ensureDirectoryExistsAndClear($tempDir.'/other');
|
||||
$this->ensureDirectoryExistsAndClear($tempDir . '/other');
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->files()->in($tempDir);
|
||||
|
@ -143,11 +155,11 @@ class ClassMapGeneratorTest extends TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
file_put_contents($tempDir.'/A.php', "<?php\nclass A {}");
|
||||
file_put_contents($tempDir.'/other/A.php', "<?php\nclass A {}");
|
||||
file_put_contents($tempDir . '/A.php', "<?php\nclass A {}");
|
||||
file_put_contents($tempDir . '/other/A.php', "<?php\nclass A {}");
|
||||
|
||||
$a = realpath($tempDir.'/A.php');
|
||||
$b = realpath($tempDir.'/other/A.php');
|
||||
$a = realpath($tempDir . '/A.php');
|
||||
$b = realpath($tempDir . '/other/A.php');
|
||||
$msg = '';
|
||||
|
||||
$io->expects($this->once())
|
||||
|
@ -157,13 +169,13 @@ class ClassMapGeneratorTest extends TestCase
|
|||
}));
|
||||
|
||||
$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 "'.$b.'" and "'.$a.'", 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>',
|
||||
);
|
||||
|
||||
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->removeDirectory($tempDir);
|
||||
|
@ -177,9 +189,9 @@ class ClassMapGeneratorTest extends TestCase
|
|||
{
|
||||
$tempDir = $this->getUniqueTmpDirectory();
|
||||
|
||||
file_put_contents($tempDir.'/A.php', "<?php\nclass A {}");
|
||||
file_put_contents($tempDir . '/A.php', "<?php\nclass A {}");
|
||||
file_put_contents(
|
||||
$tempDir.'/B.php',
|
||||
$tempDir . '/B.php',
|
||||
"<?php
|
||||
if (true) {
|
||||
interface B {}
|
||||
|
@ -190,10 +202,10 @@ class ClassMapGeneratorTest extends TestCase
|
|||
);
|
||||
|
||||
foreach (array('test', 'fixture', 'example') as $keyword) {
|
||||
if (!is_dir($tempDir.'/'.$keyword)) {
|
||||
mkdir($tempDir.'/'.$keyword, 0777, true);
|
||||
if (!is_dir($tempDir . '/' . $keyword)) {
|
||||
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')
|
||||
|
@ -215,7 +227,7 @@ class ClassMapGeneratorTest extends TestCase
|
|||
*/
|
||||
public function testCreateMapThrowsWhenDirectoryDoesNotExist()
|
||||
{
|
||||
ClassMapGenerator::createMap(__DIR__.'/no-file.no-foler');
|
||||
ClassMapGenerator::createMap(__DIR__ . '/no-file.no-foler');
|
||||
}
|
||||
|
||||
public function testDump()
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<?
|
||||
|
||||
class ShortOpenTag {}
|
|
@ -0,0 +1,5 @@
|
|||
<?
|
||||
/**
|
||||
* Some class description here.
|
||||
*/
|
||||
class ShortOpenTagDocblock {}
|
Loading…
Reference in New Issue