我正在测试 Laravel 应用程序,需要确保页面上不存在文本,这很简单。我使用 dontSee
但出现了一个令人惊讶的错误
代码
public function testSuccessfulSignupActivated(){
$this->visit('/signup?activate=true')
->type('username', 'name')
->type('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="691d0c1a1d2904080005470a0604" rel="noreferrer noopener nofollow">[email protected]</a>', 'mail')
->type('password', 'password')
->type('password', 'password_confirm')
->type('Philip', 'first_name')
->type('Fry', 'last_name')
->select('Freelancer', 'profile')
->check('licensecheck')->press('Create new account')
->seePageIs('/user')
->dontSee('A validation e-mail has been sent to your e-mail address.') ;
}
错误
无法断言“...”与 PCRE 模式不匹配验证电子邮件尚未发送到您的电子邮件地址。
它似乎否定了我通过的英文句子,这根本不是我想做的,只是为了确定我没有疯,我检查了我的源代码,文本是“验证电子邮件已发送到您的电子邮件地址”
dontSeeText
具有相同的效果,并且 dontSeeInElement
通过页面上的文本测试(误报)
最佳答案
这是 PHPUnit 中的副作用。
目前,从 Laravel 5.2.22 开始,Laravel 的 dontSee()
测试使用 PHPUnit assertNotRegExp()
测试。当此测试失败时,它返回的消息会尝试否定正在检查的文本中的某些单词。您可以看到单词列表here .
就您而言,它用 没有
替换了单词has
。
实际上有一个pull request Laravel 中解决了这个问题,并且它已经被合并了。但是,自从合并以来还没有新的标记版本。我假设下一个标记版本将包含此更新(Laravel 5.2.23)。一旦此更新包含在标记版本中,您应该能够composer更新
,并且您的验证消息看起来会更好。
关于php - Laravel 测试 dontSee 否定英文文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35927819/