Repository navigation
Expand file tree
/
Copy pathbootstrap.php
More file actions
133 lines (116 loc) · 3.45 KB
/
Copy pathbootstrap.php
File metadata and controls
133 lines (116 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
declare(strict_types=1);
$findRoot = function (): string {
$root = dirname(__DIR__);
if (is_dir($root . '/vendor/cakephp/cakephp')) {
return $root;
}
$root = dirname(__DIR__, 2);
if (is_dir($root . '/vendor/cakephp/cakephp')) {
return $root;
}
$root = dirname(__DIR__, 3);
if (is_dir($root . '/vendor/cakephp/cakephp')) {
return $root;
}
return dirname(__DIR__);
};
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
define('ROOT', $findRoot());
define('APP_DIR', 'TestApp');
define('WEBROOT_DIR', 'webroot');
define('APP', ROOT . '/tests/TestApp/');
define('CONFIG', ROOT . '/tests/TestApp/config/');
define('WWW_ROOT', ROOT . DS . WEBROOT_DIR . DS);
define('TESTS', ROOT . DS . 'tests' . DS);
define('TMP', ROOT . DS . 'tmp' . DS);
define('LOGS', TMP . 'logs' . DS);
define('CACHE', TMP . 'cache' . DS);
define('SESSIONS', TMP . 'sessions' . DS);
define('RESOURCES', ROOT . DS . 'resources' . DS);
define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . 'src' . DS);
require ROOT . '/vendor/cakephp/cakephp/src/functions.php';
require ROOT . '/vendor/autoload.php';
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\Fixture\SchemaLoader;
use Crustum\Stimulus\StimulusPlugin;
if (!function_exists('ensureDirectoryExists')) {
/**
* @param string $path Directory path
* @return void
*/
function ensureDirectoryExists(string $path): void
{
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
}
}
ensureDirectoryExists(TMP . 'cache/models');
ensureDirectoryExists(TMP . 'cache/persistent');
ensureDirectoryExists(TMP . 'cache/views');
ensureDirectoryExists(TMP . 'sessions');
ensureDirectoryExists(TMP . 'tests');
ensureDirectoryExists(LOGS);
Configure::write('debug', true);
Configure::write('App', [
'namespace' => 'TestApp',
'encoding' => 'UTF-8',
'defaultLocale' => 'en_US',
'defaultTimezone' => 'UTC',
'base' => false,
'dir' => 'src',
'webroot' => 'webroot',
'wwwRoot' => WWW_ROOT,
'fullBaseUrl' => 'http://localhost',
'paths' => [
'plugins' => [ROOT . DS],
'templates' => [APP . 'templates' . DS],
'locales' => [RESOURCES . 'locales' . DS],
],
]);
Configure::write('Security', [
'salt' => 'stimulus-test-security-salt-change-me',
]);
Configure::write('Session', [
'defaults' => 'php',
]);
Cache::setConfig('_cake_translations_', [
'className' => 'File',
'path' => CACHE . 'persistent/',
'prefix' => 'stimulus_test_translations_',
'serialize' => true,
'duration' => '+10 seconds',
]);
Cache::setConfig('_cake_model_', [
'className' => 'File',
'path' => CACHE . 'models/',
'prefix' => 'stimulus_test_model_',
'serialize' => true,
'duration' => '+10 seconds',
]);
if (!getenv('db_dsn')) {
putenv('db_dsn=sqlite:///:memory:');
}
ConnectionManager::setConfig('test', [
'url' => getenv('db_dsn'),
'timezone' => 'UTC',
]);
ConnectionManager::alias('test', 'default');
Plugin::getCollection()->add(new StimulusPlugin([
'path' => dirname(__DIR__) . DS,
'bootstrap' => true,
'routes' => true,
]));
$schemaLoader = new SchemaLoader();
$schemaLoader->loadInternalFile(TESTS . 'schema.php');
if (file_exists(CONFIG . 'bootstrap.php')) {
require CONFIG . 'bootstrap.php';
}