bootstrap.php 3.7 KB

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