ClassLoaderTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Autoload;
  12. use Composer\Autoload\ClassLoader;
  13. /**
  14. * Tests the Composer\Autoload\ClassLoader class.
  15. */
  16. class ClassLoaderTest extends \PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * Tests regular PSR-0 and PSR-4 class loading.
  20. *
  21. * @dataProvider getLoadClassTests
  22. *
  23. * @param string $class The fully-qualified class name to test, without preceding namespace separator.
  24. */
  25. public function testLoadClass($class)
  26. {
  27. $loader = new ClassLoader();
  28. $loader->add('Namespaced\\', __DIR__ . '/Fixtures');
  29. $loader->add('Pearlike_', __DIR__ . '/Fixtures');
  30. $loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures');
  31. $loader->loadClass($class);
  32. $this->assertTrue(class_exists($class, false), "->loadClass() loads '$class'");
  33. }
  34. /**
  35. * Provides arguments for ->testLoadClass().
  36. *
  37. * @return array Array of parameter sets to test with.
  38. */
  39. public function getLoadClassTests()
  40. {
  41. return array(
  42. array('Namespaced\\Foo'),
  43. array('Pearlike_Foo'),
  44. array('ShinyVendor\\ShinyPackage\\SubNamespace\\Foo'),
  45. );
  46. }
  47. /**
  48. * getPrefixes method should return empty array if ClassLoader does not have any psr-0 configuration
  49. */
  50. public function testGetPrefixesWithNoPSR0Configuration()
  51. {
  52. $loader = new ClassLoader();
  53. $this->assertEmpty($loader->getPrefixes());
  54. }
  55. }