getNamespaces test
getPrefixes test loadClass test getPrefixes test addPrefix test getFallbackDirs test fix things pointed out by stof
This commit is contained in:
parent
2cf3cb5b7a
commit
8c74b55a27
@ -15,6 +15,28 @@ use Symfony\Component\ClassLoader\ClassLoader;
|
|||||||
|
|
||||||
class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
public function testGetPrefixes()
|
||||||
|
{
|
||||||
|
$loader = new ClassLoader();
|
||||||
|
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->addPrefix('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->addPrefix('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$prefixes = $loader->getPrefixes();
|
||||||
|
$this->assertArrayHasKey('Foo', $prefixes);
|
||||||
|
$this->assertArrayNotHasKey('Foo1', $prefixes);
|
||||||
|
$this->assertArrayHasKey('Bar', $prefixes);
|
||||||
|
$this->assertArrayHasKey('Bas', $prefixes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetFallbackDirs()
|
||||||
|
{
|
||||||
|
$loader = new ClassLoader();
|
||||||
|
$loader->addPrefix(null, __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->addPrefix(null, __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$fallback_dirs = $loader->getFallbackDirs();
|
||||||
|
$this->assertCount(2, $fallback_dirs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getLoadClassTests
|
* @dataProvider getLoadClassTests
|
||||||
*/
|
*/
|
||||||
@ -37,6 +59,35 @@ class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getLoadNonexistentClassTests
|
||||||
|
*/
|
||||||
|
public function testLoadNonexistentClass($className, $testClassName, $message)
|
||||||
|
{
|
||||||
|
$loader = new ClassLoader();
|
||||||
|
$loader->addPrefix('Namespaced2\\', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->addPrefix('Pearlike2_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->loadClass($testClassName);
|
||||||
|
$this->assertFalse(class_exists($className), $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLoadNonexistentClassTests()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('\\Pearlike3_Bar', '\\Pearlike3_Bar', '->loadClass() loads non exising Pearlike3_Bar class with a leading slash'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddPrefix()
|
||||||
|
{
|
||||||
|
$loader = new ClassLoader();
|
||||||
|
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$prefixes = $loader->getPrefixes();
|
||||||
|
$this->assertArrayHasKey('Foo', $prefixes);
|
||||||
|
$this->assertCount(2, $prefixes['Foo']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testUseIncludePath()
|
public function testUseIncludePath()
|
||||||
{
|
{
|
||||||
$loader = new ClassLoader();
|
$loader = new ClassLoader();
|
||||||
|
@ -56,6 +56,32 @@ class UniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
set_include_path($includePath);
|
set_include_path($includePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetNamespaces()
|
||||||
|
{
|
||||||
|
$loader = new UniversalClassLoader();
|
||||||
|
$loader->registerNamespace('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->registerNamespace('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->registerNamespace('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$namespaces = $loader->getNamespaces();
|
||||||
|
$this->assertArrayHasKey('Foo', $namespaces);
|
||||||
|
$this->assertArrayNotHasKey('Foo1', $namespaces);
|
||||||
|
$this->assertArrayHasKey('Bar', $namespaces);
|
||||||
|
$this->assertArrayHasKey('Bas', $namespaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPrefixes()
|
||||||
|
{
|
||||||
|
$loader = new UniversalClassLoader();
|
||||||
|
$loader->registerPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->registerPrefix('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$loader->registerPrefix('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||||
|
$prefixes = $loader->getPrefixes();
|
||||||
|
$this->assertArrayHasKey('Foo', $prefixes);
|
||||||
|
$this->assertArrayNotHasKey('Foo1', $prefixes);
|
||||||
|
$this->assertArrayHasKey('Bar', $prefixes);
|
||||||
|
$this->assertArrayHasKey('Bas', $prefixes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getLoadClassFromFallbackTests
|
* @dataProvider getLoadClassFromFallbackTests
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user