ClassLoaderTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. use Composer\Test\TestCase;
  14. /**
  15. * Tests the Composer\Autoload\ClassLoader class.
  16. */
  17. class ClassLoaderTest extends TestCase
  18. {
  19. /**
  20. * Tests regular PSR-0 and PSR-4 class loading.
  21. *
  22. * @dataProvider getLoadClassTests
  23. *
  24. * @param string $class The fully-qualified class name to test, without preceding namespace separator.
  25. */
  26. public function testLoadClass($class)
  27. {
  28. $loader = new ClassLoader();
  29. $loader->add('Namespaced\\', __DIR__ . '/Fixtures');
  30. $loader->add('Pearlike_', __DIR__ . '/Fixtures');
  31. $loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures');
  32. $loader->loadClass($class);
  33. $this->assertTrue(class_exists($class, false), "->loadClass() loads '$class'");
  34. }
  35. /**
  36. * Provides arguments for ->testLoadClass().
  37. *
  38. * @return array Array of parameter sets to test with.
  39. */
  40. public function getLoadClassTests()
  41. {
  42. return array(
  43. array('Namespaced\\Foo'),
  44. array('Pearlike_Foo'),
  45. array('ShinyVendor\\ShinyPackage\\SubNamespace\\Foo'),
  46. );
  47. }
  48. /**
  49. * getPrefixes method should return empty array if ClassLoader does not have any psr-0 configuration
  50. */
  51. public function testGetPrefixesWithNoPSR0Configuration()
  52. {
  53. $loader = new ClassLoader();
  54. $this->assertEmpty($loader->getPrefixes());
  55. }
  56. }