bootstrap.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. 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. // phpcs:disable
  47. @mkdir(LOGS);
  48. @mkdir(SESSIONS);
  49. @mkdir(CACHE);
  50. @mkdir(CACHE . 'views');
  51. @mkdir(CACHE . 'models');
  52. // phpcs:enable
  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' => [TEST_APP . 'templates' . DS],
  72. 'locales' => [TEST_APP . 'resources' . DS . 'locales' . 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_URL')) {
  89. putenv('DB_URL=sqlite:///:memory:');
  90. }
  91. ConnectionManager::setConfig('test', ['url' => getenv('DB_URL')]);
  92. if (env('CAKE_TEST_AUTOQUOTE')) {
  93. ConnectionManager::get('test')->getDriver()->enableAutoQuoting(true);
  94. }
  95. Configure::write('Session', [
  96. 'defaults' => 'php',
  97. ]);
  98. Configure::write('Debugger.exportFormatter', TextFormatter::class);
  99. Log::setConfig([
  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');
  121. // Create test database schema
  122. if (env('FIXTURE_SCHEMA_METADATA')) {
  123. $loader = new SchemaLoader();
  124. $loader->loadInternalFile(env('FIXTURE_SCHEMA_METADATA'));
  125. }