Permalink
Browse files

MINOR Backported bootstrap.php changes from master and cstom TeamCity…

… configuration (required to run tests through phpunit binary)
  • Loading branch information...
1 parent 921bf9a commit 44b9d0560b18c47aadab4494c7c3e93ff21a244d @chillu chillu committed Mar 14, 2012
Showing with 53 additions and 8 deletions.
  1. +53 −8 tests/bootstrap.php
View
@@ -1,12 +1,25 @@
<?php
// Simulate an execution from sapphire/cli-script.php, Core.php has too many
// hardcoded assumptions about folder depth of the executing script.
+//
+// Make sure display_errors is on
+ini_set('display_errors', 1);
// Overrides paths relative to this file (in sapphire/tests/FullTestSuite.php)
-$_SERVER['SCRIPT_FILENAME'] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'cli-script.php';
-$_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . 'sapphire' . DIRECTORY_SEPARATOR . 'cli-script.php';
+global $_SERVER;
+if (!$_SERVER) $_SERVER = array();
+$_SERVER['SCRIPT_FILENAME'] = getcwd() . DIRECTORY_SEPARATOR . 'sapphire' . DIRECTORY_SEPARATOR . 'cli-script.php';
-define('BASE_PATH', rtrim(dirname(dirname(dirname(__FILE__)))), DIRECTORY_SEPARATOR);
+// Prepare manifest autoloader
+function silverstripe_test_autoload($className) {
+ global $_CLASS_MANIFEST;
+ $lClassName = strtolower($className);
+ if(isset($_CLASS_MANIFEST[$lClassName])) include_once($_CLASS_MANIFEST[$lClassName]);
+ else if(isset($_CLASS_MANIFEST[$className])) include_once($_CLASS_MANIFEST[$className]);
+}
+spl_autoload_register('silverstripe_test_autoload');
+
+require_once(getcwd()."/sapphire/core/Core.php");
// Copied from cli-script.php, to enable same behaviour through phpunit runner.
if(isset($_SERVER['argv'][2])) {
@@ -24,12 +37,44 @@
$_REQUEST = $_GET;
}
-if(!class_exists('Object')) {
- require_once("sapphire/core/Core.php");
- global $databaseConfig;
- DB::connect($databaseConfig);
+// Now set a fake REQUEST_URI
+$_SERVER['REQUEST_URI'] = BASE_URL . '/dev/tests/all';
+
+// 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();
+ }
}
-$_SERVER['REQUEST_URI'] = BASE_URL . '/dev';
+global $_ALL_CLASSES;
+$_ALL_CLASSES['parents']['FakeController'] = array_merge($_ALL_CLASSES['parents']['Controller'], array('Controller' => 'Controller'));
+
+$controller = new FakeController();
+
+// Connect to database
+global $databaseConfig;
+
+require_once(getcwd()."/sapphire/core/model/DB.php");
+DB::connect($databaseConfig);
+// Get test manifest
ManifestBuilder::load_test_manifest();

0 comments on commit 44b9d05

Please sign in to comment.