-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
behat 3 #13
Changes from 3 commits
a730f75
a1c85b0
6106bf4
4174ccc
4115279
51651c4
b3b6dd3
0e80313
6080406
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
|
||
"require": { | ||
"php": ">=5.3.2", | ||
"behat/behat": "~2.5" | ||
"behat/behat": "^3.2" | ||
}, | ||
|
||
"suggest": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
*/ | ||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Behat\YiiExtension\Context; | ||
|
||
class YiiContext implements YiiAwareContextInterface | ||
{ | ||
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 |
---|---|---|
|
@@ -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 <[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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be removed |
||
|
||
$basePath = $container->getParameter('paths.base'); | ||
|
||
$extensions = $container->getParameter('extensions'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -100,4 +109,7 @@ public function getConfig(ArrayNodeDefinition $builder) | |
end() | ||
; | ||
} | ||
|
||
public function initialize(ExtensionManager $extensionManager) {} | ||
public function process(ContainerBuilder $container) {} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.