bootstrap.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\Error\Debug\TextFormatter;
  19. use Cake\Log\Log;
  20. use Cake\Utility\Security;
  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. // phpcs:disable
  46. @mkdir(LOGS);
  47. @mkdir(SESSIONS);
  48. @mkdir(CACHE);
  49. @mkdir(CACHE . 'views');
  50. @mkdir(CACHE . 'models');
  51. // phpcs:enable
  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' => [TEST_APP . 'templates' . DS],
  71. 'locales' => [TEST_APP . 'resources' . DS . 'locales' . 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_URL')) {
  88. putenv('DB_URL=sqlite:///:memory:');
  89. }
  90. ConnectionManager::setConfig('test', ['url' => getenv('DB_URL')]);
  91. ConnectionManager::setConfig('test_custom_i18n_datasource', ['url' => getenv('DB_URL')]);
  92. Configure::write('Session', [
  93. 'defaults' => 'php',
  94. ]);
  95. Configure::write('Debugger.exportFormatter', TextFormatter::class);
  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. Security::setSalt('a-long-but-not-random-value');
  117. ini_set('intl.default_locale', 'en_US');
  118. ini_set('session.gc_divisor', '1');
  119. // Fixate sessionid early on, as php7.2+
  120. // does not allow the sessionid to be set after stdout
  121. // has been written to.
  122. session_id('cli');