Skip to content

Commit

Permalink
Improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
BR0kEN- committed Apr 2, 2016
1 parent 4533789 commit 9a572a9
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 9 deletions.
5 changes: 2 additions & 3 deletions composer.json
Expand Up @@ -16,8 +16,7 @@
"behat/behat": ">=3.0.6"
},
"require-dev": {
"phpunit/phpunit": "4 - 5",
"behat/soap-extension": "dev-master"
"phpunit/phpunit": "4 - 5"
},
"autoload": {
"psr-4": {
Expand All @@ -26,7 +25,7 @@
},
"autoload-dev": {
"psr-4": {
"Behat\\Tests\\ExampleExtension\\": "tests/example-extension"
"Behat\\Tests\\": "tests/behat/extensions"
}
}
}
2 changes: 1 addition & 1 deletion tests/EnvironmentLoaderTest.php
Expand Up @@ -69,7 +69,7 @@ public function loaderConstructor()
$this->readLoaderProperties();

foreach ([
'path' => sprintf('%s/example-extension', __DIR__),
'path' => sprintf('%s/behat/extensions/ExampleExtension', __DIR__),
'namespace' => sprintf('%s\ExampleExtension', __NAMESPACE__),
'container' => $this->container,
'configKey' => $this->extension->getConfigKey(),
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/behat.yml
Expand Up @@ -3,5 +3,5 @@ default:
default:
contexts: {}
extensions:
Behat\SoapExtension: ~
Behat\Tests\DummyExtension: ~
Behat\Tests\ExampleExtension: ~
20 changes: 20 additions & 0 deletions tests/behat/extensions/DummyExtension/Context/DummyContext.php
@@ -0,0 +1,20 @@
<?php
/**
* @author Sergii Bondarenko, <sb@firstvector.org>
*/
namespace Behat\Tests\DummyExtension\Context;

/**
* Class DummyContext.
*
* @package Behat\Tests\DummyExtension\Context
*/
class DummyContext extends RawDummyContext
{
/**
* @Then dummy step
*/
public function dummyStep()
{
}
}
@@ -0,0 +1,41 @@
<?php
/**
* @author Sergii Bondarenko, <sb@firstvector.org>
*/
namespace Behat\Tests\DummyExtension\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\Initializer\ContextInitializer;

/**
* Class DummyContextInitializer.
*
* @package Behat\Tests\DummyExtension\Context
*/
class DummyContextInitializer implements ContextInitializer
{
/**
* Parameters of context.
*
* @var array
*/
private $parameters = [];

/**
* @param array $parameters
*/
public function __construct(array $parameters)
{
$this->parameters = $parameters;
}

/**
* {@inheritdoc}
*/
public function initializeContext(Context $context)
{
if ($context instanceof DummyContextInterface) {
$context->setParameters($this->parameters);
}
}
}
@@ -0,0 +1,23 @@
<?php
/**
* @author Sergii Bondarenko, <sb@firstvector.org>
*/
namespace Behat\Tests\DummyExtension\Context;

use Behat\Behat\Context\Context;

/**
* Interface DummyContextInterface.
*
* @package Behat\Tests\DummyExtension\Context
*/
interface DummyContextInterface extends Context
{
/**
* Set parameters from behat.yml.
*
* @param array $parameters
* An array of parameters from configuration file.
*/
public function setParameters(array $parameters);
}
41 changes: 41 additions & 0 deletions tests/behat/extensions/DummyExtension/Context/RawDummyContext.php
@@ -0,0 +1,41 @@
<?php
/**
* @author Sergii Bondarenko, <sb@firstvector.org>
*/
namespace Behat\Tests\DummyExtension\Context;

/**
* Class RawDummyContext.
*
* @package Behat\Tests\DummyExtension\Context
*/
class RawDummyContext implements DummyContextInterface
{
/**
* Parameters of context.
*
* @var array
*/
private $parameters = [];

/**
* {@inheritdoc}
*/
public function setParameters(array $parameters)
{
if (empty($this->parameters)) {
$this->parameters = $parameters;
}
}

/**
* @param string $name
* The name of parameter from behat.yml.
*
* @return mixed
*/
protected function getParameter($name)
{
return isset($this->parameters[$name]) ? $this->parameters[$name] : false;
}
}
@@ -0,0 +1,57 @@
<?php
/**
* @author Sergii Bondarenko, <sb@firstvector.org>
*/
namespace Behat\Tests\DummyExtension\ServiceContainer;

use Behat\EnvironmentLoader;
use Behat\Testwork\ServiceContainer\Extension;
use Behat\Testwork\ServiceContainer\ExtensionManager;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

/**
* Class DummyExtension.
*
* @package Behat\SoapExtension\ServiceContainer
*/
class DummyExtension implements Extension
{
/**
* {@inheritdoc}
*/
public function getConfigKey()
{
return 'dummy';
}

/**
* {@inheritdoc}
*/
public function initialize(ExtensionManager $extensionManager)
{
}

/**
* {@inheritdoc}
*/
public function load(ContainerBuilder $container, array $config)
{
$loader = new EnvironmentLoader($this, $container, $config);
$loader->load();
}

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
}

/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder)
{
}
}
Expand Up @@ -12,7 +12,7 @@
class ExampleContext extends RawExampleContext
{
/**
* @Then /^(?:|I )do nothing$/
* @Then example step
*/
public function exampleStep()
{
Expand Down
6 changes: 3 additions & 3 deletions tests/behat/features/test.feature
@@ -1,6 +1,6 @@
Feature: Check that environment loader scans it properly
Scenario: Try execute steps from couple extensions which are used environment loader
# Try execute step from SoapExtension.
Given I am working with SOAP service WSDL "http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
# Try execute step from DummyExtension.
Given dummy step
# Try execute step from ExampleExtension.
And do nothing
And example step

0 comments on commit 9a572a9

Please sign in to comment.