behat 有没有办法让它在我填写字段时输入今天的日期?
一个例子
鉴于我填写了以下字段 |字段日期 |今天 |
我希望输出为 dd/mm/YYYY
我不明白为什么我找不到它,或者找到其他人以前做过这个?我找到了小 cucumber 和 cucumber 的答案,但没有找到 PHP 和 behat 的答案..
谢谢
最佳答案
我设法让它工作...将其添加到您的 FormContext 文件 -
/**
* Fills in specified field with date
* Example: When I fill in "field_ID" with date "now"
* Example: When I fill in "field_ID" with date "-7 days"
* Example: When I fill in "field_ID" with date "+7 days"
* Example: When I fill in "field_ID" with date "-/+0 weeks"
* Example: When I fill in "field_ID" with date "-/+0 years"
*
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with date "(?P<value>(?:[^"]|\\")*)"$/
*/
public function fillDateField($field, $value)
{
$newDate = strtotime("$value");
$dateToSet = date("d/m/Y", $newDate);
$this->getSession()->getPage()->fillField($field, $dateToSet);
}
关于php - "When I fill the following fields"输入今天的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37998665/