2017-02-01 11 views
0

の外の機能にアクセスする私は、既存の配布ベースのDrupalシステムでの動作テストの改善を担当しています。問題は、お互いを参照する異なるディレクトリからbehatテストを実行することです。私たちは複数のD7サイトをサポートしており、それらを内部配布に基づいているので、すべてのサイトで同じ種類の機能を作成するモジュールを共有できます。配布モジュールの例はdist_newsとdist_eventsであり、配布ベースのテストはdist_testモジュールにあります。これらのモジュールは、dentist.oursite.orgやradio.oursite.orgのような別々のサイトでニュースやイベントのコンテンツタイプを作成し、各モジュールはgitで独自のレポを持っています。特定のサイトは、dentist_builderまたはradio_builderと呼ばれるリポジトリに格納されています。これらのリポジトリは、独自のリポジトリに存在するdist_builderに基づいて作成され、作者、粗悪な糸などを介して個々のモジュールreposから構築されます。サイト固有のテストは、歯科医のビルダーに住むdentist_testと呼ばれる。この問題は、あるサイトにあるが別のサイトにはない機能をテストしたいときに発生します。例えば。歯科医のサイトにはニュースとイベントがあり、ラジオサイトにはニュースはありますがイベントはありません。歯科医のニュースにはIn The Newsセクションがありますが、ラジオサイトにはありません。Behat Drupal:%paths.base%

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 

が、テストシナリオを、私はそれらをテストしたい場合、私はのようなものを実行できるようにニュースやイベントのための各種試験は、dist_testに住んでいますニュースのニュースでは、ラジオにはないので、ニュースの一部が失敗するでしょう。

それでは、私は唯一の私は、サイトごとにテストしたいものをテストすることができますので、テストは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_testに

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::私は設定を試してみました

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 

これまでの作業テストを含む

Dentist_builderは、の該当するディレクトリ構造を持っています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 /テスト/コンテキスト/ FeatureContext.phpは、次のようになります。私はdentist_testにbehat.ymlからdist_testsにnews.featureにアクセスする方法を見つけ出すたら

<?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とradio_testの両方で同じディストリビューションベースのテストを複製して維持することです。これは、いったん厄介になる何百ものサイトに入るためです。 私は

paths: 
     - %paths.base%/../../../../../../profiles/dist/modules/dist/dist_test/tests/features/news 

は私が間違っているんだ、または私はそれがやりたいでもbehatことができる場所であると仮定していますか?私は単純なアーキテクチャの賢明な何かを見逃している場合、初めてbehatにダイビングので、私に知らせてください。

答えて

0

私はそれだけでは分かりませんでした。 は変更:

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 dentist_testのsrc /モジュールでの生活/しかしが/ HTML /サイト/すべて/モジュール/カスタム/ dental_testを構築するためにシンボリックリンクされていることですサイト構築中。私は後者ではなく前者からの道を踏み出す必要があった。今それは素晴らしい作品です!しかし、誰かがこれを行うより良い方法を持っている場合、私に教えてください。

関連する問題