1
0
Fork 0

Add unit tests for ClassLoader, covering PSR-0 and PSR-4.

pull/2459/head
Andreas Hennings 2013-09-26 23:44:21 +02:00
parent b08179e399
commit 2c98813431
3 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,65 @@
<?php
namespace Composer\Test\Autoload;
use Composer\Autoload\ClassLoader;
/**
* Tests the Composer\Autoload\ClassLoader class.
*/
class ClassLoaderTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests regular PSR-0 and PSR-4 class loading.
*
* @dataProvider getLoadClassTests
*
* @param string $class
* The fully-qualified class name to test,
* without preceding namespace separator.
* @param bool $prependSeparator
* Whether to call ->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', '\\'),
);
}
}

View File

@ -0,0 +1,5 @@
<?php
namespace ShinyVendor\ShinyPackage\SubNamespace;
class Bar {}

View File

@ -0,0 +1,5 @@
<?php
namespace ShinyVendor\ShinyPackage\SubNamespace;
class Foo {}