merged branch eventhorizonpl/100pc_symfony_component_class_loader (PR #5329)
Commits
-------
8c74b55
getNamespaces test
Discussion
----------
100pc symfony component class loader
Hi,
I added some tests for Symfony\Component\ClassLoader\UniversalClassLoader and Symfony\Component\ClassLoader\ClassLoader.
Best regards,
Michal
---------------------------------------------------------------------------
by eventhorizonpl at 2012-08-23T20:05:02Z
Fixed. Thanks for the review!
---------------------------------------------------------------------------
by pborreli at 2012-08-24T05:11:00Z
👍
---------------------------------------------------------------------------
by fabpot at 2012-08-24T05:46:36Z
Can you squash your commits before I merge the PR? Thanks.
This commit is contained in:
commit
b5517b2f1c
@ -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