如何以编程方式调用 Behat 步骤?警告:Behat\Behat\Definition\Call\Given::__construct() 缺少参数 2

How to call Behat step programmatically? Warning: Missing argument 2 for Behat\Behat\Definition\Call\Given::__construct()

我有 behat 3.0.15,我在创建我的第一个 Behat 测试时遵循这个 tutorial

代码:

/**
 * @When I go to see akaneo product page for :country written in :language language   
 */
public function findOrCreateProductForCountryAndVisitIt($country, $language)
{
    global $user;
    $node = new stdClass;
    $node->title = 'Test Product';
    $node->type = 'akaneo_product';
    node_object_prepare($node);
    $node->uid = $user->uid;
    $node->status = 1;
    $node->language = $language;
    #load domain id for country
    $result = db_select('domain', 'd')
        ->fields('d', array('domain_id'))
        ->condition('subdomain',  strtolower($country) . '_schiller.%', 'LIKE')
        ->execute()
        ->fetchAssoc();



    if (empty($result)) {
        throw new Exception("Cannot find subsidiary for country code: $country");
    }

    $node->domains = array(
      $result['domain_id'] => $result['domain_id']
    );

    $node = $this->nodeCreate($node);

    return new Given('I go to node/' . $node->nid);

}

输出:

  Warning: Missing argument 2 for Behat\Behat\Definition\Call\Given::__construct(), called in features/bootstrap/FeatureContext.php on line 435 and defined in vendor/behat/behat/src/Behat/Behat/Definition/Call/Given.php line 27
│
╳  Unable to access the response content before visiting a page (Behat\Mink\Exception\DriverException)
│
└─ @AfterStep # ScreenshotContext::logResponseAfterFailedStep()

我应该传递什么作为可调用的构造函数参数?

Behat 3 中无法链接步骤。 如果你想重用一些代码,只需遵循常规的 OOP 方法 - 将公共代码提取到单独的方法或 class。

您将在此处找到删除说明:https://github.com/Behat/Behat/issues/546#issuecomment-45202991