autoloader.test.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. class AutoloaderTest extends PHPUnit_Framework_TestCase {
  3. /**
  4. * Test the Autoloader::map method.
  5. *
  6. * @group laravel
  7. */
  8. public function testMapsCanBeRegistered()
  9. {
  10. Autoloader::map(array(
  11. 'Foo' => path('app').'models/foo.php',
  12. ));
  13. $this->assertEquals(path('app').'models/foo.php', Autoloader::$mappings['Foo']);
  14. }
  15. /**
  16. * Test the Autoloader::alias method.
  17. *
  18. * @group laravel
  19. */
  20. public function testAliasesCanBeRegistered()
  21. {
  22. Autoloader::alias('Foo\\Bar', 'Foo');
  23. $this->assertEquals('Foo\\Bar', Autoloader::$aliases['Foo']);
  24. }
  25. /**
  26. * Test the Autoloader::directories method.
  27. *
  28. * @group laravel
  29. */
  30. public function testPsrDirectoriesCanBeRegistered()
  31. {
  32. Autoloader::directories(array(
  33. path('app').'foo'.DS.'bar',
  34. path('app').'foo'.DS.'baz'.DS.DS,
  35. ));
  36. $this->assertTrue(in_array(path('app').'foo'.DS.'bar'.DS, Autoloader::$directories));
  37. $this->assertTrue(in_array(path('app').'foo'.DS.'baz'.DS, Autoloader::$directories));
  38. }
  39. /**
  40. * Test the Autoloader::namespaces method.
  41. *
  42. * @group laravel
  43. */
  44. public function testNamespacesCanBeRegistered()
  45. {
  46. Autoloader::namespaces(array(
  47. 'Autoloader_1' => path('bundle').'autoload'.DS.'models',
  48. 'Autoloader_2' => path('bundle').'autoload'.DS.'libraries'.DS.DS,
  49. ));
  50. $this->assertEquals(path('bundle').'autoload'.DS.'models'.DS, Autoloader::$namespaces['Autoloader_1\\']);
  51. $this->assertEquals(path('bundle').'autoload'.DS.'libraries'.DS, Autoloader::$namespaces['Autoloader_2\\']);
  52. }
  53. /**
  54. * Test the loading of PSR-0 models and libraries.
  55. *
  56. * @group laravel
  57. */
  58. public function testPsrLibrariesAndModelsCanBeLoaded()
  59. {
  60. $this->assertInstanceOf('User', new User);
  61. $this->assertInstanceOf('Repositories\\User', new Repositories\User);
  62. }
  63. /**
  64. * Test the loading of hard-coded classes.
  65. *
  66. * @group laravel
  67. */
  68. public function testHardcodedClassesCanBeLoaded()
  69. {
  70. Autoloader::map(array(
  71. 'Autoloader_HardCoded' => path('app').'models'.DS.'autoloader.php',
  72. ));
  73. $this->assertInstanceOf('Autoloader_HardCoded', new Autoloader_HardCoded);
  74. }
  75. /**
  76. * Test the loading of classes mapped by namespaces.
  77. *
  78. * @group laravel
  79. */
  80. public function testClassesMappedByNamespaceCanBeLoaded()
  81. {
  82. Autoloader::namespaces(array(
  83. 'Dashboard' => path('bundle').'dashboard'.DS.'models',
  84. ));
  85. $this->assertInstanceOf('Dashboard\\Repository', new Dashboard\Repository);
  86. }
  87. }