-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbootstrap.php
149 lines (129 loc) · 3.99 KB
/
bootstrap.php
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
declare(strict_types=1);
/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2020 Juan Pablo Ramirez and Nicolas Masson
* @link https://webrider.de/
* @since 1.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\Utility\Inflector;
use function Cake\Core\env;
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
define('ROOT', dirname(__DIR__));
define('APP_DIR', 'src');
define('APP_PATH', ROOT . DS . 'TestApp' . DS);
define('VENDOR_PATH', ROOT . DS . 'vendor' . DS);
define('TEMPLATE_PATH_CAKE_4', ROOT . DS . 'templates' . DS);
define('TEMPLATE_PATH_CAKE_3', ROOT . DS . APP_DIR . DS . 'Template' . DS);
define('TMP', ROOT . DS . 'tmp' . DS);
define('LOGS', TMP . 'logs' . DS);
define('CACHE', TMP . 'cache' . DS);
define('SESSIONS', TMP . 'sessions' . DS);
define('CAKE_CORE_INCLUDE_PATH', VENDOR_PATH . 'cakephp' . DS . 'cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . 'src' . DS);
define('CORE_TESTS', ROOT . DS . 'tests' . DS);
define('CORE_TEST_CASES', CORE_TESTS . 'TestCase');
define('TEST_APP', CORE_TESTS . 'TestApp' . DS);
// Point app constants to the test app.
define('APP', TEST_APP . 'src' . DS);
define('TESTS', TEST_APP . 'tests' . DS);
define('WWW_ROOT', TEST_APP . 'webroot' . DS);
define('CONFIG', TEST_APP . 'config' . DS);
// phpcs:disable
@mkdir(LOGS);
@mkdir(SESSIONS);
@mkdir(CACHE);
@mkdir(CACHE . 'views');
@mkdir(CACHE . 'models');
// phpcs:enable
require_once CORE_PATH . 'config/bootstrap.php';
Configure::write('debug', true);
Configure::write('App', [
'namespace' => 'TestApp',
'encoding' => 'UTF-8',
'paths' => [
'plugins' => [TEST_APP . 'plugins' . DS],
'templates' => [
TEST_APP . 'templates' . DS,
TEMPLATE_PATH_CAKE_4,
TEMPLATE_PATH_CAKE_3,
\Cake\Core\Plugin::templatePath('Bake'),
],
],
]);
Cache::setConfig([
'_cake_core_' => [
'engine' => 'File',
'prefix' => 'cake_core_',
'serialize' => true,
],
'_cake_model_' => [
'engine' => 'File',
'prefix' => 'cake_model_',
'serialize' => true,
],
]);
$loadEnv = function(string $fileName) {
if (file_exists($fileName)) {
$dotenv = new \josegonzalez\Dotenv\Loader($fileName);
$dotenv->parse()
->putenv(true)
->toEnv(true)
->toServer(true);
}
};
if (!getenv('DB_DRIVER')) {
putenv('DB_DRIVER=Sqlite');
}
$driver = getenv('DB_DRIVER');
$testDir = ROOT . DS . 'tests' . DS;
if (!file_exists("$testDir.env")) {
@copy("$testDir.env.$driver", "$testDir.env");
}
/**
* Read .env file(s).
*/
$loadEnv("$testDir.env");
// Re-read the driver
$driver = getenv('DB_DRIVER');
echo "Using driver $driver \n";
$dbConnection = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\\' . $driver,
'persistent' => false,
'host' => getenv('DB_HOST'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PWD'),
'database' => getenv('DB_DATABASE'),
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => true,
'log' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_TEST_URL', null),
'migrations' => [
['connection' => 'test'],
['plugin' => 'TestPlugin'],
]
];
ConnectionManager::setConfig('test', $dbConnection);
$dbConnection['dummy_key'] = 'DummyKeyValue';
ConnectionManager::setConfig('dummy', $dbConnection);
ConnectionManager::alias('test', 'default');
Inflector::rules('singular', ['/(ss)$/i' => '\1']);
(new \Migrations\TestSuite\Migrator())->runMany([
// TestApp Migrations
[],
['plugin' => 'TestPlugin'],
]);