mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Merge pull request #76 from silverstripe-labs/revert-75-disable_create_database
Revert "Allow setting create_temp_database to false to stop temp db crea...
This commit is contained in:
commit
0562d7e8f2
@ -24,13 +24,8 @@ use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface;
|
|||||||
*/
|
*/
|
||||||
class SilverStripeAwareInitializer implements InitializerInterface
|
class SilverStripeAwareInitializer implements InitializerInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
private $databaseName;
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $createTempDatabase;
|
|
||||||
|
|
||||||
protected $databaseName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Array
|
* @var Array
|
||||||
@ -62,36 +57,40 @@ class SilverStripeAwareInitializer implements InitializerInterface
|
|||||||
*/
|
*/
|
||||||
protected $testSessionEnvironment;
|
protected $testSessionEnvironment;
|
||||||
|
|
||||||
protected $frameworkPath;
|
/**
|
||||||
|
* Initializes initializer.
|
||||||
|
*/
|
||||||
|
public function __construct($frameworkPath)
|
||||||
|
{
|
||||||
|
$this->bootstrap($frameworkPath);
|
||||||
|
|
||||||
public function initTestSession() {
|
file_put_contents('php://stdout', "Creating test session environment" . PHP_EOL);
|
||||||
$this->bootstrap($this->frameworkPath);
|
|
||||||
|
|
||||||
if($this->createTempDatabase) {
|
$testEnv = \Injector::inst()->get('TestSessionEnvironment');
|
||||||
file_put_contents('php://stdout', "Creating test session environment" . PHP_EOL);
|
$testEnv->startTestSession(array(
|
||||||
|
'createDatabase' => true
|
||||||
|
));
|
||||||
|
|
||||||
$testEnv = \Injector::inst()->get('TestSessionEnvironment');
|
$state = $testEnv->getState();
|
||||||
$testEnv->startTestSession();
|
|
||||||
|
|
||||||
$state = $testEnv->getState();
|
$this->databaseName = $state->database;
|
||||||
$this->databaseName = $state->database;
|
$this->testSessionEnvironment = $testEnv;
|
||||||
$this->testSessionEnvironment = $testEnv;
|
|
||||||
|
|
||||||
file_put_contents('php://stdout', "Temp Database: $this->databaseName" . PHP_EOL . PHP_EOL);
|
file_put_contents('php://stdout', "Temp Database: $this->databaseName" . PHP_EOL . PHP_EOL);
|
||||||
|
|
||||||
register_shutdown_function(array($this, 'killTestSession'));
|
register_shutdown_function(array($this, '__destruct'));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function killTestSession() {
|
public function __destruct()
|
||||||
file_put_contents('php://stdout', "Killing test session environment...");
|
{
|
||||||
|
file_put_contents('php://stdout', "Killing test session environment...");
|
||||||
|
|
||||||
if($this->testSessionEnvironment) {
|
if($this->testSessionEnvironment) {
|
||||||
$this->testSessionEnvironment->endTestSession();
|
$this->testSessionEnvironment->endTestSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents('php://stdout', " done!" . PHP_EOL);
|
file_put_contents('php://stdout', " done!" . PHP_EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if initializer supports provided context.
|
* Checks if initializer supports provided context.
|
||||||
@ -112,7 +111,6 @@ class SilverStripeAwareInitializer implements InitializerInterface
|
|||||||
*/
|
*/
|
||||||
public function initialize(ContextInterface $context)
|
public function initialize(ContextInterface $context)
|
||||||
{
|
{
|
||||||
$context->setCreateTempDatabase($this->createTempDatabase);
|
|
||||||
$context->setDatabase($this->databaseName);
|
$context->setDatabase($this->databaseName);
|
||||||
$context->setAjaxSteps($this->ajaxSteps);
|
$context->setAjaxSteps($this->ajaxSteps);
|
||||||
$context->setAjaxTimeout($this->ajaxTimeout);
|
$context->setAjaxTimeout($this->ajaxTimeout);
|
||||||
@ -120,18 +118,6 @@ class SilverStripeAwareInitializer implements InitializerInterface
|
|||||||
$context->setRegionMap($this->regionMap);
|
$context->setRegionMap($this->regionMap);
|
||||||
$context->setAdminUrl($this->adminUrl);
|
$context->setAdminUrl($this->adminUrl);
|
||||||
$context->setLoginUrl($this->loginUrl);
|
$context->setLoginUrl($this->loginUrl);
|
||||||
|
|
||||||
$this->initTestSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setFrameworkPath($path)
|
|
||||||
{
|
|
||||||
$this->frameworkPath = $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCreateTempDatabase($bool)
|
|
||||||
{
|
|
||||||
$this->createTempDatabase = $bool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAjaxSteps($ajaxSteps)
|
public function setAjaxSteps($ajaxSteps)
|
||||||
@ -207,4 +193,4 @@ class SilverStripeAwareInitializer implements InitializerInterface
|
|||||||
// Remove the error handler so that PHPUnit can add its own
|
// Remove the error handler so that PHPUnit can add its own
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,9 +27,6 @@ require_once 'vendor/autoload.php';
|
|||||||
*/
|
*/
|
||||||
class SilverStripeContext extends MinkContext implements SilverStripeAwareContextInterface
|
class SilverStripeContext extends MinkContext implements SilverStripeAwareContextInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $createTempDatabase;
|
|
||||||
|
|
||||||
protected $databaseName;
|
protected $databaseName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,10 +76,6 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
|
|||||||
$this->testSessionEnvironment = new \TestSessionEnvironment();
|
$this->testSessionEnvironment = new \TestSessionEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreateTempDatabase($bool) {
|
|
||||||
$this->createTempDatabase = $bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDatabase($databaseName) {
|
public function setDatabase($databaseName) {
|
||||||
$this->databaseName = $databaseName;
|
$this->databaseName = $databaseName;
|
||||||
}
|
}
|
||||||
@ -187,31 +180,29 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
|
|||||||
* @BeforeScenario
|
* @BeforeScenario
|
||||||
*/
|
*/
|
||||||
public function before(ScenarioEvent $event) {
|
public function before(ScenarioEvent $event) {
|
||||||
if($this->createTempDatabase) {
|
if (!isset($this->databaseName)) {
|
||||||
if (!isset($this->databaseName)) {
|
throw new \LogicException(
|
||||||
throw new \LogicException(
|
'Context\'s $databaseName has to be set when implementing SilverStripeAwareContextInterface.'
|
||||||
'Context\'s $databaseName has to be set when implementing SilverStripeAwareContextInterface.'
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$state = $this->getTestSessionState();
|
$state = $this->getTestSessionState();
|
||||||
$this->testSessionEnvironment->startTestSession($state);
|
$this->testSessionEnvironment->startTestSession($state);
|
||||||
|
|
||||||
// Optionally import database
|
// Optionally import database
|
||||||
if(!empty($state['importDatabasePath'])) {
|
if(!empty($state['importDatabasePath'])) {
|
||||||
$this->testSessionEnvironment->importDatabase(
|
$this->testSessionEnvironment->importDatabase(
|
||||||
$state['importDatabasePath'],
|
$state['importDatabasePath'],
|
||||||
!empty($state['requireDefaultRecords']) ? $state['requireDefaultRecords'] : false
|
!empty($state['requireDefaultRecords']) ? $state['requireDefaultRecords'] : false
|
||||||
);
|
);
|
||||||
} else if(!empty($state['requireDefaultRecords']) && $state['requireDefaultRecords']) {
|
} else if(!empty($state['requireDefaultRecords']) && $state['requireDefaultRecords']) {
|
||||||
$this->testSessionEnvironment->requireDefaultRecords();
|
$this->testSessionEnvironment->requireDefaultRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fixtures
|
// Fixtures
|
||||||
$fixtureFile = (!empty($params['fixture'])) ? $params['fixture'] : null;
|
$fixtureFile = (!empty($params['fixture'])) ? $params['fixture'] : null;
|
||||||
if($fixtureFile) {
|
if($fixtureFile) {
|
||||||
$this->testSessionEnvironment->loadFixtureIntoDb($fixtureFile);
|
$this->testSessionEnvironment->loadFixtureIntoDb($fixtureFile);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($screenSize = getenv('BEHAT_SCREEN_SIZE')) {
|
if($screenSize = getenv('BEHAT_SCREEN_SIZE')) {
|
||||||
|
@ -54,7 +54,6 @@ class Extension implements ExtensionInterface
|
|||||||
$container->setParameter('behat.silverstripe_extension.admin_url', $config['admin_url']);
|
$container->setParameter('behat.silverstripe_extension.admin_url', $config['admin_url']);
|
||||||
$container->setParameter('behat.silverstripe_extension.login_url', $config['login_url']);
|
$container->setParameter('behat.silverstripe_extension.login_url', $config['login_url']);
|
||||||
$container->setParameter('behat.silverstripe_extension.screenshot_path', $config['screenshot_path']);
|
$container->setParameter('behat.silverstripe_extension.screenshot_path', $config['screenshot_path']);
|
||||||
$container->setParameter('behat.silverstripe_extension.create_temp_database', $config['create_temp_database']);
|
|
||||||
$container->setParameter('behat.silverstripe_extension.ajax_timeout', $config['ajax_timeout']);
|
$container->setParameter('behat.silverstripe_extension.ajax_timeout', $config['ajax_timeout']);
|
||||||
if (isset($config['ajax_steps'])) {
|
if (isset($config['ajax_steps'])) {
|
||||||
$container->setParameter('behat.silverstripe_extension.ajax_steps', $config['ajax_steps']);
|
$container->setParameter('behat.silverstripe_extension.ajax_steps', $config['ajax_steps']);
|
||||||
@ -83,9 +82,6 @@ class Extension implements ExtensionInterface
|
|||||||
{
|
{
|
||||||
$builder->
|
$builder->
|
||||||
children()->
|
children()->
|
||||||
scalarNode('create_temp_database')->
|
|
||||||
defaultValue(true)->
|
|
||||||
end()->
|
|
||||||
scalarNode('framework_path')->
|
scalarNode('framework_path')->
|
||||||
defaultValue('framework')->
|
defaultValue('framework')->
|
||||||
end()->
|
end()->
|
||||||
|
@ -10,16 +10,15 @@ parameters:
|
|||||||
behat.silverstripe_extension.admin_url: ~
|
behat.silverstripe_extension.admin_url: ~
|
||||||
behat.silverstripe_extension.login_url: ~
|
behat.silverstripe_extension.login_url: ~
|
||||||
behat.silverstripe_extension.screenshot_path: ~
|
behat.silverstripe_extension.screenshot_path: ~
|
||||||
behat.silverstripe_extension.create_temp_database: true
|
|
||||||
behat.silverstripe_extension.module:
|
behat.silverstripe_extension.module:
|
||||||
behat.silverstripe_extension.region_map: ~
|
behat.silverstripe_extension.region_map: ~
|
||||||
behat.silverstripe_extension.context.path_suffix: tests/behat/features/
|
behat.silverstripe_extension.context.path_suffix: tests/behat/features/
|
||||||
services:
|
services:
|
||||||
behat.silverstripe_extension.context.initializer:
|
behat.silverstripe_extension.context.initializer:
|
||||||
class: %behat.silverstripe_extension.context.initializer.class%
|
class: %behat.silverstripe_extension.context.initializer.class%
|
||||||
|
arguments:
|
||||||
|
- %behat.silverstripe_extension.framework_path%
|
||||||
calls:
|
calls:
|
||||||
- [setFrameworkPath, [%behat.silverstripe_extension.framework_path%]]
|
|
||||||
- [setCreateTempDatabase, [%behat.silverstripe_extension.create_temp_database%]]
|
|
||||||
- [setAjaxSteps, [%behat.silverstripe_extension.ajax_steps%]]
|
- [setAjaxSteps, [%behat.silverstripe_extension.ajax_steps%]]
|
||||||
- [setAjaxTimeout, [%behat.silverstripe_extension.ajax_timeout%]]
|
- [setAjaxTimeout, [%behat.silverstripe_extension.ajax_timeout%]]
|
||||||
- [setAdminUrl, [%behat.silverstripe_extension.admin_url%]]
|
- [setAdminUrl, [%behat.silverstripe_extension.admin_url%]]
|
||||||
@ -34,4 +33,4 @@ services:
|
|||||||
- %behat.silverstripe_extension.context.namespace_suffix%
|
- %behat.silverstripe_extension.context.namespace_suffix%
|
||||||
- %behat.context.class%
|
- %behat.context.class%
|
||||||
tags:
|
tags:
|
||||||
- { name: behat.context.class_guesser, priority: 10 }
|
- { name: behat.context.class_guesser, priority: 10 }
|
Loading…
Reference in New Issue
Block a user