Behat Drupal:访问 %paths.base% 之外的功能
Behat Drupal: accessing features outside the %paths.base%
我的任务是改进我们现有的基于分布的 Drupal 系统中的行为测试。问题是我想 运行 behat 来自相互引用的不同目录的测试。我们支持多个 D7 站点并将它们基于我们的内部发行版,因此所有站点都可以共享创建相同功能的模块。分发模块的示例是:dist_news 和 dist_events 并且基于分发的测试将存在于 dist_test 模块中。这些模块将在 dentist.oursite.org 或 radio.oursite.org 等不同站点创建新闻和事件内容类型,并且每个模块在 git 中都有自己的 repo。特定站点位于名为 dentist_builder 或 radio_builder 的存储库中,这两个存储库都基于 dist_builder ,它存在于自己的存储库中,并通过 composer g 从各个模块存储库构建自身运行t、yarn 等。特定于站点的测试位于名为 dentist_test 的模块中,该模块位于牙医构建器中。当我想测试一个站点上的功能而不是另一个站点上的功能时,问题就出现了。例如。牙医站点有新闻和事件,广播站点有新闻但没有事件,牙医新闻有新闻版块,而广播站点没有。新闻和事件的各种测试都在 dist_test 中进行,所以如果我想测试它们,我可以 运行 像这样:
vendor/bin/behat -c build/html/profiles/dist/modules/dist/dist_test/tests/behat.yml build/html/profiles/dist/modules/dist/dist_test/tests/features/news/news.feature
vendor/bin/behat -c build/html/profiles/dist/modules/dist/dist_test/tests/behat.yml build/html/profiles/dist/modules/dist/dist_test/tests/features/events/events.feature
对于收音机我可以 运行:
vendor/bin/behat -c build/html/profiles/dist/modules/dist/dist_test/tests/behat.yml build/html/profiles/dist/modules/dist/dist_test/tests/features/news/news.feature
但是测试新闻的 In The News 部分的场景会失败,因为它不在 Radio 中。
所以我要设置的是通过 dentist_test 的 behat.yml 或 radio_test 的 behat.yml 进行测试 运行所以我只能测试每个网站我想测试的东西:
vendor/bin/behat -c build/html/src/modules/dentist_test/tests/behat.yml --suite=news
vendor/bin/behat -c build/html/src/modules/radio_test/tests/behat.yml --suite=news
各个套件将 运行 所有测试,通过标签过滤器或路径,用于牙医网站,只有我们需要的无线电网站测试。
Dentist_builder,包括目前有效的测试,相关目录结构为:
vendor/
bin/
behat
build/
html/
profiles/
dist/
modules/
dist/
dist_test/
tests/
behat.yml
contexts/
/FeatureContext.php
features/
/news
/news.feature
src/
modules/
dentist_test/
tests/
behat.yml
features/
/homepage.feature
behat.yml in dentist_test 是这样设置的:
default:
suites:
default:
contexts:
- Dist\Context\FeatureContext:
- screenshotDirectory: '%paths.base%/screenshots'
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
我已经尝试设置另一个套件来使用 dist_test 中的功能,但它不起作用:
news:
contexts:
- Dist\Context\FeatureContext:
- screenshotDirectory: '%paths.base%/screenshots'
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
filters:
tags: "@news"
paths:
- %paths.base%/../../../../../../profiles/dist/modules/dist/dist_test/tests/features/news
dist_test/tests/contexts/FeatureContext.php 看起来像:
<?php
/**
* @file
* Default context class defining how behat should test our application.
*
* @see http://docs.behat.org/en/latest/guides/4.contexts.html
*/
namespace Dist\Context;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ExpectationException;
use Behat\Mink\Exception\ElementNotFoundException;
use Symfony\Component\DependencyInjection\Container;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {
/**
* Initializes context.
*
* Every scenario gets its own context instance.
*/
public function __construct($parameters = array()) {
foreach ($parameters as $key => $value) {
$property = lcfirst(Container::camelize($key));
$this->$property = $value;
}
}
/**
* Custom step to assert that username of user with uid is not listed.
*
* @Then I should not see user :uid
*/
public function iShouldNotSeeUser($uid) {
$user = \user_load($uid);
$this->assertSession()->pageTextNotContains($user->name);
}
... (a bunch more functions)
}
一旦我弄清楚如何从 dentist_test 中的 behat.yml 访问 dist_test 中的 news.feature 我可以用我认为的路径和标签修复其余部分,我现在只需要了解如何使用这些功能。我想避免的是在 dentist_test 和 radio_test 中复制和维护相同的基于分布的测试,因为一旦我们进入数百个站点,这将变得荒谬可笑。
我假设
paths:
- %paths.base%/../../../../../../profiles/dist/modules/dist/dist_test/tests/features/news
我哪里出错了,或者甚至可以做我想让它做的事?第一次深入 behat,所以如果我遗漏了一些简单的架构方面的知识,请告诉我。
事实证明这是路径,我只需要输入所有这些内容就可以弄清楚。
更改:
paths:
- %paths.base%/../../../../../../profiles/dist/modules/dist/dist_test/tests/features/news
至:
paths:
- %paths.base%/../../../../profiles/dist/modules/dist/dist_test/tests/features/news
我错过的是 dental_test 位于 src/modules/dentist_test,但在站点构建期间与 build/html/sites/all/modules/custom/dental_test 建立了符号链接。我需要从前者而不是后者开始。现在效果很好!但是,如果有人有更好的方法,请告诉我。
我的任务是改进我们现有的基于分布的 Drupal 系统中的行为测试。问题是我想 运行 behat 来自相互引用的不同目录的测试。我们支持多个 D7 站点并将它们基于我们的内部发行版,因此所有站点都可以共享创建相同功能的模块。分发模块的示例是:dist_news 和 dist_events 并且基于分发的测试将存在于 dist_test 模块中。这些模块将在 dentist.oursite.org 或 radio.oursite.org 等不同站点创建新闻和事件内容类型,并且每个模块在 git 中都有自己的 repo。特定站点位于名为 dentist_builder 或 radio_builder 的存储库中,这两个存储库都基于 dist_builder ,它存在于自己的存储库中,并通过 composer g 从各个模块存储库构建自身运行t、yarn 等。特定于站点的测试位于名为 dentist_test 的模块中,该模块位于牙医构建器中。当我想测试一个站点上的功能而不是另一个站点上的功能时,问题就出现了。例如。牙医站点有新闻和事件,广播站点有新闻但没有事件,牙医新闻有新闻版块,而广播站点没有。新闻和事件的各种测试都在 dist_test 中进行,所以如果我想测试它们,我可以 运行 像这样:
vendor/bin/behat -c build/html/profiles/dist/modules/dist/dist_test/tests/behat.yml build/html/profiles/dist/modules/dist/dist_test/tests/features/news/news.feature
vendor/bin/behat -c build/html/profiles/dist/modules/dist/dist_test/tests/behat.yml build/html/profiles/dist/modules/dist/dist_test/tests/features/events/events.feature
对于收音机我可以 运行:
vendor/bin/behat -c build/html/profiles/dist/modules/dist/dist_test/tests/behat.yml build/html/profiles/dist/modules/dist/dist_test/tests/features/news/news.feature
但是测试新闻的 In The News 部分的场景会失败,因为它不在 Radio 中。
所以我要设置的是通过 dentist_test 的 behat.yml 或 radio_test 的 behat.yml 进行测试 运行所以我只能测试每个网站我想测试的东西:
vendor/bin/behat -c build/html/src/modules/dentist_test/tests/behat.yml --suite=news
vendor/bin/behat -c build/html/src/modules/radio_test/tests/behat.yml --suite=news
各个套件将 运行 所有测试,通过标签过滤器或路径,用于牙医网站,只有我们需要的无线电网站测试。
Dentist_builder,包括目前有效的测试,相关目录结构为:
vendor/
bin/
behat
build/
html/
profiles/
dist/
modules/
dist/
dist_test/
tests/
behat.yml
contexts/
/FeatureContext.php
features/
/news
/news.feature
src/
modules/
dentist_test/
tests/
behat.yml
features/
/homepage.feature
behat.yml in dentist_test 是这样设置的:
default:
suites:
default:
contexts:
- Dist\Context\FeatureContext:
- screenshotDirectory: '%paths.base%/screenshots'
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
我已经尝试设置另一个套件来使用 dist_test 中的功能,但它不起作用:
news:
contexts:
- Dist\Context\FeatureContext:
- screenshotDirectory: '%paths.base%/screenshots'
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
filters:
tags: "@news"
paths:
- %paths.base%/../../../../../../profiles/dist/modules/dist/dist_test/tests/features/news
dist_test/tests/contexts/FeatureContext.php 看起来像:
<?php
/**
* @file
* Default context class defining how behat should test our application.
*
* @see http://docs.behat.org/en/latest/guides/4.contexts.html
*/
namespace Dist\Context;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ExpectationException;
use Behat\Mink\Exception\ElementNotFoundException;
use Symfony\Component\DependencyInjection\Container;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {
/**
* Initializes context.
*
* Every scenario gets its own context instance.
*/
public function __construct($parameters = array()) {
foreach ($parameters as $key => $value) {
$property = lcfirst(Container::camelize($key));
$this->$property = $value;
}
}
/**
* Custom step to assert that username of user with uid is not listed.
*
* @Then I should not see user :uid
*/
public function iShouldNotSeeUser($uid) {
$user = \user_load($uid);
$this->assertSession()->pageTextNotContains($user->name);
}
... (a bunch more functions)
}
一旦我弄清楚如何从 dentist_test 中的 behat.yml 访问 dist_test 中的 news.feature 我可以用我认为的路径和标签修复其余部分,我现在只需要了解如何使用这些功能。我想避免的是在 dentist_test 和 radio_test 中复制和维护相同的基于分布的测试,因为一旦我们进入数百个站点,这将变得荒谬可笑。 我假设
paths:
- %paths.base%/../../../../../../profiles/dist/modules/dist/dist_test/tests/features/news
我哪里出错了,或者甚至可以做我想让它做的事?第一次深入 behat,所以如果我遗漏了一些简单的架构方面的知识,请告诉我。
事实证明这是路径,我只需要输入所有这些内容就可以弄清楚。 更改:
paths:
- %paths.base%/../../../../../../profiles/dist/modules/dist/dist_test/tests/features/news
至:
paths:
- %paths.base%/../../../../profiles/dist/modules/dist/dist_test/tests/features/news
我错过的是 dental_test 位于 src/modules/dentist_test,但在站点构建期间与 build/html/sites/all/modules/custom/dental_test 建立了符号链接。我需要从前者而不是后者开始。现在效果很好!但是,如果有人有更好的方法,请告诉我。