|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under The MIT License |
|
6
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
|
9
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
use Cake\Core\Configure; |
|
13
|
|
|
use Cake\Core\Plugin; |
|
14
|
|
|
use Cake\Mailer\Email; |
|
15
|
|
|
use Cake\Utility\Security; |
|
16
|
|
|
|
|
17
|
|
|
$findRoot = function () { |
|
18
|
|
|
$root = dirname(__DIR__); |
|
19
|
|
|
if (is_dir($root . '/vendor/cakephp/cakephp')) { |
|
20
|
|
|
return $root; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$root = dirname(dirname(__DIR__)); |
|
24
|
|
|
if (is_dir($root . '/vendor/cakephp/cakephp')) { |
|
25
|
|
|
return $root; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$root = dirname(dirname(dirname(__DIR__))); |
|
29
|
|
|
if (is_dir($root . '/vendor/cakephp/cakephp')) { |
|
30
|
|
|
return $root; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return null; |
|
34
|
|
|
}; |
|
35
|
|
|
|
|
36
|
|
|
function def($name, $value) |
|
37
|
|
|
{ |
|
38
|
|
|
if (!defined($name)) { |
|
39
|
|
|
define($name, $value); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
def('DS', DIRECTORY_SEPARATOR); |
|
44
|
|
|
def('ROOT', $findRoot()); |
|
45
|
|
|
def('APP_DIR', 'App'); |
|
46
|
|
|
def('WEBROOT_DIR', 'webroot'); |
|
47
|
|
|
def('APP', ROOT . '/tests/App/'); |
|
48
|
|
|
def('CONFIG', ROOT . '/tests/Config/'); |
|
49
|
|
|
def('WWW_ROOT', ROOT . DS . WEBROOT_DIR . DS); |
|
50
|
|
|
def('TESTS', ROOT . DS . 'tests' . DS); |
|
51
|
|
|
def('TMP', ROOT . DS . 'tmp' . DS); |
|
52
|
|
|
def('LOGS', TMP . 'logs' . DS); |
|
53
|
|
|
def('CACHE', TMP . 'cache' . DS); |
|
54
|
|
|
def('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp'); |
|
55
|
|
|
def('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS); |
|
56
|
|
|
def('CAKE', CORE_PATH . 'src' . DS); |
|
57
|
|
|
|
|
58
|
|
|
require ROOT . '/vendor/cakephp/cakephp/src/basics.php'; |
|
59
|
|
|
require ROOT . '/vendor/autoload.php'; |
|
60
|
|
|
|
|
61
|
|
|
Cake\Core\Configure::write('App.namespace', 'CakeDC\Api\Test\App'); |
|
62
|
|
|
Cake\Core\Configure::write('App.encoding', 'UTF-8'); |
|
63
|
|
|
Cake\Core\Configure::write('debug', true); |
|
64
|
|
|
|
|
65
|
|
|
$TMP = new \Cake\Filesystem\Folder(TMP); |
|
66
|
|
|
$TMP->create(TMP . 'cache/models', 0777); |
|
67
|
|
|
$TMP->create(TMP . 'cache/persistent', 0777); |
|
68
|
|
|
$TMP->create(TMP . 'cache/views', 0777); |
|
69
|
|
|
|
|
70
|
|
|
$cache = [ |
|
71
|
|
|
'default' => [ |
|
72
|
|
|
'engine' => 'File', |
|
73
|
|
|
], |
|
74
|
|
|
'_cake_core_' => [ |
|
75
|
|
|
'className' => 'File', |
|
76
|
|
|
'prefix' => 'api_app_cake_core_', |
|
77
|
|
|
'path' => CACHE . 'persistent/', |
|
78
|
|
|
'serialize' => true, |
|
79
|
|
|
'duration' => '+10 seconds', |
|
80
|
|
|
], |
|
81
|
|
|
'_cake_model_' => [ |
|
82
|
|
|
'className' => 'File', |
|
83
|
|
|
'prefix' => 'api_app_cake_model_', |
|
84
|
|
|
'path' => CACHE . 'models/', |
|
85
|
|
|
'serialize' => 'File', |
|
86
|
|
|
'duration' => '+10 seconds', |
|
87
|
|
|
], |
|
88
|
|
|
]; |
|
89
|
|
|
|
|
90
|
|
|
Cake\Cache\Cache::setConfig($cache); |
|
91
|
|
|
Cake\Core\Configure::write('EmailTransport', [ |
|
92
|
|
|
'default' => [ |
|
93
|
|
|
'className' => 'Debug', |
|
94
|
|
|
'host' => 'localhost', |
|
95
|
|
|
'port' => 25, |
|
96
|
|
|
'timeout' => 30, |
|
97
|
|
|
'username' => 'user', |
|
98
|
|
|
'password' => 'secret', |
|
99
|
|
|
'client' => null, |
|
100
|
|
|
'tls' => null, |
|
101
|
|
|
'log' => true |
|
102
|
|
|
], |
|
103
|
|
|
]); |
|
104
|
|
|
Cake\Core\Configure::write('Email', [ |
|
105
|
|
|
'default' => [ |
|
106
|
|
|
'transport' => 'default', |
|
107
|
|
|
'from' => 'test@localhost', |
|
108
|
|
|
'log' => true, |
|
109
|
|
|
], |
|
110
|
|
|
]); |
|
111
|
|
|
Cake\Core\Configure::write('Session', [ |
|
112
|
|
|
'defaults' => 'php' |
|
113
|
|
|
]); |
|
114
|
|
|
Cake\Core\Configure::write('Security.salt', 'bc8b5b70eb0e18bac40204dc3a5b9fbc8b5b70eb0e18bac40204dc3a5b9f'); |
|
115
|
|
|
|
|
116
|
|
|
mb_internal_encoding(Configure::read('App.encoding')); |
|
117
|
|
|
Security::setSalt(Configure::read('Security.salt')); |
|
118
|
|
|
\Cake\Mailer\TransportFactory::setConfig(Configure::consume('EmailTransport')); |
|
|
|
|
|
|
119
|
|
|
Email::setConfig(Configure::consume('Email')); |
|
120
|
|
|
|
|
121
|
|
|
// Ensure default test connection is defined |
|
122
|
|
|
if (!getenv('db_dsn')) { |
|
123
|
|
|
putenv('db_dsn=sqlite:///:memory:'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
Cake\Datasource\ConnectionManager::setConfig('test', [ |
|
127
|
|
|
'url' => getenv('db_dsn'), |
|
128
|
|
|
'timezone' => 'UTC' |
|
129
|
|
|
]); |
|
130
|
|
|
|
|
131
|
|
|
class_alias('CakeDC\Api\Test\App\Controller\AppController', 'App\Controller\AppController'); |
|
132
|
|
|
|
|
133
|
|
|
$isCli = PHP_SAPI === 'cli'; |
|
134
|
|
|
if ($isCli) { |
|
135
|
|
|
(new Cake\Console\ConsoleErrorHandler(Cake\Core\Configure::read('Error')))->register(); |
|
136
|
|
|
} else { |
|
137
|
|
|
(new Cake\Error\ErrorHandler(Cake\Core\Configure::read('Error')))->register(); |
|
138
|
|
|
} |
|
139
|
|
|
\Cake\Routing\Router::reload(); |
|
140
|
|
|
$application = new \CakeDC\Api\Test\App\Application(CONFIG); |
|
141
|
|
|
$application->bootstrap(); |
|
142
|
|
|
$application->pluginBootstrap(); |
|
143
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.