mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Refactor bootstrap.php to allow for code sharing with cms bootstrap
This commit is contained in:
parent
5347d660a0
commit
e386c6a153
@ -54,7 +54,8 @@ before_script:
|
||||
- "if [ \"$NPM_TEST\" = \"1\" ]; then nvm install $TRAVIS_NODE_VERSION && npm install; fi"
|
||||
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then sh -e /etc/init.d/xvfb start; sleep 3; fi"
|
||||
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then (vendor/bin/selenium-server-standalone > selenium.log 2>&1 &); fi"
|
||||
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then (vendor/bin/serve --bootstrap-file tests/behat/serve-bootstrap.php &> serve.log &); fi"
|
||||
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then (vendor/bin/serve --bootstrap-file tests/behat/serve-bootstrap.php &> serve.log &); fi"
|
||||
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then (vendor/bin/serve --bootstrap-file cms/tests/behat/serve-bootstrap.php &> serve.log &); fi"
|
||||
script:
|
||||
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/phpunit; fi"
|
||||
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then vendor/bin/phpunit cms/tests; fi"
|
||||
|
@ -1,47 +1,5 @@
|
||||
<?php
|
||||
|
||||
// Asset folder
|
||||
if(!file_exists(BASE_PATH . '/assets')) {
|
||||
mkdir(BASE_PATH . '/assets', 02775);
|
||||
}
|
||||
|
||||
// DATABASE BOOTSTRAP
|
||||
if (!defined('SS_ENVIRONMENT_TYPE')) {
|
||||
define('SS_ENVIRONMENT_TYPE', 'dev');
|
||||
}
|
||||
|
||||
if (!defined('SS_DATABASE_CLASS') && !defined('SS_DATABASE_USERNAME')) {
|
||||
// The default settings let us define the database config via environment vars
|
||||
// Database connection, including PDO and legacy ORM support
|
||||
switch(getenv('DB')) {
|
||||
case "PGSQL";
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'PostgrePDODatabase' : 'PostgreSQLDatabase');
|
||||
define('SS_DATABASE_USERNAME', 'postgres');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
break;
|
||||
|
||||
case "SQLITE":
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'SQLite3PDODatabase' : 'SQLite3Database');
|
||||
define('SS_DATABASE_USERNAME', 'root');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
define('SS_SQLITE_DATABASE_PATH', ':memory:');
|
||||
break;
|
||||
|
||||
default:
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'MySQLPDODatabase' : 'MySQLDatabase');
|
||||
define('SS_DATABASE_USERNAME', 'root');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
}
|
||||
|
||||
define('SS_DATABASE_SERVER', '127.0.0.1');
|
||||
define('SS_DATABASE_CHOOSE_NAME', true);
|
||||
}
|
||||
|
||||
// Default database settings
|
||||
global $database;
|
||||
$database = '';
|
||||
|
||||
require_once(__DIR__ . '/../../conf/ConfigureFromEnv.php');
|
||||
|
||||
class Page extends SilverStripe\View\ViewableData {}
|
||||
class Page_Controller extends SilverStripe\Control\Controller {}
|
||||
require __DIR__ . '/../bootstrap/init.php';
|
||||
require __DIR__ . '/../bootstrap/environment.php';
|
||||
require __DIR__ . '/../bootstrap/mysite.php';
|
||||
|
@ -1,122 +1,7 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
if(!defined('BASE_PATH')) {
|
||||
echo "BASE_PATH hasn't been defined. This probably means that framework/Core/Constants.php hasn't been " .
|
||||
"included by Composer's autoloader.\n" .
|
||||
"Make sure the you are running your tests via vendor/bin/phpunit and your autoloader is up to date.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This bootstraps the SilverStripe system so that phpunit can be run directly on SilverStripe tests.
|
||||
*/
|
||||
|
||||
// Make sure display_errors is on
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Fake the script name and base
|
||||
global $_SERVER;
|
||||
if (!$_SERVER) $_SERVER = array();
|
||||
|
||||
$frameworkPath = dirname(dirname(__FILE__));
|
||||
$frameworkDir = basename($frameworkPath);
|
||||
|
||||
$_SERVER['SCRIPT_FILENAME'] = $frameworkPath . DIRECTORY_SEPARATOR . 'cli-script.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . $frameworkDir . DIRECTORY_SEPARATOR . 'cli-script.php';
|
||||
|
||||
// Copied from cli-script.php, to enable same behaviour through phpunit runner.
|
||||
if(isset($_SERVER['argv'][2])) {
|
||||
$args = array_slice($_SERVER['argv'],2);
|
||||
if(!isset($_GET)) $_GET = array();
|
||||
if(!isset($_REQUEST)) $_REQUEST = array();
|
||||
foreach($args as $arg) {
|
||||
if(strpos($arg,'=') == false) {
|
||||
$_GET['args'][] = $arg;
|
||||
} else {
|
||||
$newItems = array();
|
||||
parse_str( (substr($arg,0,2) == '--') ? substr($arg,2) : $arg, $newItems );
|
||||
$_GET = array_merge($_GET, $newItems);
|
||||
}
|
||||
}
|
||||
$_REQUEST = array_merge($_REQUEST, $_GET);
|
||||
}
|
||||
|
||||
// DATABASE BOOTSTRAP
|
||||
|
||||
if (!defined('SS_ENVIRONMENT_TYPE')) {
|
||||
define('SS_ENVIRONMENT_TYPE', 'dev');
|
||||
}
|
||||
|
||||
if (!defined('SS_DATABASE_CLASS') && !defined('SS_DATABASE_USERNAME')) {
|
||||
// The default settings let us define the database config via environment vars
|
||||
// Database connection, including PDO and legacy ORM support
|
||||
switch(getenv('DB')) {
|
||||
case "PGSQL";
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'PostgrePDODatabase' : 'PostgreSQLDatabase');
|
||||
define('SS_DATABASE_USERNAME', 'postgres');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
break;
|
||||
|
||||
case "SQLITE":
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'SQLite3PDODatabase' : 'SQLite3Database');
|
||||
define('SS_DATABASE_USERNAME', 'root');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
define('SS_SQLITE_DATABASE_PATH', ':memory:');
|
||||
break;
|
||||
|
||||
default:
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'MySQLPDODatabase' : 'MySQLDatabase');
|
||||
define('SS_DATABASE_USERNAME', 'root');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
}
|
||||
|
||||
define('SS_DATABASE_SERVER', '127.0.0.1');
|
||||
define('SS_DATABASE_CHOOSE_NAME', true);
|
||||
}
|
||||
|
||||
// Ensure Director::protocolAndHost() works
|
||||
if (empty($_SERVER['HTTP_HOST'])) {
|
||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||
}
|
||||
|
||||
// Asset folder
|
||||
if(!file_exists(BASE_PATH . '/assets')) {
|
||||
mkdir(BASE_PATH . '/assets', 02775);
|
||||
}
|
||||
|
||||
// Default database settings
|
||||
global $project;
|
||||
$project = 'mysite';
|
||||
|
||||
global $database;
|
||||
$database = '';
|
||||
|
||||
require_once(__DIR__ . '/../conf/ConfigureFromEnv.php');
|
||||
|
||||
// Connect to database
|
||||
require_once $frameworkPath . '/Core/Core.php';
|
||||
require_once $frameworkPath . '/tests/FakeController.php';
|
||||
|
||||
global $databaseConfig;
|
||||
DB::connect($databaseConfig);
|
||||
|
||||
// Now set a fake REQUEST_URI
|
||||
$_SERVER['REQUEST_URI'] = BASE_URL;
|
||||
|
||||
// Fake a session
|
||||
$_SESSION = null;
|
||||
|
||||
// Prepare manifest autoloader
|
||||
$controller = new FakeController();
|
||||
|
||||
SapphireTest::use_test_manifest();
|
||||
|
||||
SapphireTest::set_is_running_test(true);
|
||||
|
||||
// Remove the error handler so that PHPUnit can add its own
|
||||
restore_error_handler();
|
||||
|
||||
require __DIR__ . '/bootstrap/init.php';
|
||||
require __DIR__ . '/bootstrap/cli.php';
|
||||
require __DIR__ . '/bootstrap/environment.php';
|
||||
require __DIR__ . '/bootstrap/mysite.php';
|
||||
require __DIR__ . '/bootstrap/phpunit.php';
|
||||
|
0
tests/bootstrap/_manifest_exclude
Normal file
0
tests/bootstrap/_manifest_exclude
Normal file
33
tests/bootstrap/cli.php
Normal file
33
tests/bootstrap/cli.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
// Fake the script name and base
|
||||
global $_SERVER;
|
||||
if (!$_SERVER) $_SERVER = array();
|
||||
|
||||
$frameworkPath = dirname(dirname(__FILE__));
|
||||
$frameworkDir = basename($frameworkPath);
|
||||
|
||||
$_SERVER['SCRIPT_FILENAME'] = $frameworkPath . DIRECTORY_SEPARATOR . 'cli-script.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . $frameworkDir . DIRECTORY_SEPARATOR . 'cli-script.php';
|
||||
|
||||
// Copied from cli-script.php, to enable same behaviour through phpunit runner.
|
||||
if(isset($_SERVER['argv'][2])) {
|
||||
$args = array_slice($_SERVER['argv'],2);
|
||||
if(!isset($_GET)) $_GET = array();
|
||||
if(!isset($_REQUEST)) $_REQUEST = array();
|
||||
foreach($args as $arg) {
|
||||
if(strpos($arg,'=') == false) {
|
||||
$_GET['args'][] = $arg;
|
||||
} else {
|
||||
$newItems = array();
|
||||
parse_str( (substr($arg,0,2) == '--') ? substr($arg,2) : $arg, $newItems );
|
||||
$_GET = array_merge($_GET, $newItems);
|
||||
}
|
||||
}
|
||||
$_REQUEST = array_merge($_REQUEST, $_GET);
|
||||
}
|
||||
|
||||
// Ensure Director::protocolAndHost() works
|
||||
if (empty($_SERVER['HTTP_HOST'])) {
|
||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||
}
|
34
tests/bootstrap/environment.php
Normal file
34
tests/bootstrap/environment.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
// Bootstrap _ss_environment.php
|
||||
|
||||
if (!defined('SS_ENVIRONMENT_TYPE')) {
|
||||
define('SS_ENVIRONMENT_TYPE', 'dev');
|
||||
}
|
||||
|
||||
if (!defined('SS_DATABASE_CLASS') && !defined('SS_DATABASE_USERNAME')) {
|
||||
// The default settings let us define the database config via environment vars
|
||||
// Database connection, including PDO and legacy ORM support
|
||||
switch(getenv('DB')) {
|
||||
case "PGSQL";
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'PostgrePDODatabase' : 'PostgreSQLDatabase');
|
||||
define('SS_DATABASE_USERNAME', 'postgres');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
break;
|
||||
|
||||
case "SQLITE":
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'SQLite3PDODatabase' : 'SQLite3Database');
|
||||
define('SS_DATABASE_USERNAME', 'root');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
define('SS_SQLITE_DATABASE_PATH', ':memory:');
|
||||
break;
|
||||
|
||||
default:
|
||||
define('SS_DATABASE_CLASS', getenv('PDO') ? 'MySQLPDODatabase' : 'MySQLDatabase');
|
||||
define('SS_DATABASE_USERNAME', 'root');
|
||||
define('SS_DATABASE_PASSWORD', '');
|
||||
}
|
||||
|
||||
define('SS_DATABASE_SERVER', '127.0.0.1');
|
||||
define('SS_DATABASE_CHOOSE_NAME', true);
|
||||
}
|
21
tests/bootstrap/init.php
Normal file
21
tests/bootstrap/init.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
if(!defined('BASE_PATH')) {
|
||||
echo "BASE_PATH hasn't been defined. This probably means that framework/Core/Constants.php hasn't been " .
|
||||
"included by Composer's autoloader.\n" .
|
||||
"Make sure the you are running your tests via vendor/bin/phpunit and your autoloader is up to date.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This bootstraps the SilverStripe system so that phpunit can be run directly on SilverStripe tests.
|
||||
*/
|
||||
|
||||
// Make sure display_errors is on
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Asset folder
|
||||
if(!file_exists(BASE_PATH . '/assets')) {
|
||||
mkdir(BASE_PATH . '/assets', 02775);
|
||||
}
|
10
tests/bootstrap/mysite.php
Normal file
10
tests/bootstrap/mysite.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
// Default database settings
|
||||
global $project;
|
||||
$project = 'mysite';
|
||||
|
||||
global $database;
|
||||
$database = '';
|
||||
|
||||
require_once(__DIR__ . '/../../conf/ConfigureFromEnv.php');
|
29
tests/bootstrap/phpunit.php
Normal file
29
tests/bootstrap/phpunit.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
// Bootstrap for running SapphireTests
|
||||
|
||||
// Connect to database
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\DB;
|
||||
|
||||
require_once __DIR__ . '/../../Core/Core.php';
|
||||
require_once __DIR__ . '/../FakeController.php';
|
||||
|
||||
global $databaseConfig;
|
||||
DB::connect($databaseConfig);
|
||||
|
||||
// Now set a fake REQUEST_URI
|
||||
$_SERVER['REQUEST_URI'] = BASE_URL;
|
||||
|
||||
// Fake a session
|
||||
$_SESSION = null;
|
||||
|
||||
// Prepare manifest autoloader
|
||||
$controller = new FakeController();
|
||||
|
||||
SapphireTest::use_test_manifest();
|
||||
|
||||
SapphireTest::set_is_running_test(true);
|
||||
|
||||
// Remove the error handler so that PHPUnit can add its own
|
||||
restore_error_handler();
|
Loading…
Reference in New Issue
Block a user