BootstrapTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_Application
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Application_Module_BootstrapTest::main');
  24. }
  25. /**
  26. * Test helper
  27. */
  28. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  29. /**
  30. * Zend_Loader_Autoloader
  31. */
  32. require_once 'Zend/Loader/Autoloader.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Application
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Application_Module_BootstrapTest extends PHPUnit_Framework_TestCase
  41. {
  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. Zend_Loader_Autoloader::resetInstance();
  57. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  58. $this->application = new Zend_Application('testing');
  59. }
  60. public function tearDown()
  61. {
  62. // Restore original autoloaders
  63. $loaders = spl_autoload_functions();
  64. foreach ($loaders as $loader) {
  65. spl_autoload_unregister($loader);
  66. }
  67. foreach ($this->loaders as $loader) {
  68. spl_autoload_register($loader);
  69. }
  70. }
  71. public function testConstructorShouldInitializeModuleResourceLoaderWithModulePrefix()
  72. {
  73. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  74. $bootstrap = new ZfModule_Bootstrap($this->application);
  75. $module = $bootstrap->getModuleName();
  76. $loader = $bootstrap->getResourceLoader();
  77. $this->assertEquals($module, $loader->getNamespace());
  78. }
  79. public function testConstructorShouldAcceptResourceLoaderInOptions()
  80. {
  81. $loader = new Zend_Loader_Autoloader_Resource(array(
  82. 'namespace' => 'Foo',
  83. 'basePath' => dirname(__FILE__),
  84. ));
  85. $this->application->setOptions(array('resourceLoader' => $loader));
  86. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  87. $bootstrap = new ZfModule_Bootstrap($this->application);
  88. $this->assertSame($loader, $bootstrap->getResourceLoader(), var_export($bootstrap->getOptions(), 1));
  89. }
  90. public function testModuleNameShouldBeFirstSegmentOfClassName()
  91. {
  92. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  93. $bootstrap = new ZfModule_Bootstrap($this->application);
  94. $this->assertEquals('ZfModule', $bootstrap->getModuleName());
  95. }
  96. public function testShouldPullModuleNamespacedOptionsWhenPresent()
  97. {
  98. $options = array(
  99. 'foo' => 'bar',
  100. 'ZfModule' => array(
  101. 'foo' => 'baz',
  102. )
  103. );
  104. $this->application->setOptions($options);
  105. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  106. $bootstrap = new ZfModule_Bootstrap($this->application);
  107. $this->assertEquals('baz', $bootstrap->foo);
  108. }
  109. }
  110. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Module_BootstrapTest::main') {
  111. Zend_Application_Module_BootstrapTest::main();
  112. }