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;
|
|
|
|
|
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
|
|
|
|
2012-04-30 15:04:59 +02:00
|
|
|
if(!defined('BASE_PATH')) define('BASE_PATH', dirname($frameworkPath));
|
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
|
|
|
}
|
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
// Connect to database
|
2012-05-09 12:42:45 +02:00
|
|
|
require_once $frameworkPath . '/core/Core.php';
|
|
|
|
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();
|
|
|
|
|