diff --git a/tests/Composer/Test/Autoload/ClassLoaderTest.php b/tests/Composer/Test/Autoload/ClassLoaderTest.php new file mode 100644 index 000000000..7a8ae253b --- /dev/null +++ b/tests/Composer/Test/Autoload/ClassLoaderTest.php @@ -0,0 +1,65 @@ +loadClass() with a class name with preceding + * namespace separator, as it happens in PHP 5.3.0 - 5.3.2. + * See https://bugs.php.net/50731 + */ + public function testLoadClass($class, $prependSeparator = FALSE) + { + $loader = new ClassLoader(); + $loader->add('Namespaced\\', __DIR__ . '/Fixtures'); + $loader->add('Pearlike_', __DIR__ . '/Fixtures'); + $loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures'); + + if ($prependSeparator) { + $prepend = '\\'; + $message = "->loadClass() loads '$class'."; + } + else { + $prepend = ''; + $message = "->loadClass() loads '\\$class', as required in PHP 5.3.0 - 5.3.2."; + } + + $loader->loadClass($prepend . $class); + $this->assertTrue(class_exists($class, false), $message); + } + + /** + * Provides arguments for ->testLoadClass(). + * + * @return array + * Array of parameter sets to test with. + */ + public function getLoadClassTests() + { + return array( + array('Namespaced\\Foo'), + array('Pearlike_Foo'), + array('ShinyVendor\\ShinyPackage\\SubNamespace\\Foo'), + // "Bar" would not work here, since it is defined in a ".inc" file, + // instead of a ".php" file. So, use "Baz" instead. + array('Namespaced\\Baz', '\\'), + array('Pearlike_Bar', '\\'), + array('ShinyVendor\\ShinyPackage\\SubNamespace\\Bar', '\\'), + ); + } + +} diff --git a/tests/Composer/Test/Autoload/Fixtures/SubNamespace/Bar.php b/tests/Composer/Test/Autoload/Fixtures/SubNamespace/Bar.php new file mode 100644 index 000000000..74cd9d7f3 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/SubNamespace/Bar.php @@ -0,0 +1,5 @@ +