WIP Behat 3 upgrade

This commit is contained in:
Ingo Schommer 2014-08-03 13:50:52 +12:00
parent 88065af39e
commit bba86f060e
9 changed files with 73 additions and 63 deletions

View File

@ -72,7 +72,7 @@ class InitProcessor extends BaseProcessor
throw new \InvalidArgumentException('Please specify a module name (e.g. "@mymodule")'); throw new \InvalidArgumentException('Please specify a module name (e.g. "@mymodule")');
} }
// Can't use 'behat.paths.base' since that's locked at this point to base folder (not module) // Can't use 'paths.base' since that's locked at this point to base folder (not module)
$pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix'); $pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix');
$currentModuleName = null; $currentModuleName = null;
$modules = \SS_ClassLoader::instance()->getManifest()->getModules(); $modules = \SS_ClassLoader::instance()->getManifest()->getModules();
@ -101,7 +101,7 @@ class InitProcessor extends BaseProcessor
$namespace .= '\\' . $this->container->getParameter('behat.silverstripe_extension.context.namespace_suffix'); $namespace .= '\\' . $this->container->getParameter('behat.silverstripe_extension.context.namespace_suffix');
$featuresPath = rtrim($currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix,DIRECTORY_SEPARATOR); $featuresPath = rtrim($currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix,DIRECTORY_SEPARATOR);
$basePath = $this->container->getParameter('behat.paths.base').DIRECTORY_SEPARATOR; $basePath = $this->container->getParameter('paths.base').DIRECTORY_SEPARATOR;
$bootstrapPath = $featuresPath.DIRECTORY_SEPARATOR.'bootstrap'; $bootstrapPath = $featuresPath.DIRECTORY_SEPARATOR.'bootstrap';
$contextPath = $bootstrapPath.DIRECTORY_SEPARATOR.'Context'; $contextPath = $bootstrapPath.DIRECTORY_SEPARATOR.'Context';
@ -118,8 +118,7 @@ class InitProcessor extends BaseProcessor
if (!is_dir($contextPath)) { if (!is_dir($contextPath)) {
mkdir($contextPath, 0777, true); mkdir($contextPath, 0777, true);
$className = $this->container->getParameter('context.class');
$className = $this->container->getParameter('behat.context.class');
file_put_contents( file_put_contents(
$contextPath . DIRECTORY_SEPARATOR . $className . '.php', $contextPath . DIRECTORY_SEPARATOR . $className . '.php',
strtr($this->getFeatureContextSkelet(), array( strtr($this->getFeatureContextSkelet(), array(

View File

@ -55,7 +55,7 @@ class LocatorProcessor extends BaseProcessor
{ {
$featuresPath = $input->getArgument('features'); $featuresPath = $input->getArgument('features');
// Can't use 'behat.paths.base' since that's locked at this point to base folder (not module) // Can't use 'paths.base' since that's locked at this point to base folder (not module)
$pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix'); $pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix');
$currentModuleName = null; $currentModuleName = null;

View File

@ -5,7 +5,7 @@ namespace SilverStripe\BehatExtension\Context;
use Behat\Behat\Context\ClosuredContextInterface, use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface, Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext, Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step, Behat\Behat\Definition\Call,
Behat\Behat\Event\StepEvent, Behat\Behat\Event\StepEvent,
Behat\Behat\Event\ScenarioEvent, Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Exception\PendingException; Behat\Behat\Exception\PendingException;
@ -404,7 +404,7 @@ JS;
$this->getSession()->executeScript($js); $this->getSession()->executeScript($js);
$this->getSession()->wait(1000); $this->getSession()->wait(1000);
return new Step\Given(sprintf('I attach the file "%s" to "%s"', $path, $field)); return new Call\Given(sprintf('I attach the file "%s" to "%s"', $path, $field));
} }
/** /**

View File

@ -2,8 +2,8 @@
namespace SilverStripe\BehatExtension\Context\Initializer; namespace SilverStripe\BehatExtension\Context\Initializer;
use Behat\Behat\Context\Initializer\InitializerInterface, use Behat\Behat\Context\Initializer\ContextInitializer,
Behat\Behat\Context\ContextInterface; Behat\Behat\Context\Context;
use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface; use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface;
@ -22,7 +22,7 @@ use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface;
* *
* @author Michał Ochman <ochman.d.michal@gmail.com> * @author Michał Ochman <ochman.d.michal@gmail.com>
*/ */
class SilverStripeAwareInitializer implements InitializerInterface class SilverStripeAwareInitializer implements ContextInitializer
{ {
private $databaseName; private $databaseName;
@ -109,7 +109,7 @@ class SilverStripeAwareInitializer implements InitializerInterface
* *
* @param ContextInterface $context * @param ContextInterface $context
*/ */
public function initialize(ContextInterface $context) public function initializeContext(Context $context)
{ {
$context->setDatabase($this->databaseName); $context->setDatabase($this->databaseName);
$context->setAjaxSteps($this->ajaxSteps); $context->setAjaxSteps($this->ajaxSteps);

View File

@ -5,7 +5,7 @@ namespace SilverStripe\BehatExtension\Context;
use Behat\Behat\Context\ClosuredContextInterface, use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface, Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext, Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step, Behat\Behat\Definition\Call,
Behat\Behat\Exception\PendingException; Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode, use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode; Behat\Gherkin\Node\TableNode;
@ -106,7 +106,7 @@ class LoginContext extends BehatContext
$this->cache_generatedMembers[$permCode] = $member; $this->cache_generatedMembers[$permCode] = $member;
} }
return new Step\Given(sprintf('I log in with "%s" and "%s"', "$permCode@example.org", 'secret')); return new Call\Given(sprintf('I log in with "%s" and "%s"', "$permCode@example.org", 'secret'));
} }
/** /**

View File

@ -2,7 +2,7 @@
namespace SilverStripe\BehatExtension\Context; namespace SilverStripe\BehatExtension\Context;
use Behat\Behat\Context\Step, use Behat\Behat\Definition\Call,
Behat\Behat\Event\FeatureEvent, Behat\Behat\Event\FeatureEvent,
Behat\Behat\Event\ScenarioEvent, Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Event\SuiteEvent; Behat\Behat\Event\SuiteEvent;
@ -335,7 +335,7 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
$this->getSession()->getDriver()->getClient()->followRedirects(false); $this->getSession()->getDriver()->getClient()->followRedirects(false);
} }
return new Step\Given($step); return new Call\Given($step);
} }
/** /**

View File

@ -7,7 +7,8 @@ use Symfony\Component\Config\FileLocator,
Symfony\Component\DependencyInjection\Loader\YamlFileLoader, Symfony\Component\DependencyInjection\Loader\YamlFileLoader,
Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Behat\Behat\Extension\ExtensionInterface; use Behat\Testwork\ServiceContainer\ExtensionManager;
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
/* /*
* This file is part of the SilverStripe\BehatExtension * This file is part of the SilverStripe\BehatExtension
@ -26,12 +27,28 @@ use Behat\Behat\Extension\ExtensionInterface;
class Extension implements ExtensionInterface class Extension implements ExtensionInterface
{ {
/** /**
* Loads a specific configuration. * Extension configuration ID.
* */
* @param array $config Extension configuration hash (from behat.yml) const SILVERSTRIPE_ID = 'silverstripe_extension';
* @param ContainerBuilder $container ContainerBuilder instance
/**
* {@inheritDoc}
*/
public function getConfigKey() {
return self::SILVERSTRIPE_ID;
}
/**
* {@inheritDoc}
*/
public function initialize(ExtensionManager $extensionManager) {
}
/**
* {@inheritDoc}
*/ */
public function load(array $config, ContainerBuilder $container) public function load(ContainerBuilder $container, array $config)
{ {
if (!isset($config['framework_path'])) { if (!isset($config['framework_path'])) {
throw new \InvalidArgumentException('Specify `framework_path` parameter for silverstripe_extension'); throw new \InvalidArgumentException('Specify `framework_path` parameter for silverstripe_extension');
@ -40,7 +57,7 @@ class Extension implements ExtensionInterface
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services')); $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services'));
$loader->load('silverstripe.yml'); $loader->load('silverstripe.yml');
$behatBasePath = $container->getParameter('behat.paths.base'); $behatBasePath = $container->getParameter('paths.base');
$config['framework_path'] = realpath(sprintf('%s%s%s', $config['framework_path'] = realpath(sprintf('%s%s%s',
rtrim($behatBasePath, DIRECTORY_SEPARATOR), rtrim($behatBasePath, DIRECTORY_SEPARATOR),
DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
@ -64,21 +81,15 @@ class Extension implements ExtensionInterface
} }
/** /**
* @return array * {@inheritDoc}
*/ */
public function getCompilerPasses() public function process(ContainerBuilder $container)
{ {
return array( $corePass = new Compiler\CoreInitializationPass();
new Compiler\CoreInitializationPass() $corePass->process($container);
);
} }
/** public function configure(ArrayNodeDefinition $builder)
* Setups configuration for current extension.
*
* @param ArrayNodeDefinition $builder
*/
function getConfig(ArrayNodeDefinition $builder)
{ {
$builder-> $builder->
children()-> children()->

View File

@ -6,7 +6,7 @@ namespace SilverStripe\BehatExtension;
* Subclass the main extension in order to get a say in the config compilation. * Subclass the main extension in order to get a say in the config compilation.
* We need to intercept setting the base_url to auto-detect it from SilverStripe configuration. * We need to intercept setting the base_url to auto-detect it from SilverStripe configuration.
*/ */
class MinkExtension extends \Behat\MinkExtension\Extension class MinkExtension extends \Behat\MinkExtension\ServiceContainer\MinkExtension
{ {
public function getCompilerPasses() public function getCompilerPasses()

View File

@ -1,36 +1,36 @@
parameters: parameters:
behat.silverstripe_extension.context.initializer.class: SilverStripe\BehatExtension\Context\Initializer\SilverStripeAwareInitializer silverstripe_extension.context.initializer.class: SilverStripe\BehatExtension\Context\Initializer\SilverStripeAwareInitializer
behat.silverstripe_extension.context.class_guesser.class: SilverStripe\BehatExtension\Context\ClassGuesser\ModuleContextClassGuesser silverstripe_extension.context.class_guesser.class: SilverStripe\BehatExtension\Context\ClassGuesser\ModuleContextClassGuesser
behat.console.processor.locator.class: SilverStripe\BehatExtension\Console\Processor\LocatorProcessor console.processor.locator.class: SilverStripe\BehatExtension\Console\Processor\LocatorProcessor
behat.console.processor.init.class: SilverStripe\BehatExtension\Console\Processor\InitProcessor console.processor.init.class: SilverStripe\BehatExtension\Console\Processor\InitProcessor
behat.silverstripe_extension.context.namespace_suffix: Test\Behaviour silverstripe_extension.context.namespace_suffix: Test\Behaviour
behat.silverstripe_extension.framework_path: framework silverstripe_extension.framework_path: framework
behat.silverstripe_extension.ajax_steps: ~ silverstripe_extension.ajax_steps: ~
behat.silverstripe_extension.ajax_timeout: ~ silverstripe_extension.ajax_timeout: ~
behat.silverstripe_extension.admin_url: ~ silverstripe_extension.admin_url: ~
behat.silverstripe_extension.login_url: ~ silverstripe_extension.login_url: ~
behat.silverstripe_extension.screenshot_path: ~ silverstripe_extension.screenshot_path: ~
behat.silverstripe_extension.module: silverstripe_extension.module:
behat.silverstripe_extension.region_map: ~ silverstripe_extension.region_map: ~
behat.silverstripe_extension.context.path_suffix: tests/behat/features/ silverstripe_extension.context.path_suffix: tests/behat/features/
services: services:
behat.silverstripe_extension.context.initializer: silverstripe_extension.context.initializer:
class: %behat.silverstripe_extension.context.initializer.class% class: %silverstripe_extension.context.initializer.class%
arguments: arguments:
- %behat.silverstripe_extension.framework_path% - %silverstripe_extension.framework_path%
calls: calls:
- [setAjaxSteps, [%behat.silverstripe_extension.ajax_steps%]] - [setAjaxSteps, [%silverstripe_extension.ajax_steps%]]
- [setAjaxTimeout, [%behat.silverstripe_extension.ajax_timeout%]] - [setAjaxTimeout, [%silverstripe_extension.ajax_timeout%]]
- [setAdminUrl, [%behat.silverstripe_extension.admin_url%]] - [setAdminUrl, [%silverstripe_extension.admin_url%]]
- [setLoginUrl, [%behat.silverstripe_extension.login_url%]] - [setLoginUrl, [%silverstripe_extension.login_url%]]
- [setScreenshotPath, [%behat.silverstripe_extension.screenshot_path%]] - [setScreenshotPath, [%silverstripe_extension.screenshot_path%]]
- [setRegionMap, [%behat.silverstripe_extension.region_map%]] - [setRegionMap, [%silverstripe_extension.region_map%]]
tags: tags:
- { name: behat.context.initializer } - { name: context.initializer }
behat.silverstripe_extension.context.class_guesser: silverstripe_extension.context.class_guesser:
class: %behat.silverstripe_extension.context.class_guesser.class% class: %silverstripe_extension.context.class_guesser.class%
arguments: arguments:
- %behat.silverstripe_extension.context.namespace_suffix% - %silverstripe_extension.context.namespace_suffix%
- %behat.context.class% - FeatureContext
tags: tags:
- { name: behat.context.class_guesser, priority: 10 } - { name: silverstripe_extension.context.class_guesser.class, priority: 10 }