NEW: Add bootstrap_file extension parameter.

The bootstrap_file parameter specifies a PHP file that will be included
between Constants.php (which is included by the composer autoloader)
and Core.php (which is included by SilverStripeAwareInitializer).

The goal of this setting is to provide a bit more flexibility about how
behat test environments are set up. It’s the logical companion of
PHPUnit’s bootstrap property.
This commit is contained in:
Sam Minnee 2016-09-13 18:03:12 +12:00
parent c9783741ca
commit 2c4eb2050d
4 changed files with 21 additions and 6 deletions

View File

@ -31,8 +31,8 @@
"symfony/translation": "~2.0",
"symfony/yaml": "~2.0",
"symfony/finder": "~2.0",
"silverstripe/testsession": "*",
"silverstripe/framework": "^4.0.0"
"silverstripe/testsession": "^2.0.0-alpha2",
"silverstripe/framework": "^4.0.0-alpha2"
},
"autoload": {

View File

@ -57,14 +57,19 @@ class SilverStripeAwareInitializer implements InitializerInterface
*/
protected $testSessionEnvironment;
/**
* @var string PHP file to included before loading Core.php
*/
protected $bootstrapFile;
/**
* Initializes initializer.
*
* @param string $frameworkPath
*/
public function __construct($frameworkPath)
public function __construct($frameworkPath, $bootstrapFile = null)
{
$this->bootstrap($frameworkPath);
$this->bootstrap($frameworkPath, $bootstrapFile);
file_put_contents('php://stdout', "Creating test session environment" . PHP_EOL);
@ -187,10 +192,15 @@ class SilverStripeAwareInitializer implements InitializerInterface
/**
* @param string $frameworkPath Absolute path to 'framework' module
*/
protected function bootstrap($frameworkPath)
protected function bootstrap($frameworkPath, $bootstrapFile = null)
{
file_put_contents('php://stdout', 'Bootstrapping' . PHP_EOL);
// Require a bootstrap file, if provided
if ($bootstrapFile) {
require_once($bootstrapFile);
}
// Connect to database and build manifest
$_GET['flush'] = 1;
require_once $frameworkPath . '/Core/Core.php';

View File

@ -62,6 +62,7 @@ class Extension implements ExtensionInterface
if (isset($config['region_map'])) {
$container->setParameter('behat.silverstripe_extension.region_map', $config['region_map']);
}
$container->setParameter('behat.silverstripe_extension.bootstrap_file', $config['bootstrap_file']);
}
/**
@ -102,6 +103,9 @@ class Extension implements ExtensionInterface
scalarNode('ajax_timeout')->
defaultValue(5000)->
end()->
scalarNode('bootstrap_file')->
defaultNull()->
end()->
arrayNode('ajax_steps')->
defaultValue(array(
'go to',

View File

@ -18,6 +18,7 @@ services:
class: %behat.silverstripe_extension.context.initializer.class%
arguments:
- %behat.silverstripe_extension.framework_path%
- %behat.silverstripe_extension.bootstrap_file%
calls:
- [setAjaxSteps, [%behat.silverstripe_extension.ajax_steps%]]
- [setAjaxTimeout, [%behat.silverstripe_extension.ajax_timeout%]]
@ -33,4 +34,4 @@ services:
- %behat.silverstripe_extension.context.namespace_suffix%
- %behat.context.class%
tags:
- { name: behat.context.class_guesser, priority: 10 }
- { name: behat.context.class_guesser, priority: 10 }