MINOR Backported bootstrap.php changes from CI setup (creates a FakeController to avoid empty controller stacks, fake empty session global)

This commit is contained in:
Ingo Schommer 2011-12-04 13:35:06 +01:00
parent 755663a00a
commit 1b544a46a3

View File

@ -2,11 +2,17 @@
// Simulate an execution from sapphire/cli-script.php, Core.php has too many
// hardcoded assumptions about folder depth of the executing script.
// Overrides paths relative to this file (in sapphire/tests/FullTestSuite.php)
$_SERVER['SCRIPT_FILENAME'] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'cli-script.php';
// 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';
$_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . 'sapphire' . DIRECTORY_SEPARATOR . 'cli-script.php';
define('BASE_PATH', rtrim(dirname(dirname(dirname(__FILE__)))), DIRECTORY_SEPARATOR);
define('BASE_PATH', getcwd());
// Copied from cli-script.php, to enable same behaviour through phpunit runner.
if(isset($_SERVER['argv'][2])) {
@ -24,14 +30,47 @@ if(isset($_SERVER['argv'][2])) {
$_REQUEST = $_GET;
}
if(!class_exists('Object')) {
require_once("sapphire/core/Core.php");
global $databaseConfig;
DB::connect($databaseConfig);
}
// Connect to database
require_once(getcwd()."/sapphire/core/Core.php");
global $databaseConfig;
DB::connect($databaseConfig);
// Now set a fake REQUEST_URI
$_SERVER['REQUEST_URI'] = BASE_URL . '/dev';
// 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
TestRunner::use_test_manifest();
// Remove the error handler so that PHPUnit can add its own