首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何以编程方式调用Behat步骤?警告: Behat\Behat\Definition\Call\Given::__construct()缺少参数2

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

Stack Overflow用户
提问于 2016-08-10 22:33:42
回答 1查看 436关注 0票数 0

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

代码:

代码语言:javascript
复制
/**
 * @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);

}

输出:

代码语言:javascript
复制
  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()

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-10 22:50:21

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

你可以在这里找到删除的解释:https://github.com/Behat/Behat/issues/546#issuecomment-45202991

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38876371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档