2010-10-19 05:41:34 +02:00
|
|
|
<?php
|
|
|
|
// Simulate an execution from sapphire/cli-script.php, Core.php has too many
|
|
|
|
// hardcoded assumptions about folder depth of the executing script.
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = getcwd() . DIRECTORY_SEPARATOR . 'sapphire' . DIRECTORY_SEPARATOR . 'cli-script.php';
|
2010-10-19 05:41:34 +02:00
|
|
|
$_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . 'sapphire' . DIRECTORY_SEPARATOR . 'cli-script.php';
|
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
define('BASE_PATH', getcwd());
|
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);
|
|
|
|
$_GET = 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 = $_GET;
|
|
|
|
}
|
|
|
|
|
2011-12-04 13:35:06 +01:00
|
|
|
// Connect to database
|
|
|
|
require_once(getcwd()."/sapphire/core/Core.php");
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Fake a current controller. Way harder than it should be
|
|
|
|
class FakeController extends Controller {
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$session = new Session(isset($_SESSION) ? $_SESSION : null);
|
|
|
|
$this->setSession($session);
|
|
|
|
|
|
|
|
$this->pushCurrent();
|
|
|
|
|
|
|
|
$this->request = new SS_HTTPRequest(
|
|
|
|
(isset($_SERVER['X-HTTP-Method-Override'])) ? $_SERVER['X-HTTP-Method-Override'] : $_SERVER['REQUEST_METHOD'],
|
|
|
|
'/'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->response = new SS_HTTPResponse();
|
|
|
|
|
|
|
|
$this->init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
global $_ALL_CLASSES;
|
|
|
|
if(isset($_ALL_CLASSES)) {
|
|
|
|
$_ALL_CLASSES['parents']['FakeController'] = array_merge($_ALL_CLASSES['parents']['Controller'], array('Controller' => 'Controller'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
restore_error_handler();
|