bootstrap.php 3.9 KB

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