mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Merge pull request #163 from open-sausages/pulls/4.0/app-object
Updated behat-extension to use app object
This commit is contained in:
commit
704300f873
@ -2,7 +2,13 @@
|
||||
|
||||
namespace SilverStripe\BehatExtension\Compiler;
|
||||
|
||||
use SilverStripe\Control\CLIRequestBuilder;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPApplication;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Core\CoreKernel;
|
||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
@ -18,12 +24,13 @@ class CoreInitializationPass implements CompilerPassInterface
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
// Note: Moved from SilverStripeAwareInitializer
|
||||
file_put_contents('php://stdout', 'Bootstrapping' . PHP_EOL);
|
||||
|
||||
// Connect to database and build manifest
|
||||
$_GET['flush'] = 1;
|
||||
if (!getenv('SS_ENVIRONMENT_TYPE')) {
|
||||
putenv('SS_ENVIRONMENT_TYPE=dev');
|
||||
}
|
||||
require_once('Core/Core.php');
|
||||
|
||||
// Include bootstrap file
|
||||
$bootstrapFile = $container->getParameter('silverstripe_extension.bootstrap_file');
|
||||
@ -31,6 +38,25 @@ class CoreInitializationPass implements CompilerPassInterface
|
||||
require_once $bootstrapFile;
|
||||
}
|
||||
|
||||
// Copied from SapphireTest
|
||||
$request = CLIRequestBuilder::createFromEnvironment();
|
||||
$kernel = new CoreKernel(BASE_PATH);
|
||||
$app = new HTTPApplication($kernel);
|
||||
$app->execute($request, function (HTTPRequest $request) {
|
||||
// Start session and execute
|
||||
$request->getSession()->init();
|
||||
|
||||
// Invalidate classname spec since the test manifest will now pull out new subclasses for each internal class
|
||||
// (e.g. Member will now have various subclasses of DataObjects that implement TestOnly)
|
||||
DataObject::reset();
|
||||
|
||||
// Set dummy controller;
|
||||
$controller = Controller::create();
|
||||
$controller->setRequest($request);
|
||||
$controller->pushCurrent();
|
||||
$controller->doInit();
|
||||
}, true);
|
||||
|
||||
// Register all paths
|
||||
foreach (ModuleLoader::inst()->getManifest()->getModules() as $module) {
|
||||
$container->setParameter('paths.modules.'.$module->getShortName(), $module->getPath());
|
||||
@ -41,8 +67,6 @@ class CoreInitializationPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
unset($_GET['flush']);
|
||||
|
||||
// Remove the error handler so that PHPUnit can add its own
|
||||
restore_error_handler();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ use SilverStripe\Dev\FixtureBlueprint;
|
||||
use SilverStripe\Dev\FixtureFactory;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\YamlFixture;
|
||||
use SilverStripe\ORM\Connect\TempDatabase;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
@ -46,6 +47,13 @@ class FixtureContext implements Context
|
||||
*/
|
||||
protected $filesPath;
|
||||
|
||||
/**
|
||||
* Temp database helper
|
||||
*
|
||||
* @var TempDatabase
|
||||
*/
|
||||
protected $tempDatabase;
|
||||
|
||||
/**
|
||||
* @var String Tracks all files and folders created from fixtures, for later cleanup.
|
||||
*/
|
||||
@ -66,6 +74,7 @@ class FixtureContext implements Context
|
||||
throw new InvalidArgumentException("filesPath is required");
|
||||
}
|
||||
$this->setFilesPath($filesPath);
|
||||
$this->setTempDatabase(new TempDatabase());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,6 +134,24 @@ class FixtureContext implements Context
|
||||
return $this->filesPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TempDatabase
|
||||
*/
|
||||
public function getTempDatabase()
|
||||
{
|
||||
return $this->tempDatabase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TempDatabase $database
|
||||
* @return $this
|
||||
*/
|
||||
public function setTempDatabase(TempDatabase $database)
|
||||
{
|
||||
$this->tempDatabase = $database;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @BeforeScenario @database-defaults
|
||||
*
|
||||
@ -132,7 +159,7 @@ class FixtureContext implements Context
|
||||
*/
|
||||
public function beforeDatabaseDefaults(BeforeScenarioScope $event)
|
||||
{
|
||||
SapphireTest::empty_temp_db();
|
||||
$this->getTempDatabase()->clearAllData();
|
||||
DB::get_conn()->quiet();
|
||||
$dataClasses = ClassInfo::subclassesFor(DataObject::class);
|
||||
array_shift($dataClasses);
|
||||
@ -147,7 +174,7 @@ class FixtureContext implements Context
|
||||
*/
|
||||
public function afterResetDatabase(AfterScenarioScope $event)
|
||||
{
|
||||
SapphireTest::empty_temp_db();
|
||||
$this->getTempDatabase()->clearAllData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,13 +65,6 @@ class SilverStripeAwareInitializer implements ContextInitializer
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
file_put_contents('php://stdout', 'Bootstrapping' . PHP_EOL);
|
||||
|
||||
SapphireTest::start();
|
||||
|
||||
// Remove the error handler so that PHPUnit can add its own
|
||||
restore_error_handler();
|
||||
|
||||
file_put_contents('php://stdout', "Creating test session environment" . PHP_EOL);
|
||||
|
||||
$testEnv = TestSessionEnvironment::singleton();
|
||||
|
Loading…
Reference in New Issue
Block a user