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")');
}
// 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');
$currentModuleName = null;
$modules = \SS_ClassLoader::instance()->getManifest()->getModules();
@ -101,7 +101,7 @@ class InitProcessor extends BaseProcessor
$namespace .= '\\' . $this->container->getParameter('behat.silverstripe_extension.context.namespace_suffix');
$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';
$contextPath = $bootstrapPath.DIRECTORY_SEPARATOR.'Context';
@ -118,8 +118,7 @@ class InitProcessor extends BaseProcessor
if (!is_dir($contextPath)) {
mkdir($contextPath, 0777, true);
$className = $this->container->getParameter('behat.context.class');
$className = $this->container->getParameter('context.class');
file_put_contents(
$contextPath . DIRECTORY_SEPARATOR . $className . '.php',
strtr($this->getFeatureContextSkelet(), array(

View File

@ -55,7 +55,7 @@ class LocatorProcessor extends BaseProcessor
{
$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');
$currentModuleName = null;

View File

@ -5,7 +5,7 @@ namespace SilverStripe\BehatExtension\Context;
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step,
Behat\Behat\Definition\Call,
Behat\Behat\Event\StepEvent,
Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Exception\PendingException;
@ -404,7 +404,7 @@ JS;
$this->getSession()->executeScript($js);
$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;
use Behat\Behat\Context\Initializer\InitializerInterface,
Behat\Behat\Context\ContextInterface;
use Behat\Behat\Context\Initializer\ContextInitializer,
Behat\Behat\Context\Context;
use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface;
@ -22,7 +22,7 @@ use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface;
*
* @author Michał Ochman <ochman.d.michal@gmail.com>
*/
class SilverStripeAwareInitializer implements InitializerInterface
class SilverStripeAwareInitializer implements ContextInitializer
{
private $databaseName;
@ -109,7 +109,7 @@ class SilverStripeAwareInitializer implements InitializerInterface
*
* @param ContextInterface $context
*/
public function initialize(ContextInterface $context)
public function initializeContext(Context $context)
{
$context->setDatabase($this->databaseName);
$context->setAjaxSteps($this->ajaxSteps);

View File

@ -5,7 +5,7 @@ namespace SilverStripe\BehatExtension\Context;
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step,
Behat\Behat\Definition\Call,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
@ -106,7 +106,7 @@ class LoginContext extends BehatContext
$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;
use Behat\Behat\Context\Step,
use Behat\Behat\Definition\Call,
Behat\Behat\Event\FeatureEvent,
Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Event\SuiteEvent;
@ -335,7 +335,7 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
$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\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
@ -26,12 +27,28 @@ use Behat\Behat\Extension\ExtensionInterface;
class Extension implements ExtensionInterface
{
/**
* Loads a specific configuration.
*
* @param array $config Extension configuration hash (from behat.yml)
* @param ContainerBuilder $container ContainerBuilder instance
* Extension configuration ID.
*/
public function load(array $config, ContainerBuilder $container)
const SILVERSTRIPE_ID = 'silverstripe_extension';
/**
* {@inheritDoc}
*/
public function getConfigKey() {
return self::SILVERSTRIPE_ID;
}
/**
* {@inheritDoc}
*/
public function initialize(ExtensionManager $extensionManager) {
}
/**
* {@inheritDoc}
*/
public function load(ContainerBuilder $container, array $config)
{
if (!isset($config['framework_path'])) {
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->load('silverstripe.yml');
$behatBasePath = $container->getParameter('behat.paths.base');
$behatBasePath = $container->getParameter('paths.base');
$config['framework_path'] = realpath(sprintf('%s%s%s',
rtrim($behatBasePath, 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(
new Compiler\CoreInitializationPass()
);
$corePass = new Compiler\CoreInitializationPass();
$corePass->process($container);
}
/**
* Setups configuration for current extension.
*
* @param ArrayNodeDefinition $builder
*/
function getConfig(ArrayNodeDefinition $builder)
public function configure(ArrayNodeDefinition $builder)
{
$builder->
children()->

View File

@ -6,7 +6,7 @@ namespace SilverStripe\BehatExtension;
* 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.
*/
class MinkExtension extends \Behat\MinkExtension\Extension
class MinkExtension extends \Behat\MinkExtension\ServiceContainer\MinkExtension
{
public function getCompilerPasses()

View File

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