2016-08-10 36 views
0

缺少参数2我有behat 3.0.15,在创建我的第一个Behat测试时,我遵循这个tutorial如何以编程方式调用Behat步骤?警告:Behat Behat Definition Call Given :: __ construct()

代码:

/** 
* @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() 

我应该通过为调用构造器的参数?

+0

你的步骤是怎样的?你可以添加代码吗? – lauda

+0

添加了更多代码 – drupality

回答

1

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

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

+0

因此,没有办法将自定义步骤中创建的内容的ID传递给另一个? – drupality

+0

您可以将此ID作为参数传递给其他方法。 –

+0

正是:)非常感谢 – drupality