Skip to content

Commit

Permalink
Simplify tests bootstrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jul 28, 2019
1 parent 1180d85 commit 483ad65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 69 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"require-dev": {
"cakephp/cakephp": "^3.5",
"cakephp/chronos": "^1.1",
"phpunit/phpunit": "^5.7.14|^6.0",
"league/flysystem-vfs": "*",
"cakephp/cakephp-codesniffer": "dev-master"
Expand Down
85 changes: 16 additions & 69 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,24 @@
<?php
// @codingStandardsIgnoreFile

$findRoot = function () {
$root = __DIR__;
for ($i = 0; $i < 3; $i++) {
/*
* Test suite bootstrap
*
* This function is used to find the location of CakePHP whether CakePHP
* has been installed as a dependency of the plugin, or the plugin is itself
* installed as a dependency of an application.
*/
$findRoot = function ($root) {
do {
$lastRoot = $root;
$root = dirname($root);
if (is_dir($root . '/vendor/cakephp/cakephp')) {
return $root;
}
}
} while ($root !== $lastRoot);
throw new Exception('Cannot find the root of the application, unable to run tests');
};

if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
define('ROOT', $findRoot());
define('APP_DIR', 'App');
define('WEBROOT_DIR', 'webroot');
define('APP', ROOT . '/tests/App/');
define('CONFIG', ROOT . '/tests/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('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/autoload.php';
require CORE_PATH . 'config/bootstrap.php';

Cake\Core\Configure::write('App', ['namespace' => 'App']);
Cake\Core\Configure::write('debug', true);

$TMP = new \Cake\Filesystem\Folder(TMP);
$TMP->create(TMP . 'cache/models', 0777);
$TMP->create(TMP . 'cache/persistent', 0777);
$TMP->create(TMP . 'cache/views', 0777);

$cache = [
'default' => [
'engine' => 'File'
],
'_cake_core_' => [
'className' => 'File',
'prefix' => 'upload_myapp_cake_core_',
'path' => CACHE . 'persistent/',
'serialize' => true,
'duration' => '+10 seconds'
],
'_cake_model_' => [
'className' => 'File',
'prefix' => 'upload_my_app_cake_model_',
'path' => CACHE . 'models/',
'serialize' => 'File',
'duration' => '+10 seconds'
]
];

Cake\Cache\Cache::setConfig($cache);
Cake\Core\Configure::write('Session', [
'defaults' => 'php'
]);

// Ensure default test connection is defined
if (!getenv('db_dsn')) {
putenv('db_dsn=sqlite:///:memory:');
}

Cake\Datasource\ConnectionManager::setConfig('test', [
'url' => getenv('db_dsn'),
'timezone' => 'UTC'
]);
$root = $findRoot(__FILE__);
unset($findRoot);
chdir($root);

loadPHPUnitAliases();
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';

0 comments on commit 483ad65

Please sign in to comment.