bootstrap.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. define('CONFIG', TEST_APP . 'config' . DS);
  39. //@codingStandardsIgnoreStart
  40. @mkdir(LOGS);
  41. @mkdir(SESSIONS);
  42. @mkdir(CACHE);
  43. @mkdir(CACHE . 'views');
  44. @mkdir(CACHE . 'models');
  45. //@codingStandardsIgnoreEnd
  46. require CAKE . 'Core/ClassLoader.php';
  47. $loader = new Cake\Core\ClassLoader;
  48. $loader->register();
  49. $loader->addNamespace('TestApp', APP);
  50. $loader->addNamespace('TestPlugin', TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS . 'src');
  51. $loader->addNamespace('TestPlugin\Test', TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS . 'tests');
  52. $loader->addNamespace('TestPluginTwo', TEST_APP . 'Plugin' . DS . 'TestPluginTwo' . DS . 'src');
  53. $loader->addNamespace('PluginJs', TEST_APP . 'Plugin' . DS . 'PluginJs' . DS . 'src');
  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_DIR,
  65. 'www_root' => 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' => [APP . 'Template' . DS]
  73. ]
  74. ]);
  75. Cache::config([
  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_class')) {
  89. putenv('db_class=Cake\Database\Driver\Sqlite');
  90. putenv('db_dsn=sqlite::memory:');
  91. }
  92. ConnectionManager::config('test', [
  93. 'className' => 'Cake\Database\Connection',
  94. 'driver' => getenv('db_class'),
  95. 'dsn' => getenv('db_dsn'),
  96. 'database' => getenv('db_database'),
  97. 'login' => getenv('db_login'),
  98. 'password' => getenv('db_password'),
  99. 'timezone' => 'UTC'
  100. ]);
  101. Configure::write('Session', [
  102. 'defaults' => 'php'
  103. ]);
  104. Log::config([
  105. 'debug' => [
  106. 'engine' => 'Cake\Log\Engine\FileLog',
  107. 'levels' => ['notice', 'info', 'debug'],
  108. 'file' => 'debug',
  109. ],
  110. 'error' => [
  111. 'engine' => 'Cake\Log\Engine\FileLog',
  112. 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
  113. 'file' => 'error',
  114. ]
  115. ]);
  116. Carbon\Carbon::setTestNow(Carbon\Carbon::now());