bootstrap.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. use Cake\Utility\Security;
  22. if (is_file('vendor/autoload.php')) {
  23. require_once 'vendor/autoload.php';
  24. } else {
  25. require_once dirname(__DIR__) . '/vendor/autoload.php';
  26. }
  27. if (!defined('DS')) {
  28. define('DS', DIRECTORY_SEPARATOR);
  29. }
  30. define('ROOT', dirname(__DIR__));
  31. define('APP_DIR', 'TestApp');
  32. define('TMP', sys_get_temp_dir() . DS);
  33. define('LOGS', TMP . 'logs' . DS);
  34. define('CACHE', TMP . 'cache' . DS);
  35. define('SESSIONS', TMP . 'sessions' . DS);
  36. define('CAKE_CORE_INCLUDE_PATH', ROOT);
  37. define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
  38. define('CAKE', CORE_PATH . 'src' . DS);
  39. define('CORE_TESTS', CORE_PATH . 'tests' . DS);
  40. define('CORE_TEST_CASES', CORE_TESTS . 'TestCase');
  41. define('TEST_APP', CORE_TESTS . 'test_app' . DS);
  42. // Point app constants to the test app.
  43. define('APP', TEST_APP . 'TestApp' . DS);
  44. define('WWW_ROOT', TEST_APP . 'webroot' . DS);
  45. define('CONFIG', TEST_APP . 'config' . DS);
  46. //@codingStandardsIgnoreStart
  47. @mkdir(LOGS);
  48. @mkdir(SESSIONS);
  49. @mkdir(CACHE);
  50. @mkdir(CACHE . 'views');
  51. @mkdir(CACHE . 'models');
  52. //@codingStandardsIgnoreEnd
  53. require_once CORE_PATH . 'config/bootstrap.php';
  54. date_default_timezone_set('UTC');
  55. mb_internal_encoding('UTF-8');
  56. Configure::write('debug', true);
  57. Configure::write('App', [
  58. 'namespace' => 'App',
  59. 'encoding' => 'UTF-8',
  60. 'base' => false,
  61. 'baseUrl' => false,
  62. 'dir' => APP_DIR,
  63. 'webroot' => 'webroot',
  64. 'wwwRoot' => WWW_ROOT,
  65. 'fullBaseUrl' => 'http://localhost',
  66. 'imageBaseUrl' => 'img/',
  67. 'jsBaseUrl' => 'js/',
  68. 'cssBaseUrl' => 'css/',
  69. 'paths' => [
  70. 'plugins' => [TEST_APP . 'Plugin' . DS],
  71. 'templates' => [APP . 'Template' . DS],
  72. 'locales' => [APP . 'Locale' . DS],
  73. ],
  74. ]);
  75. Cache::setConfig([
  76. '_cake_core_' => [
  77. 'engine' => 'File',
  78. 'prefix' => 'cake_core_',
  79. 'serialize' => true,
  80. ],
  81. '_cake_model_' => [
  82. 'engine' => 'File',
  83. 'prefix' => 'cake_model_',
  84. 'serialize' => true,
  85. ],
  86. ]);
  87. // Ensure default test connection is defined
  88. if (!getenv('db_dsn')) {
  89. putenv('db_dsn=sqlite:///:memory:');
  90. }
  91. ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]);
  92. ConnectionManager::setConfig('test_custom_i18n_datasource', ['url' => getenv('db_dsn')]);
  93. Configure::write('Session', [
  94. 'defaults' => 'php',
  95. ]);
  96. Log::setConfig([
  97. // 'queries' => [
  98. // 'className' => 'Console',
  99. // 'stream' => 'php://stderr',
  100. // 'scopes' => ['queriesLog']
  101. // ],
  102. 'debug' => [
  103. 'engine' => 'Cake\Log\Engine\FileLog',
  104. 'levels' => ['notice', 'info', 'debug'],
  105. 'file' => 'debug',
  106. 'path' => LOGS,
  107. ],
  108. 'error' => [
  109. 'engine' => 'Cake\Log\Engine\FileLog',
  110. 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
  111. 'file' => 'error',
  112. 'path' => LOGS,
  113. ],
  114. ]);
  115. Chronos::setTestNow(Chronos::now());
  116. ini_set('intl.default_locale', 'en_US');
  117. ini_set('session.gc_divisor', '1');
  118. Security::setSalt('a-long-but-not-random-value');
  119. loadPHPUnitAliases();
  120. // Fixate sessionid early on, as php7.2+
  121. // does not allow the sessionid to be set after stdout
  122. // has been written to.
  123. session_id('cli');