bootstrap.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  12. */
  13. use Cake\Cache\Cache;
  14. use Cake\Core\Configure;
  15. use Cake\Datasource\ConnectionManager;
  16. use Cake\I18n\I18n;
  17. use Cake\Log\Log;
  18. require_once 'vendor/autoload.php';
  19. define('DS', DIRECTORY_SEPARATOR);
  20. define('ROOT', dirname(__DIR__));
  21. define('APP_DIR', 'TestApp');
  22. define('WEBROOT_DIR', 'webroot');
  23. define('TMP', sys_get_temp_dir() . DS);
  24. define('LOGS', TMP . 'logs' . DS);
  25. define('CACHE', TMP . 'cache' . DS);
  26. define('SESSIONS', TMP . 'sessions' . DS);
  27. define('CAKE_CORE_INCLUDE_PATH', ROOT);
  28. define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
  29. define('CAKE', CORE_PATH . 'src' . DS);
  30. define('CORE_TESTS', CORE_PATH . 'tests' . DS);
  31. define('CORE_TEST_CASES', CORE_TESTS . 'TestCase');
  32. define('TEST_APP', CORE_TESTS . 'test_app' . DS);
  33. define('LOG_ERROR', LOG_ERR);
  34. // Point app constants to the test app.
  35. define('APP', TEST_APP . 'TestApp' . DS);
  36. define('WWW_ROOT', TEST_APP . WEBROOT_DIR . DS);
  37. define('TESTS', TEST_APP . 'tests' . DS);
  38. //@codingStandardsIgnoreStart
  39. @mkdir(LOGS);
  40. @mkdir(SESSIONS);
  41. @mkdir(CACHE);
  42. @mkdir(CACHE . 'views');
  43. @mkdir(CACHE . 'models');
  44. //@codingStandardsIgnoreEnd
  45. require CAKE . 'Core/ClassLoader.php';
  46. $loader = new Cake\Core\ClassLoader;
  47. $loader->register();
  48. $loader->addNamespace('TestApp', APP);
  49. $loader->addNamespace('TestPlugin', TEST_APP . 'Plugin/TestPlugin');
  50. $loader->addNamespace('TestPluginTwo', TEST_APP . 'Plugin/TestPluginTwo');
  51. $loader->addNamespace('PluginJs', TEST_APP . 'Plugin/PluginJs');
  52. require_once CAKE . '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_DIR,
  63. 'www_root' => 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' => [APP . 'Template' . DS]
  71. ]
  72. ]);
  73. Cache::config([
  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_class')) {
  87. putenv('db_class=Cake\Database\Driver\Sqlite');
  88. putenv('db_dsn=sqlite::memory:');
  89. }
  90. ConnectionManager::config('test', [
  91. 'className' => 'Cake\Database\Connection',
  92. 'driver' => getenv('db_class'),
  93. 'dsn' => getenv('db_dsn'),
  94. 'database' => getenv('db_database'),
  95. 'login' => getenv('db_login'),
  96. 'password' => getenv('db_password'),
  97. 'timezone' => 'UTC'
  98. ]);
  99. Configure::write('Session', [
  100. 'defaults' => 'php'
  101. ]);
  102. Log::config([
  103. 'debug' => [
  104. 'engine' => 'Cake\Log\Engine\FileLog',
  105. 'levels' => ['notice', 'info', 'debug'],
  106. 'file' => 'debug',
  107. ],
  108. 'error' => [
  109. 'engine' => 'Cake\Log\Engine\FileLog',
  110. 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
  111. 'file' => 'error',
  112. ]
  113. ]);
  114. // Initialize the empty language.
  115. I18n::translate('empty');
  116. Carbon\Carbon::setTestNow(Carbon\Carbon::now());