From a730f75231ccb83c842fc99913dc52ab4483dcca Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Tue, 8 Nov 2016 13:52:46 +0100 Subject: [PATCH 1/9] bumped behat version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f9843dc..0c2b49f 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "php": ">=5.3.2", - "behat/behat": "~2.5" + "behat/behat": "^3.2" }, "suggest": { From a1c85b037655836ab22419d6ba0e5131aa346fd1 Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Tue, 8 Nov 2016 14:43:08 +0100 Subject: [PATCH 2/9] update context initialization for behat 3 --- .../Initializer/YiiAwareInitializer.php | 10 +++--- .../YiiExtension.php} | 34 +++++++++++++------ src/Behat/YiiExtension/services/yii.xml | 18 +++++----- 3 files changed, 37 insertions(+), 25 deletions(-) rename src/Behat/YiiExtension/{Extension.php => ServiceContainer/YiiExtension.php} (75%) diff --git a/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php b/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php index 6bf0d0d..02ee984 100644 --- a/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php +++ b/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php @@ -11,8 +11,8 @@ namespace Behat\YiiExtension\Context\Initializer; -use Behat\Behat\Context\Initializer\InitializerInterface; -use Behat\Behat\Context\ContextInterface; +use Behat\Behat\Context\Context; +use Behat\Behat\Context\Initializer\ContextInitializer; use Behat\YiiExtension\Context\YiiAwareContextInterface; /** @@ -21,7 +21,7 @@ * * @author Konstantin Kudryashov */ -class YiiAwareInitializer implements InitializerInterface +class YiiAwareInitializer implements ContextInitializer { private $yii; @@ -48,7 +48,7 @@ public function __construct($frameworkScript, $configScript, $webApplicationFact * * @return Boolean */ - public function supports(ContextInterface $context) + public function supportsContext(Context $context) { return $context instanceof YiiAwareContextInterface; } @@ -58,7 +58,7 @@ public function supports(ContextInterface $context) * * @param ContextInterface $context */ - public function initialize(ContextInterface $context) + public function initializeContext(Context $context) { $context->setYiiWebApplication($this->yii); } diff --git a/src/Behat/YiiExtension/Extension.php b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php similarity index 75% rename from src/Behat/YiiExtension/Extension.php rename to src/Behat/YiiExtension/ServiceContainer/YiiExtension.php index 6677671..38ecb7e 100644 --- a/src/Behat/YiiExtension/Extension.php +++ b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php @@ -9,11 +9,12 @@ * with this source code in the file LICENSE. */ -namespace Behat\YiiExtension; +namespace Behat\YiiExtension\ServiceContainer; -use Behat\Behat\Extension\Extension as BaseExtension; -use Symfony\Component\Config\FileLocator; +use Behat\Testwork\ServiceContainer\Extension; +use Behat\Testwork\ServiceContainer\ExtensionManager; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; @@ -22,21 +23,29 @@ * * @author Konstantin Kudryashov */ -class Extension extends BaseExtension +class YiiExtension implements Extension { + public function getConfigKey() + { + return 'yii_extension'; + } + /** * Loads a specific configuration. * * @param array $config Extension configuration hash (from behat.yml) * @param ContainerBuilder $container ContainerBuilder instance */ - public function load(array $config, ContainerBuilder $container) + public function load(ContainerBuilder $container, array $config) { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/services')); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../services')); $loader->load('yii.xml'); - $basePath = $container->getParameter('behat.paths.base'); - $extensions = $container->getParameter('behat.extension.classes'); + // echo json_encode($container->getParameterBag()->all()); exit; + + $basePath = $container->getParameter('paths.base'); + + $extensions = $container->getParameter('extensions'); if (!isset($config['framework_script'])) { throw new \InvalidArgumentException( @@ -46,7 +55,7 @@ public function load(array $config, ContainerBuilder $container) if (file_exists($cfg = $basePath.DIRECTORY_SEPARATOR.$config['framework_script'])) { $config['framework_script'] = $cfg; } - $container->setParameter('behat.yii_extension.framework_script', $config['framework_script']); + $container->setParameter('yii_extension.framework_script', $config['framework_script']); if (!isset($config['config_script'])) { throw new \InvalidArgumentException( @@ -56,7 +65,7 @@ public function load(array $config, ContainerBuilder $container) if (file_exists($cfg = $basePath.DIRECTORY_SEPARATOR.$config['config_script'])) { $config['config_script'] = $cfg; } - $container->setParameter('behat.yii_extension.config_script', $config['config_script']); + $container->setParameter('yii_extension.config_script', $config['config_script']); if ($config['mink_driver']) { if (!class_exists('Behat\\Mink\\Driver\\WUnitDriver')) { @@ -76,7 +85,7 @@ public function load(array $config, ContainerBuilder $container) * * @param ArrayNodeDefinition $builder */ - public function getConfig(ArrayNodeDefinition $builder) + public function configure(ArrayNodeDefinition $builder) { $boolFilter = function ($v) { $filtered = filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); @@ -100,4 +109,7 @@ public function getConfig(ArrayNodeDefinition $builder) end() ; } + + public function initialize(ExtensionManager $extensionManager) {} + public function process(ContainerBuilder $container) {} } diff --git a/src/Behat/YiiExtension/services/yii.xml b/src/Behat/YiiExtension/services/yii.xml index a5007ae..3f1a9f6 100644 --- a/src/Behat/YiiExtension/services/yii.xml +++ b/src/Behat/YiiExtension/services/yii.xml @@ -4,18 +4,18 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Behat\YiiExtension\Context\Initializer\YiiAwareInitializer - - - \Yii + Behat\YiiExtension\Context\Initializer\YiiAwareInitializer + + + \Yii - - %behat.yii_extension.framework_script% - %behat.yii_extension.config_script% - %behat.yii_extension.web_application_factory% - + + %yii_extension.framework_script% + %yii_extension.config_script% + %yii_extension.web_application_factory% + From 6106bf469a619a1b50c6e6c0d55a1676633c2378 Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Tue, 8 Nov 2016 14:59:03 +0100 Subject: [PATCH 3/9] standalone yii context created --- .../Initializer/YiiAwareInitializer.php | 16 +++------- .../Context/YiiAwareContextInterface.php | 4 ++- src/Behat/YiiExtension/Context/YiiContext.php | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 src/Behat/YiiExtension/Context/YiiContext.php diff --git a/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php b/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php index 02ee984..37179a1 100644 --- a/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php +++ b/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php @@ -41,18 +41,6 @@ public function __construct($frameworkScript, $configScript, $webApplicationFact $this->yii = $webApplicationFactory::createWebApplication($configScript); } - /** - * Checks if initializer supports provided context. - * - * @param ContextInterface $context - * - * @return Boolean - */ - public function supportsContext(Context $context) - { - return $context instanceof YiiAwareContextInterface; - } - /** * Initializes provided context. * @@ -60,6 +48,10 @@ public function supportsContext(Context $context) */ public function initializeContext(Context $context) { + if (!$context instanceof YiiAwareContextInterface) { + return; + } + $context->setYiiWebApplication($this->yii); } } diff --git a/src/Behat/YiiExtension/Context/YiiAwareContextInterface.php b/src/Behat/YiiExtension/Context/YiiAwareContextInterface.php index beaae18..369b710 100644 --- a/src/Behat/YiiExtension/Context/YiiAwareContextInterface.php +++ b/src/Behat/YiiExtension/Context/YiiAwareContextInterface.php @@ -11,12 +11,14 @@ namespace Behat\YiiExtension\Context; +use Behat\Behat\Context\Context; + /** * Yii aware interface for contexts. * * @author Konstantin Kudryashov */ -interface YiiAwareContextInterface +interface YiiAwareContextInterface extends Context { /** * Sets Yii web application instance. diff --git a/src/Behat/YiiExtension/Context/YiiContext.php b/src/Behat/YiiExtension/Context/YiiContext.php new file mode 100644 index 0000000..43a746e --- /dev/null +++ b/src/Behat/YiiExtension/Context/YiiContext.php @@ -0,0 +1,30 @@ +yii = $yii; + } + + /** + * Returns Mink instance. + * + * @return Mink + */ + public function getYii() + { + if (null === $this->yii) { + throw new \RuntimeException( + 'Yii instance has not been set on Yii context class. ' . + 'Have you enabled the Yii Extension?' + ); + } + + return $this->yii; + } +} \ No newline at end of file From 4174ccc10dcd2703dd580e4389f72e6e7c8faf33 Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Thu, 1 Dec 2016 13:23:56 +0100 Subject: [PATCH 4/9] version bump, authorship --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0c2b49f..419d724 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,10 @@ { "name": "Konstantin Kudryashov", "email": "ever.zet@gmail.com" + }, + { + "name": "Michael Kubovic", + "email": "michael.kubovic@gmail.com" } ], @@ -27,7 +31,7 @@ "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } } } From 411527985b302c43b8d12df6307027aac0958410 Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Thu, 1 Dec 2016 13:24:41 +0100 Subject: [PATCH 5/9] removed leftover --- src/Behat/YiiExtension/ServiceContainer/YiiExtension.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php index 38ecb7e..1ad6e19 100644 --- a/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php +++ b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php @@ -41,8 +41,6 @@ public function load(ContainerBuilder $container, array $config) $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../services')); $loader->load('yii.xml'); - // echo json_encode($container->getParameterBag()->all()); exit; - $basePath = $container->getParameter('paths.base'); $extensions = $container->getParameter('extensions'); From 51651c4b5ce15d9fb514a00191cd93d1583579c6 Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Thu, 1 Dec 2016 13:25:04 +0100 Subject: [PATCH 6/9] wunit discontinued --- composer.json | 4 ---- .../ServiceContainer/YiiExtension.php | 14 ------------- .../YiiExtension/services/sessions/wunit.xml | 21 ------------------- 3 files changed, 39 deletions(-) delete mode 100644 src/Behat/YiiExtension/services/sessions/wunit.xml diff --git a/composer.json b/composer.json index 419d724..0503fd3 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,6 @@ "behat/behat": "^3.2" }, - "suggest": { - "behat/mink-wunit-driver": "to register the MinkWUnitDriver with MinkExtension" - }, - "autoload": { "psr-0": { "Behat\\YiiExtension": "src/" } }, diff --git a/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php index 1ad6e19..2c7a55d 100644 --- a/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php +++ b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php @@ -43,8 +43,6 @@ public function load(ContainerBuilder $container, array $config) $basePath = $container->getParameter('paths.base'); - $extensions = $container->getParameter('extensions'); - if (!isset($config['framework_script'])) { throw new \InvalidArgumentException( 'Specify `framework_script` parameter for yii_extension.' @@ -64,18 +62,6 @@ public function load(ContainerBuilder $container, array $config) $config['config_script'] = $cfg; } $container->setParameter('yii_extension.config_script', $config['config_script']); - - if ($config['mink_driver']) { - if (!class_exists('Behat\\Mink\\Driver\\WUnitDriver')) { - throw new \RuntimeException( - 'Install WUnitDriver in order to activate wunit session.' - ); - } - - $loader->load('sessions/wunit.xml'); - } elseif (in_array('Behat\\MinkExtension\\Extension', $extensions) && class_exists('Behat\\Mink\\Driver\\WUnitDriver')) { - $loader->load('sessions/wunit.xml'); - } } /** diff --git a/src/Behat/YiiExtension/services/sessions/wunit.xml b/src/Behat/YiiExtension/services/sessions/wunit.xml deleted file mode 100644 index 6456aa3..0000000 --- a/src/Behat/YiiExtension/services/sessions/wunit.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - Behat\Mink\Driver\WUnitDriver - \WUnit\WUnit - - - - - - - - - - - - - From b3b6dd3c5262f2c41f2f427e6a9fe81ae32570ea Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Thu, 1 Dec 2016 13:52:45 +0100 Subject: [PATCH 7/9] removed wunit-related configuration --- src/Behat/YiiExtension/ServiceContainer/YiiExtension.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php index 2c7a55d..918abaf 100644 --- a/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php +++ b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php @@ -84,12 +84,6 @@ public function configure(ArrayNodeDefinition $builder) scalarNode('config_script')-> isRequired()-> end()-> - booleanNode('mink_driver')-> - beforeNormalization()-> - ifString()->then($boolFilter)-> - end()-> - defaultFalse()-> - end()-> end() ; } From 0e80313ff2c4aca85650f529e2eb6ac9b90cb87f Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Thu, 1 Dec 2016 13:52:50 +0100 Subject: [PATCH 8/9] updated readme --- README.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a7df6d1..ce29e44 100644 --- a/README.md +++ b/README.md @@ -4,26 +4,26 @@ YiiExtension Provides integration layer for the [Yii framework](http://www.yiiframework.com/): * Additional services for Behat (`Yii`, `Sessions`, `Drivers`) -* `Behat\MinkExtension\Context\YiiAwareInterface` which provides `CWebApplication` - instance for your contexts or subcontexts -* Additional `wunit` session (sets as default) for Mink (if MinkExtension is installed) - for functional testing without Selenium through [wunit](http://www.yiiframework.com/extension/wunit) +* `Behat\YiiExtension\Context\YiiAwareContextInterface` which provides `CWebApplication` + instance for your contexts + +between Behat 3.2+ and Yii 1.0+. -between Behat 2.5+ and Yii. Behat configuration ------------------- ```yml default: - extensions: - Behat\MinkExtension\Extension: - default_session: wunit + suites: + default: + contexts: + - Behat\YiiExtension\Context\YiiContext - Behat\YiiExtension\Extension: + extensions: + Behat\YiiExtension: framework_script: ../../framework/yii.php config_script: ../config/test.php - mink_driver: true ``` Installation @@ -32,15 +32,14 @@ Installation ```json { "require-dev": { - "behat/mink": "~1.5", - "behat/mink-extension": "~1.3", - "behat/yii-extension": "~1.0" + "behat/mink-extension": "^2.2", + "behat/yii-extension": "~2.0" } } ``` ```bash -$ composer update 'behat/mink' 'behat/mink-extension' 'behat/yii-extension' +$ composer update 'behat/mink-extension' 'behat/yii-extension' ``` Copyright From 6080406f08c7567cbd8234facfd9029de6a04e17 Mon Sep 17 00:00:00 2001 From: Michael Kubovic Date: Thu, 1 Dec 2016 13:58:31 +0100 Subject: [PATCH 9/9] removed boolfilter, not used any more --- src/Behat/YiiExtension/ServiceContainer/YiiExtension.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php index 918abaf..b027cb3 100644 --- a/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php +++ b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php @@ -71,11 +71,6 @@ public function load(ContainerBuilder $container, array $config) */ public function configure(ArrayNodeDefinition $builder) { - $boolFilter = function ($v) { - $filtered = filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); - return (null === $filtered) ? $v : $filtered; - }; - $builder-> children()-> scalarNode('framework_script')->