bootstrap.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. use Cake\Datasource\ConnectionManager;
  3. use Cake\Routing\Route\DashedRoute;
  4. use Cake\Routing\Router;
  5. if (!defined('DS')) {
  6. define('DS', DIRECTORY_SEPARATOR);
  7. }
  8. if (!defined('WINDOWS')) {
  9. if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
  10. define('WINDOWS', true);
  11. } else {
  12. define('WINDOWS', false);
  13. }
  14. }
  15. define('ROOT', dirname(__DIR__));
  16. define('TMP', ROOT . DS . 'tmp' . DS);
  17. define('LOGS', TMP . 'logs' . DS);
  18. define('CACHE', TMP . 'cache' . DS);
  19. define('APP', sys_get_temp_dir());
  20. define('APP_DIR', 'src');
  21. define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
  22. define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
  23. define('CAKE', CORE_PATH . APP_DIR . DS);
  24. define('TESTS', ROOT . DS . 'tests' . DS);
  25. define('WWW_ROOT', ROOT . DS . 'webroot' . DS);
  26. define('CONFIG', __DIR__ . DS . 'config' . DS);
  27. define('TEST_FILES', ROOT . DS . 'tests' . DS . 'test_files' . DS);
  28. ini_set('intl.default_locale', 'de_DE');
  29. require_once 'vendor/cakephp/cakephp/src/basics.php';
  30. require_once 'vendor/autoload.php';
  31. Cake\Core\Configure::write('App', [
  32. 'namespace' => 'TestApp',
  33. 'encoding' => 'UTF-8',
  34. 'fullBaseUrl' => '//localhost',
  35. 'paths' => [
  36. 'templates' => [
  37. TESTS . 'templates' . DS,
  38. ],
  39. ],
  40. ]);
  41. Cake\Core\Configure::write('debug', true);
  42. Cake\Core\Configure::write('Config', [
  43. 'adminEmail' => 'test@example.com',
  44. 'adminName' => 'Mark',
  45. ]);
  46. Cake\Mailer\Mailer::setConfig('default', ['transport' => 'Debug']);
  47. Cake\Mailer\TransportFactory::setConfig('Debug', [
  48. 'className' => 'Debug',
  49. ]);
  50. mb_internal_encoding('UTF-8');
  51. $Tmp = new Cake\Filesystem\Folder(TMP);
  52. $Tmp->create(TMP . 'cache/models', 0770);
  53. $Tmp->create(TMP . 'cache/persistent', 0770);
  54. $Tmp->create(TMP . 'cache/views', 0770);
  55. $cache = [
  56. 'default' => [
  57. 'engine' => 'File',
  58. 'path' => CACHE,
  59. ],
  60. '_cake_core_' => [
  61. 'className' => 'File',
  62. 'prefix' => 'crud_myapp_cake_core_',
  63. 'path' => CACHE . 'persistent/',
  64. 'serialize' => true,
  65. 'duration' => '+10 seconds',
  66. ],
  67. '_cake_model_' => [
  68. 'className' => 'File',
  69. 'prefix' => 'crud_my_app_cake_model_',
  70. 'path' => CACHE . 'models/',
  71. 'serialize' => 'File',
  72. 'duration' => '+10 seconds',
  73. ],
  74. ];
  75. Cake\Cache\Cache::setConfig($cache);
  76. Cake\Log\Log::setConfig('debug', [
  77. 'className' => 'Cake\Log\Engine\FileLog',
  78. 'path' => LOGS,
  79. 'file' => 'debug',
  80. 'scopes' => false,
  81. 'levels' => ['notice', 'info', 'debug'],
  82. 'url' => env('LOG_DEBUG_URL', null),
  83. ]);
  84. Cake\Log\Log::setConfig('error', [
  85. 'className' => 'Cake\Log\Engine\FileLog',
  86. 'path' => LOGS,
  87. 'file' => 'error',
  88. 'scopes' => false,
  89. 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
  90. 'url' => env('LOG_ERROR_URL', null),
  91. ]);
  92. Cake\Utility\Security::setSalt('foo');
  93. // Why is this required?
  94. require ROOT . DS . 'config' . DS . 'bootstrap.php';
  95. Router::defaultRouteClass(DashedRoute::class);
  96. class_alias(TestApp\Controller\AppController::class, 'App\Controller\AppController');
  97. Cake\Core\Plugin::getCollection()->add(new Tools\Plugin());
  98. if (getenv('db_dsn')) {
  99. ConnectionManager::setConfig('test', [
  100. 'url' => getenv('db_dsn'),
  101. 'timezone' => 'UTC',
  102. 'quoteIdentifiers' => true,
  103. 'cacheMetadata' => true,
  104. ]);
  105. return;
  106. }
  107. // Ensure default test connection is defined
  108. if (!getenv('db_class')) {
  109. putenv('db_dsn=sqlite:///:memory:');
  110. //putenv('db_dsn=postgres://postgres@127.0.0.1/test');
  111. }
  112. Cake\Datasource\ConnectionManager::setConfig('test', [
  113. 'url' => getenv('db_dsn') ?: null,
  114. 'driver' => getenv('db_class') ?: null,
  115. 'database' => getenv('db_database') ?: null,
  116. 'username' => getenv('db_username') ?: null,
  117. 'password' => getenv('db_password') ?: null,
  118. 'timezone' => 'UTC',
  119. 'quoteIdentifiers' => true,
  120. 'cacheMetadata' => true,
  121. ]);