bootstrap.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @link https://cakephp.org CakePHP(tm) Project
  11. * @license https://opensource.org/licenses/mit-license.php MIT License
  12. */
  13. use Cake\Cache\Cache;
  14. use Cake\Chronos\Chronos;
  15. use Cake\Chronos\Date;
  16. use Cake\Chronos\MutableDate;
  17. use Cake\Chronos\MutableDateTime;
  18. use Cake\Core\Configure;
  19. use Cake\Datasource\ConnectionManager;
  20. use Cake\Log\Log;
  21. if (is_file('vendor/autoload.php')) {
  22. require_once 'vendor/autoload.php';
  23. } else {
  24. require_once dirname(__DIR__) . '/vendor/autoload.php';
  25. }
  26. if (!defined('DS')) {
  27. define('DS', DIRECTORY_SEPARATOR);
  28. }
  29. define('ROOT', dirname(__DIR__));
  30. define('APP_DIR', 'TestApp');
  31. define('TMP', sys_get_temp_dir() . DS);
  32. define('LOGS', TMP . 'logs' . DS);
  33. define('CACHE', TMP . 'cache' . DS);
  34. define('SESSIONS', TMP . 'sessions' . DS);
  35. define('CAKE_CORE_INCLUDE_PATH', ROOT);
  36. define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
  37. define('CAKE', CORE_PATH . 'src' . DS);
  38. define('CORE_TESTS', CORE_PATH . 'tests' . DS);
  39. define('CORE_TEST_CASES', CORE_TESTS . 'TestCase');
  40. define('TEST_APP', CORE_TESTS . 'test_app' . DS);
  41. // Point app constants to the test app.
  42. define('APP', TEST_APP . 'TestApp' . DS);
  43. define('WWW_ROOT', TEST_APP . 'webroot' . DS);
  44. define('CONFIG', TEST_APP . 'config' . DS);
  45. //@codingStandardsIgnoreStart
  46. @mkdir(LOGS);
  47. @mkdir(SESSIONS);
  48. @mkdir(CACHE);
  49. @mkdir(CACHE . 'views');
  50. @mkdir(CACHE . 'models');
  51. //@codingStandardsIgnoreEnd
  52. require_once CORE_PATH . 'config/bootstrap.php';
  53. date_default_timezone_set('UTC');
  54. mb_internal_encoding('UTF-8');
  55. Configure::write('debug', true);
  56. Configure::write('App', [
  57. 'namespace' => 'App',
  58. 'encoding' => 'UTF-8',
  59. 'base' => false,
  60. 'baseUrl' => false,
  61. 'dir' => APP_DIR,
  62. 'webroot' => 'webroot',
  63. 'wwwRoot' => WWW_ROOT,
  64. 'fullBaseUrl' => 'http://localhost',
  65. 'imageBaseUrl' => 'img/',
  66. 'jsBaseUrl' => 'js/',
  67. 'cssBaseUrl' => 'css/',
  68. 'paths' => [
  69. 'plugins' => [TEST_APP . 'Plugin' . DS],
  70. 'templates' => [APP . 'Template' . DS],
  71. 'locales' => [APP . 'Locale' . DS],
  72. ]
  73. ]);
  74. Cache::setConfig([
  75. '_cake_core_' => [
  76. 'engine' => 'File',
  77. 'prefix' => 'cake_core_',
  78. 'serialize' => true
  79. ],
  80. '_cake_model_' => [
  81. 'engine' => 'File',
  82. 'prefix' => 'cake_model_',
  83. 'serialize' => true
  84. ]
  85. ]);
  86. // Ensure default test connection is defined
  87. if (!getenv('db_dsn')) {
  88. putenv('db_dsn=sqlite:///:memory:');
  89. }
  90. ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]);
  91. ConnectionManager::setConfig('test_custom_i18n_datasource', ['url' => getenv('db_dsn')]);
  92. Configure::write('Session', [
  93. 'defaults' => 'php'
  94. ]);
  95. Log::setConfig([
  96. // 'queries' => [
  97. // 'className' => 'Console',
  98. // 'stream' => 'php://stderr',
  99. // 'scopes' => ['queriesLog']
  100. // ],
  101. 'debug' => [
  102. 'engine' => 'Cake\Log\Engine\FileLog',
  103. 'levels' => ['notice', 'info', 'debug'],
  104. 'file' => 'debug',
  105. ],
  106. 'error' => [
  107. 'engine' => 'Cake\Log\Engine\FileLog',
  108. 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
  109. 'file' => 'error',
  110. ]
  111. ]);
  112. Chronos::setTestNow(Chronos::now());
  113. MutableDateTime::setTestNow(MutableDateTime::now());
  114. Date::setTestNow(Date::now());
  115. MutableDate::setTestNow(MutableDate::now());
  116. ini_set('intl.default_locale', 'en_US');
  117. ini_set('session.gc_divisor', '1');
  118. if (class_exists('PHPUnit_Runner_Version')) {
  119. class_alias('PHPUnit_Framework_TestResult', 'PHPUnit\Framework\TestResult');
  120. class_alias('PHPUnit_Framework_Error', 'PHPUnit\Framework\Error\Error');
  121. class_alias('PHPUnit_Framework_Error_Warning', 'PHPUnit\Framework\Error\Warning');
  122. class_alias('PHPUnit_Framework_ExpectationFailedException', 'PHPUnit\Framework\ExpectationFailedException');
  123. }
  124. // Fixate sessionid early on, as php7.2+
  125. // does not allow the sessionid to be set after stdout
  126. // has been written to.
  127. session_id('cli');
  128. // Fix multiple http/server requests in a single test method.
  129. $_SERVER['PHP_SELF'] = '/';