123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
-
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
- namespace Symfony\Tests\Component\ClassLoader;
-
- use Symfony\Component\ClassLoader\UniversalClassLoader;
-
- class UniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
- {
- /**
- * @dataProvider getLoadClassTests
- */
- public function testLoadClass($className, $testClassName, $message)
- {
- $loader = new UniversalClassLoader();
- $loader->registerNamespace('Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
- $loader->registerPrefix('Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
- $loader->loadClass($testClassName);
- $this->assertTrue(class_exists($className), $message);
- }
-
- public function getLoadClassTests()
- {
- return array(
- array('\\Namespaced\\Foo', 'Namespaced\\Foo', '->loadClass() loads Namespaced\Foo class'),
- array('\\Pearlike_Foo', 'Pearlike_Foo', '->loadClass() loads Pearlike_Foo class'),
- array('\\Namespaced\\Bar', '\\Namespaced\\Bar', '->loadClass() loads Namespaced\Bar class with a leading slash'),
- array('\\Pearlike_Bar', '\\Pearlike_Bar', '->loadClass() loads Pearlike_Bar class with a leading slash'),
- );
- }
-
- /**
- * @dataProvider getLoadClassFromFallbackTests
- */
- public function testLoadClassFromFallback($className, $testClassName, $message)
- {
- $loader = new UniversalClassLoader();
- $loader->registerNamespace('Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
- $loader->registerPrefix('Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
- $loader->registerNamespaceFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'));
- $loader->registerPrefixFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'));
- $loader->loadClass($testClassName);
- $this->assertTrue(class_exists($className), $message);
- }
-
- public function getLoadClassFromFallbackTests()
- {
- return array(
- array('\\Namespaced\\Baz', 'Namespaced\\Baz', '->loadClass() loads Namespaced\Baz class'),
- array('\\Pearlike_Baz', 'Pearlike_Baz', '->loadClass() loads Pearlike_Baz class'),
- array('\\Namespaced\\FooBar', 'Namespaced\\FooBar', '->loadClass() loads Namespaced\Baz class from fallback dir'),
- array('\\Pearlike_FooBar', 'Pearlike_FooBar', '->loadClass() loads Pearlike_Baz class from fallback dir'),
- );
- }
-
- /**
- * @dataProvider getLoadClassNamespaceCollisionTests
- */
- public function testLoadClassNamespaceCollision($namespaces, $className, $message)
- {
- $loader = new UniversalClassLoader();
- $loader->registerNamespaces($namespaces);
-
- $loader->loadClass($className);
- $this->assertTrue(class_exists($className), $message);
- }
-
- public function getLoadClassNamespaceCollisionTests()
- {
- return array(
- array(
- array(
- 'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
- 'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
- ),
- 'NamespaceCollision\A\Foo',
- '->loadClass() loads NamespaceCollision\A\Foo from alpha.',
- ),
- array(
- array(
- 'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
- 'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
- ),
- 'NamespaceCollision\A\Bar',
- '->loadClass() loads NamespaceCollision\A\Bar from alpha.',
- ),
- array(
- array(
- 'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
- 'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
- ),
- 'NamespaceCollision\A\B\Foo',
- '->loadClass() loads NamespaceCollision\A\B\Foo from beta.',
- ),
- array(
- array(
- 'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
- 'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
- ),
- 'NamespaceCollision\A\B\Bar',
- '->loadClass() loads NamespaceCollision\A\B\Bar from beta.',
- ),
- );
- }
-
- /**
- * @dataProvider getLoadClassPrefixCollisionTests
- */
- public function testLoadClassPrefixCollision($prefixes, $className, $message)
- {
- $loader = new UniversalClassLoader();
- $loader->registerPrefixes($prefixes);
-
- $loader->loadClass($className);
- $this->assertTrue(class_exists($className), $message);
- }
-
- public function getLoadClassPrefixCollisionTests()
- {
- return array(
- array(
- array(
- 'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
- 'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
- ),
- 'PrefixCollision_A_Foo',
- '->loadClass() loads PrefixCollision_A_Foo from alpha.',
- ),
- array(
- array(
- 'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
- 'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
- ),
- 'PrefixCollision_A_Bar',
- '->loadClass() loads PrefixCollision_A_Bar from alpha.',
- ),
- array(
- array(
- 'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
- 'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
- ),
- 'PrefixCollision_A_B_Foo',
- '->loadClass() loads PrefixCollision_A_B_Foo from beta.',
- ),
- array(
- array(
- 'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
- 'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
- ),
- 'PrefixCollision_A_B_Bar',
- '->loadClass() loads PrefixCollision_A_B_Bar from beta.',
- ),
- );
- }
- }
|