2
0

BootstrapTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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-2010 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_Bootstrap_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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. * @group Zend_Application
  40. */
  41. class Zend_Application_Bootstrap_BootstrapTest extends PHPUnit_Framework_TestCase
  42. {
  43. public static function main()
  44. {
  45. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. public function setUp()
  49. {
  50. // Store original autoloaders
  51. $this->loaders = spl_autoload_functions();
  52. if (!is_array($this->loaders)) {
  53. // spl_autoload_functions does not return empty array when no
  54. // autoloaders registered...
  55. $this->loaders = array();
  56. }
  57. Zend_Loader_Autoloader::resetInstance();
  58. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  59. $this->application = new Zend_Application('testing');
  60. $this->bootstrap = new Zend_Application_Bootstrap_Bootstrap(
  61. $this->application
  62. );
  63. $this->resetFrontController();
  64. }
  65. public function tearDown()
  66. {
  67. // Restore original autoloaders
  68. $loaders = spl_autoload_functions();
  69. foreach ($loaders as $loader) {
  70. spl_autoload_unregister($loader);
  71. }
  72. foreach ($this->loaders as $loader) {
  73. spl_autoload_register($loader);
  74. }
  75. // Reset autoloader instance so it doesn't affect other tests
  76. Zend_Loader_Autoloader::resetInstance();
  77. }
  78. public function resetFrontController()
  79. {
  80. $front = Zend_Controller_Front::getInstance();
  81. $front->resetInstance();
  82. $front->setRequest(new Zend_Controller_Request_HttpTestCase)
  83. ->setResponse(new Zend_Controller_Response_HttpTestCase);
  84. }
  85. public function testFrontControllerResourcePluginShouldBeRegisteredByDefault()
  86. {
  87. $this->assertTrue($this->bootstrap->hasPluginResource('FrontController'));
  88. }
  89. /**
  90. * @expectedException Zend_Application_Bootstrap_Exception
  91. */
  92. public function testRunShouldRaiseExceptionIfNoControllerDirectoryRegisteredWithFrontController()
  93. {
  94. $this->bootstrap->bootstrap();
  95. $this->bootstrap->run();
  96. }
  97. public function testRunShouldDispatchFrontController()
  98. {
  99. $this->bootstrap->setOptions(array(
  100. 'resources' => array(
  101. 'frontcontroller' => array(
  102. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  103. ),
  104. ),
  105. ));
  106. $this->bootstrap->bootstrap();
  107. $front = $this->bootstrap->getResource('FrontController');
  108. $request = $front->getRequest();
  109. $request->setRequestUri('/zfappbootstrap');
  110. $this->bootstrap->run();
  111. $this->assertTrue($this->bootstrap->getContainer()->zfappbootstrap);
  112. }
  113. /**
  114. * @group ZF-8496
  115. */
  116. public function testBootstrapModuleAutoloaderShouldNotBeInitializedByDefault()
  117. {
  118. $this->assertFalse($this->bootstrap->getResourceLoader() instanceof Zend_Application_Module_Autoloader);
  119. }
  120. /**
  121. * @group ZF-8496
  122. */
  123. public function testBootstrapShouldInitializeModuleAutoloaderWhenNamespaceSpecified()
  124. {
  125. $application = new Zend_Application('testing', array(
  126. 'appnamespace' => 'Application',
  127. ));
  128. $bootstrap = new Zend_Application_Bootstrap_Bootstrap(
  129. $application
  130. );
  131. $this->assertTrue($bootstrap->getResourceLoader() instanceof Zend_Application_Module_Autoloader);
  132. $al = $bootstrap->getResourceLoader();
  133. $this->assertEquals('Application', $al->getNamespace());
  134. }
  135. /**
  136. * @group ZF-8496
  137. */
  138. public function testBootstrapAutoloaderNamespaceShouldBeConfigurable()
  139. {
  140. $application = new Zend_Application('testing', array(
  141. 'appnamespace' => 'Default',
  142. ));
  143. $bootstrap = new Zend_Application_Bootstrap_Bootstrap(
  144. $application
  145. );
  146. $al = $bootstrap->getResourceLoader();
  147. $this->assertEquals('Default', $al->getNamespace());
  148. }
  149. }
  150. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Bootstrap_BootstrapTest::main') {
  151. Zend_Application_Bootstrap_BootstrapTest::main();
  152. }