AutoloaderFactoryClassMapLoaderTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Loader
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. if (!defined('PHPUnit_MAIN_METHOD')) {
  22. define('PHPUnit_MAIN_METHOD', 'Zend_Loader_AutoloaderFactoryClassMapLoaderTest::main');
  23. }
  24. require_once 'Zend/Loader/AutoloaderFactory.php';
  25. /**
  26. * @package Zend_Loader
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Loader
  31. */
  32. class Zend_Loader_AutoloaderFactoryClassMapLoaderTest extends PHPUnit_Framework_TestCase
  33. {
  34. /**
  35. * @var array
  36. */
  37. protected $_loaders;
  38. /**
  39. * @var string
  40. */
  41. protected $_includePath;
  42. public static function main()
  43. {
  44. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  45. $result = PHPUnit_TextUI_TestRunner::run($suite);
  46. }
  47. public function setUp()
  48. {
  49. // Store original autoloaders
  50. $this->_loaders = spl_autoload_functions();
  51. if (!is_array($this->_loaders)) {
  52. // spl_autoload_functions does not return empty array when no
  53. // autoloaders registered...
  54. $this->_loaders = array();
  55. }
  56. // Clear out other autoloaders to ensure those being tested are at the
  57. // top of the stack
  58. foreach ($this->_loaders as $loader) {
  59. spl_autoload_unregister($loader);
  60. }
  61. // Store original include_path
  62. $this->_includePath = get_include_path();
  63. }
  64. public function tearDown()
  65. {
  66. Zend_Loader_AutoloaderFactory::unregisterAutoloaders();
  67. // Restore original autoloaders
  68. $loaders = spl_autoload_functions();
  69. if (is_array($loaders)) {
  70. foreach ($loaders as $loader) {
  71. spl_autoload_unregister($loader);
  72. }
  73. }
  74. foreach ($this->_loaders as $loader) {
  75. spl_autoload_register($loader);
  76. }
  77. // Restore original include_path
  78. set_include_path($this->_includePath);
  79. }
  80. public function testAutoincluding()
  81. {
  82. Zend_Loader_AutoloaderFactory::factory(
  83. array(
  84. 'Zend_Loader_ClassMapAutoloader' => array(
  85. dirname(__FILE__) . '/_files/goodmap.php',
  86. ),
  87. )
  88. );
  89. $loader = Zend_Loader_AutoloaderFactory::getRegisteredAutoloader(
  90. 'Zend_Loader_ClassMapAutoloader'
  91. );
  92. $map = $loader->getAutoloadMap();
  93. $this->assertTrue(is_array($map));
  94. $this->assertEquals(2, count($map));
  95. }
  96. }
  97. if (PHPUnit_MAIN_METHOD == 'Zend_Loader_AutoloaderFactoryClassMapLoaderTest::main') {
  98. Zend_Loader_AutoloaderFactoryClassMapLoaderTest::main();
  99. }