NEW: Refactor test bootstrap to be more modular.

The test bootstrap is broken into units that can be combined for
different test situations:

 - phpunit
 - behat
 - serve
This commit is contained in:
Sam Minnee 2016-10-28 17:47:30 +13:00
parent d946a3b240
commit bf9939e32c
6 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,7 @@
<?php
require __DIR__ . '/../bootstrap/init.php';
require FRAMEWORK_PATH . '/tests/bootstrap/init.php';
require FRAMEWORK_PATH . '/tests/bootstrap/environment.php';
require __DIR__ . '/../bootstrap/mysite.php';
require FRAMEWORK_PATH . '/tests/bootstrap/mysite.php';

10
tests/bootstrap.php Normal file
View File

@ -0,0 +1,10 @@
<?php
require __DIR__ . '/bootstrap/init.php';
require FRAMEWORK_PATH . '/tests/bootstrap/init.php';
require FRAMEWORK_PATH . '/tests/bootstrap/cli.php';
require FRAMEWORK_PATH . '/tests/bootstrap/environment.php';
require __DIR__ . '/bootstrap/mysite.php';
require FRAMEWORK_PATH . '/tests/bootstrap/mysite.php';
require FRAMEWORK_PATH . '/tests/bootstrap/phpunit.php';

View File

@ -0,0 +1,12 @@
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Controllers\ContentController;
class Page extends SiteTree
{
}
class Page_Controller extends ContentController
{
}

12
tests/bootstrap/init.php Normal file
View File

@ -0,0 +1,12 @@
<?php
if(!defined('FRAMEWORK_PATH')) {
echo "FRAMEWORK_PATH hasn't been defined. This probably means that framework/Core/Constants.php hasn't been " .
"included by Composer's autoloader.\n" .
"Make sure the you are running your tests via vendor/bin/phpunit and your autoloader is up to date.\n";
exit(1);
}
if (empty($_SERVER['HTTP_HOST'])) {
$_SERVER['HTTP_HOST'] = 'localhost';
}

View File

@ -0,0 +1,14 @@
<?php
// Mock mysite if not installed with silverstripe/installer
if (defined('BASE_PATH')) {
$projectPath = BASE_PATH . '/mysite';
} else {
$projectPath = getcwd() . '/mysite';
}
if (!is_dir($projectPath)) {
mkdir($projectPath, 02775);
mkdir($projectPath.'/code', 02775);
mkdir($projectPath.'/_config', 02775);
copy(__DIR__.'/fixtures/Page.php.fixture', $projectPath . '/code/Page.php');
}