2010-10-19 05:41:34 +02:00
|
|
|
<?php
|
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);
|
|
|
|
|
2012-05-28 06:20:28 +02:00
|
|
|
// Check we're using at least PHPUnit 3.5
|
|
|
|
if(version_compare(PHPUnit_Runner_Version::id(), '3.5', '<')) {
|
|
|
|
echo 'PHPUnit 3.5 required to run tests using bootstrap.php';
|
2012-05-09 13:40:25 +02:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
// 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-08-14 06:44:32 +02:00
|
|
|
$_GET['flush'] = 1;
|
2012-03-24 04:38:57 +01:00
|
|
|
$_SERVER['SCRIPT_FILENAME'] = $frameworkPath . DIRECTORY_SEPARATOR . 'cli-script.php';
|
|
|
|
$_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . $frameworkDir . DIRECTORY_SEPARATOR . 'cli-script.php';
|
|
|
|
|
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])) {
|
|
|
|
$args = array_slice($_SERVER['argv'],2);
|
2012-07-04 12:05:31 +02:00
|
|
|
if(!isset($_GET)) $_GET = array();
|
|
|
|
if(!isset($_REQUEST)) $_REQUEST = array();
|
2010-10-19 05:41:34 +02:00
|
|
|
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
|
2010-10-19 05:41:34 +02:00
|
|
|
$_SERVER['REQUEST_URI'] = BASE_URL . '/dev';
|
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
// Fake a session
|
|
|
|
$_SESSION = null;
|
|
|
|
|
|
|
|
// Prepare manifest autoloader
|
|
|
|
$controller = new FakeController();
|
|
|
|
|
|
|
|
// Get test manifest
|
2011-12-04 13:10:28 +01:00
|
|
|
TestRunner::use_test_manifest();
|
|
|
|
|
|
|
|
// Remove the error handler so that PHPUnit can add its own
|
2012-07-06 12:00:38 +02:00
|
|
|
restore_error_handler();
|
|
|
|
|
|
|
|
if(!isset($_GET['flush']) || !$_GET['flush']) {
|
|
|
|
Debug::message(
|
|
|
|
"WARNING: Manifest not flushed. " .
|
|
|
|
"Add flush=1 as an argument to discover new classes or files.\n",
|
|
|
|
false
|
|
|
|
);
|
2012-08-14 06:44:32 +02:00
|
|
|
}
|