Behat3 子上下文
Behat3 Subcontexts
Behat 的早期版本使用 useContext 来包含子上下文并执行它们。我的问题是如何在 Behat3 中包含 SubContext ?
我尝试查看 Behat3 文档,但看起来 link 已损坏,也尝试搜索 Whosebug,但仍然没有任何线索。
你可以这样做
//behat.yml
default:
suites:
default:
contexts: [FeatureContext, SubContext]
//FeatureContext.php
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
class FeatureContext implements Context {
private $subContext;
/** @BeforeScenario */
public function fetchContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();
$this->subContext = $environment->getContext('SubContext');
}
/** @When I do something on :foo */
function IDoSomethingOnFoo($foo) {
$this->subContext->doSomethingOnFoo($foo);
}
}
//SubContext.php
<?php
use Behat\Behat\Context\Context;
class SubContext implements Context {
function doSomethingOnFoo($foo) {
//...
}
}
我没有测试过它,但我非常有信心这会回答你的问题。
Behat 的早期版本使用 useContext 来包含子上下文并执行它们。我的问题是如何在 Behat3 中包含 SubContext ?
我尝试查看 Behat3 文档,但看起来 link 已损坏,也尝试搜索 Whosebug,但仍然没有任何线索。
你可以这样做
//behat.yml
default:
suites:
default:
contexts: [FeatureContext, SubContext]
//FeatureContext.php
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
class FeatureContext implements Context {
private $subContext;
/** @BeforeScenario */
public function fetchContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();
$this->subContext = $environment->getContext('SubContext');
}
/** @When I do something on :foo */
function IDoSomethingOnFoo($foo) {
$this->subContext->doSomethingOnFoo($foo);
}
}
//SubContext.php
<?php
use Behat\Behat\Context\Context;
class SubContext implements Context {
function doSomethingOnFoo($foo) {
//...
}
}
我没有测试过它,但我非常有信心这会回答你的问题。