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 diff --git a/composer.json b/composer.json index f9843dc..0503fd3 100644 --- a/composer.json +++ b/composer.json @@ -9,16 +9,16 @@ { "name": "Konstantin Kudryashov", "email": "ever.zet@gmail.com" + }, + { + "name": "Michael Kubovic", + "email": "michael.kubovic@gmail.com" } ], "require": { "php": ">=5.3.2", - "behat/behat": "~2.5" - }, - - "suggest": { - "behat/mink-wunit-driver": "to register the MinkWUnitDriver with MinkExtension" + "behat/behat": "^3.2" }, "autoload": { @@ -27,7 +27,7 @@ "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } } } diff --git a/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php b/src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php index 6bf0d0d..37179a1 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; @@ -41,25 +41,17 @@ public function __construct($frameworkScript, $configScript, $webApplicationFact $this->yii = $webApplicationFactory::createWebApplication($configScript); } - /** - * Checks if initializer supports provided context. - * - * @param ContextInterface $context - * - * @return Boolean - */ - public function supports(ContextInterface $context) - { - return $context instanceof YiiAwareContextInterface; - } - /** * Initializes provided context. * * @param ContextInterface $context */ - public function initialize(ContextInterface $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 diff --git a/src/Behat/YiiExtension/Extension.php b/src/Behat/YiiExtension/ServiceContainer/YiiExtension.php similarity index 56% rename from src/Behat/YiiExtension/Extension.php rename to src/Behat/YiiExtension/ServiceContainer/YiiExtension.php index 6677671..b027cb3 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,25 @@ * * @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'); + $basePath = $container->getParameter('paths.base'); if (!isset($config['framework_script'])) { throw new \InvalidArgumentException( @@ -46,7 +51,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,19 +61,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']); - - 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'); - } + $container->setParameter('yii_extension.config_script', $config['config_script']); } /** @@ -76,13 +69,8 @@ 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); - return (null === $filtered) ? $v : $filtered; - }; - $builder-> children()-> scalarNode('framework_script')-> @@ -91,13 +79,10 @@ public function getConfig(ArrayNodeDefinition $builder) scalarNode('config_script')-> isRequired()-> end()-> - booleanNode('mink_driver')-> - beforeNormalization()-> - ifString()->then($boolFilter)-> - end()-> - defaultFalse()-> - end()-> end() ; } + + public function initialize(ExtensionManager $extensionManager) {} + public function process(ContainerBuilder $container) {} } 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 - - - - - - - - - - - - - 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% +