2010-10-19 05:41:34 +02:00
|
|
|
<?php
|
2012-05-28 06:20:28 +02:00
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\DB;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2016-09-20 23:43:14 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
/**
|
2012-05-28 06:20:28 +02:00
|
|
|
* This bootstraps the SilverStripe system so that phpunit can be run directly on SilverStripe tests.
|
|
|
|
*/
|
2010-10-19 05:41:34 +02:00
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
// Make sure display_errors is on
|
|
|
|
ini_set('display_errors', 1);
|
|
|
|
|
|
|
|
// Fake the script name and base
|
|
|
|
global $_SERVER;
|
|
|
|
if (!$_SERVER) $_SERVER = array();
|
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
$frameworkPath = dirname(dirname(__FILE__));
|
|
|
|
$frameworkDir = basename($frameworkPath);
|
2010-10-19 05:41:34 +02:00
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
$_SERVER['SCRIPT_FILENAME'] = $frameworkPath . DIRECTORY_SEPARATOR . 'cli-script.php';
|
2014-08-15 08:53:05 +02:00
|
|
|
$_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . $frameworkDir . DIRECTORY_SEPARATOR . 'cli-script.php';
|
2012-03-24 04:38:57 +01:00
|
|
|
|
2010-10-19 05:41:34 +02:00
|
|
|
// Copied from cli-script.php, to enable same behaviour through phpunit runner.
|
|
|
|
if(isset($_SERVER['argv'][2])) {
|
2012-12-08 12:20:20 +01:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
2012-07-04 12:05:31 +02:00
|
|
|
$_REQUEST = array_merge($_REQUEST, $_GET);
|
2010-10-19 05:41:34 +02:00
|
|
|
}
|
|
|
|
|
2016-09-12 07:42:05 +02:00
|
|
|
// 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';
|
|
|
|
}
|
|
|
|
|
2016-09-13 08:23:31 +02:00
|
|
|
// Asset folder
|
|
|
|
if(!file_exists(BASE_PATH . '/assets')) {
|
|
|
|
mkdir(BASE_PATH . '/assets', 02775);
|
|
|
|
}
|
|
|
|
|
2016-09-12 07:42:05 +02:00
|
|
|
// Default database settings
|
|
|
|
global $project;
|
|
|
|
$project = 'mysite';
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
$database = '';
|
|
|
|
|
|
|
|
require_once(__DIR__ . '/../conf/ConfigureFromEnv.php');
|
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
// Connect to database
|
2016-08-19 00:51:35 +02:00
|
|
|
require_once $frameworkPath . '/Core/Core.php';
|
2012-05-09 12:42:45 +02:00
|
|
|
require_once $frameworkPath . '/tests/FakeController.php';
|
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
global $databaseConfig;
|
|
|
|
DB::connect($databaseConfig);
|
2010-10-19 05:41:34 +02:00
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
// Now set a fake REQUEST_URI
|
2015-07-16 11:32:42 +02:00
|
|
|
$_SERVER['REQUEST_URI'] = BASE_URL;
|
2010-10-19 05:41:34 +02:00
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
// Fake a session
|
2011-12-04 13:35:06 +01:00
|
|
|
$_SESSION = null;
|
|
|
|
|
|
|
|
// Prepare manifest autoloader
|
|
|
|
$controller = new FakeController();
|
|
|
|
|
2015-07-16 11:32:42 +02:00
|
|
|
SapphireTest::use_test_manifest();
|
2011-12-04 13:10:28 +01:00
|
|
|
|
2013-01-09 23:31:10 +01:00
|
|
|
SapphireTest::set_is_running_test(true);
|
|
|
|
|
2011-12-04 13:10:28 +01:00
|
|
|
// Remove the error handler so that PHPUnit can add its own
|
2012-07-06 12:00:38 +02:00
|
|
|
restore_error_handler();
|
|
|
|
|