Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

getNamespaces test

getPrefixes test

loadClass test

getPrefixes test

addPrefix test

getFallbackDirs test

fix things pointed out by stof
  • Loading branch information...
commit 4389ce714e3c964055014c1f26b0a26c1c6e5a05 1 parent f475330
Michał Piotrowski eventhorizonpl authored
Showing with 77 additions and 0 deletions.
  1. +51 −0 Tests/ClassLoaderTest.php
  2. +26 −0 Tests/UniversalClassLoaderTest.php
51 Tests/ClassLoaderTest.php
View
@@ -15,6 +15,28 @@
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
*/
@@ -37,6 +59,35 @@ public function getLoadClassTests()
);
}
+ /**
+ * @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()
{
$loader = new ClassLoader();
26 Tests/UniversalClassLoaderTest.php
View
@@ -56,6 +56,32 @@ public function testUseIncludePath()
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
*/
Please sign in to comment.
Something went wrong with that request. Please try again.