bootstrap.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright 2005-2012, 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 MIT License (http://www.opensource.org/licenses/mit-license.php)
  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. define('DS', DIRECTORY_SEPARATOR);
  19. define('ROOT', dirname(__DIR__));
  20. define('APP_DIR', 'TestApp');
  21. define('WEBROOT_DIR', 'webroot');
  22. define('TMP', sys_get_temp_dir() . DS);
  23. define('LOGS', TMP . 'logs' . DS);
  24. define('CACHE', TMP . 'cache' . DS);
  25. define('SESSIONS', TMP . 'sessions' . DS);
  26. define('CAKE_CORE_INCLUDE_PATH', ROOT);
  27. define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
  28. define('CAKE', CORE_PATH . 'src' . DS);
  29. define('CORE_TESTS', CORE_PATH . 'tests' . DS);
  30. define('CORE_TEST_CASES', CORE_TESTS . 'TestCase');
  31. define('TEST_APP', CORE_TESTS . 'test_app' . DS);
  32. define('LOG_ERROR', LOG_ERR);
  33. // Point app constants to the test app.
  34. define('APP', TEST_APP . 'TestApp' . DS);
  35. define('WWW_ROOT', TEST_APP . WEBROOT_DIR . DS);
  36. define('TESTS', TEST_APP . 'tests' . DS);
  37. //@codingStandardsIgnoreStart
  38. @mkdir(LOGS);
  39. @mkdir(SESSIONS);
  40. @mkdir(CACHE);
  41. @mkdir(CACHE . 'views');
  42. @mkdir(CACHE . 'models');
  43. //@codingStandardsIgnoreEnd
  44. require CAKE . 'Core/ClassLoader.php';
  45. $loader = new Cake\Core\ClassLoader;
  46. $loader->register();
  47. $loader->addNamespace('Cake', CAKE);
  48. $loader->addNamespace('Cake\Test', CORE_TESTS);
  49. $loader->addNamespace('TestApp', APP);
  50. $loader->addNamespace('TestPlugin', TEST_APP . 'Plugin/TestPlugin');
  51. $loader->addNamespace('TestPluginTwo', TEST_APP . 'Plugin/TestPluginTwo');
  52. $loader->addNamespace('PluginJs', TEST_APP . 'Plugin/PluginJs');
  53. require CAKE . '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_DIR,
  64. 'www_root' => WWW_ROOT,
  65. 'fullBaseUrl' => 'http://localhost',
  66. 'imageBaseUrl' => 'img/',
  67. 'jsBaseUrl' => 'js/',
  68. 'cssBaseUrl' => 'css/',
  69. 'paths' => [
  70. 'plugins' => [TEST_APP . 'Plugin/'],
  71. 'templates' => [APP . 'Template/']
  72. ]
  73. ]);
  74. Cache::config([
  75. '_cake_core_' => [
  76. 'engine' => 'File',
  77. 'prefix' => 'cake_core_',
  78. 'serialize' => true
  79. ],
  80. '_cake_model_' => [
  81. 'engine' => 'File',
  82. 'prefix' => 'cake_model_',
  83. 'serialize' => true
  84. ]
  85. ]);
  86. // Ensure default test connection is defined
  87. if (!getenv('db_class')) {
  88. putenv('db_class=Cake\Database\Driver\Sqlite');
  89. putenv('db_dsn=sqlite::memory:');
  90. }
  91. ConnectionManager::config('test', [
  92. 'className' => 'Cake\Database\Connection',
  93. 'driver' => getenv('db_class'),
  94. 'dsn' => getenv('db_dsn'),
  95. 'database' => getenv('db_database'),
  96. 'login' => getenv('db_login'),
  97. 'password' => getenv('db_password'),
  98. 'timezone' => 'UTC'
  99. ]);
  100. Configure::write('Session', [
  101. 'defaults' => 'php'
  102. ]);
  103. Log::config([
  104. 'debug' => [
  105. 'engine' => 'Cake\Log\Engine\FileLog',
  106. 'levels' => ['notice', 'info', 'debug'],
  107. 'file' => 'debug',
  108. ],
  109. 'error' => [
  110. 'engine' => 'Cake\Log\Engine\FileLog',
  111. 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
  112. 'file' => 'error',
  113. ]
  114. ]);
  115. // Initialize the empty language.
  116. I18n::translate('empty');