Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

behat 3 #13

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"require": {
"php": ">=5.3.2",
"behat/behat": "~2.5"
"behat/behat": "^3.2"
},

"suggest": {
Expand Down
24 changes: 8 additions & 16 deletions src/Behat/YiiExtension/Context/Initializer/YiiAwareInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -21,7 +21,7 @@
*
* @author Konstantin Kudryashov <[email protected]>
*/
class YiiAwareInitializer implements InitializerInterface
class YiiAwareInitializer implements ContextInitializer
{
private $yii;

Expand All @@ -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);
}
}
4 changes: 3 additions & 1 deletion src/Behat/YiiExtension/Context/YiiAwareContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

namespace Behat\YiiExtension\Context;

use Behat\Behat\Context\Context;

/**
* Yii aware interface for contexts.
*
* @author Konstantin Kudryashov <[email protected]>
*/
interface YiiAwareContextInterface
interface YiiAwareContextInterface extends Context
{
/**
* Sets Yii web application instance.
Expand Down
30 changes: 30 additions & 0 deletions src/Behat/YiiExtension/Context/YiiContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Behat\YiiExtension\Context;

class YiiContext implements YiiAwareContextInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we don't need this base class. Implementing the setter is easy enough

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep that class. Anybody who wants to integrate this context to his feature contexts should imo use hooks, i.e. BeforeScenario. Having the class ready for integration seems natural.

{
private $yii;

public function setYiiWebApplication(\CWebApplication $yii)
{
$this->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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,21 +23,29 @@
*
* @author Konstantin Kudryashov <[email protected]>
*/
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed


$basePath = $container->getParameter('paths.base');

$extensions = $container->getParameter('extensions');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is used by the WUnitDriver registration, but the way it is done currently is wrong for MinkExtension 2. Registering a session is the wrong way. It should register a driver factory instead (look at the Symfony2Extension for an example)


if (!isset($config['framework_script'])) {
throw new \InvalidArgumentException(
Expand All @@ -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(
Expand All @@ -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')) {
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this bool filter is really weird to me

$filtered = filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
Expand All @@ -100,4 +109,7 @@ public function getConfig(ArrayNodeDefinition $builder)
end()
;
}

public function initialize(ExtensionManager $extensionManager) {}
public function process(ContainerBuilder $container) {}
}
18 changes: 9 additions & 9 deletions src/Behat/YiiExtension/services/yii.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="behat.yii_extension.context.initializer.class">Behat\YiiExtension\Context\Initializer\YiiAwareInitializer</parameter>
<parameter key="behat.yii_extension.framework_script"></parameter>
<parameter key="behat.yii_extension.config_script"></parameter>
<parameter key="behat.yii_extension.web_application_factory">\Yii</parameter>
<parameter key="yii_extension.context.initializer.class">Behat\YiiExtension\Context\Initializer\YiiAwareInitializer</parameter>
<parameter key="yii_extension.framework_script"></parameter>
<parameter key="yii_extension.config_script"></parameter>
<parameter key="yii_extension.web_application_factory">\Yii</parameter>
</parameters>

<services>
<service id="behat.yii_extension.context.initializer" class="%behat.yii_extension.context.initializer.class%">
<argument>%behat.yii_extension.framework_script%</argument>
<argument>%behat.yii_extension.config_script%</argument>
<argument>%behat.yii_extension.web_application_factory%</argument>
<tag name="behat.context.initializer" />
<service id="yii_extension.context.initializer" class="%yii_extension.context.initializer.class%">
<argument>%yii_extension.framework_script%</argument>
<argument>%yii_extension.config_script%</argument>
<argument>%yii_extension.web_application_factory%</argument>
<tag name="context.initializer" />
</service>
</services>
</container>