Merge branch '2.0'

* 2.0:
  Generate changelog for v2.0.4 and v2.0.5
  Allow accessing a context in another context
This commit is contained in:
Kamil Kokot
2019-03-04 14:14:22 +01:00
3 changed files with 81 additions and 1 deletions

View File

@@ -1,5 +1,13 @@
# CHANGELOG for `2.0.x`
## v2.0.5 (2019-03-04)
- [#72](https://github.com/FriendsOfBehat/SymfonyExtension/issues/72) Allow accessing a context in another context ([@pamil](https://github.com/pamil))
## v2.0.4 (2019-02-13)
- [#68](https://github.com/FriendsOfBehat/SymfonyExtension/issues/68) Better compatibility with Behat itself ([@pamil](https://github.com/pamil), [@alanpoulain](https://github.com/alanpoulain))
## v2.0.3 (2019-02-07)
Removed the possibility to autoconfigure `$minkParameters` without a typehint due to an instable implementation in Symfony.

View File

@@ -0,0 +1,70 @@
Feature: Accessing a context in another context
Scenario: Accessing a context in another context
Given a working Symfony application with SymfonyExtension configured
And a Behat configuration containing:
"""
default:
suites:
default:
contexts:
- App\Tests\SomeContext
- App\Tests\AnotherContext
"""
And a feature file containing:
"""
Feature:
Scenario:
Then it should pass
"""
And a context file "tests/SomeContext.php" containing:
"""
<?php
namespace App\Tests;
use Behat\Behat\Context\Context;
final class SomeContext implements Context {
public function someMethod(): void {}
}
"""
And a context file "tests/AnotherContext.php" containing:
"""
<?php
namespace App\Tests;
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
final class AnotherContext implements Context {
/** @var SomeContext */
private $someContext;
/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();
$this->someContext = $environment->getContext('App\Tests\SomeContext');
}
/** @Then it should pass */
public function itShouldPass(): void
{
$this->someContext->someMethod();
}
}
"""
And a YAML services file containing:
"""
services:
App\Tests\SomeContext:
public: true
App\Tests\AnotherContext:
public: true
"""
When I run Behat
Then it should pass

View File

@@ -72,9 +72,11 @@ final class InitializedSymfonyExtensionEnvironment implements SymfonyExtensionEn
}
/**
* @see http://behat.org/en/latest/cookbooks/accessing_contexts_from_each_other.html
*
* @throws ContextNotFoundException
*/
private function getContext(string $class): Context
public function getContext(string $class): Context
{
if (!isset($this->contexts[$class])) {
throw new ContextNotFoundException(sprintf(