如果找到正则表达式文本,PHPUnit assertTrue?
发布时间:2020-12-14 06:24:30 所属栏目:百科 来源:网络整理
导读:我正在使用 PHPUnit并尝试检查页面上是否存在文本. assertRegExp工作但使用if语句我得到错误Failed断言null为真. 我知道$test返回null,但是如果文本存在,我不知道如何让它返回1或0或true / false?任何帮助表示感谢. $element = $this-byCssSelector('body')
我正在使用
PHPUnit并尝试检查页面上是否存在文本. assertRegExp工作但使用if语句我得到错误Failed断言null为真.
我知道$test返回null,但是如果文本存在,我不知道如何让它返回1或0或true / false?任何帮助表示感谢. $element = $this->byCssSelector('body')->text(); $test = $this->assertRegExp('/find this text/i',$element); if($this->assertTrue($test)){ echo 'text found'; } else{ echo 'not found'; }
assertRegExp()将不返回任何内容.如果断言失败 – 意味着找不到文本 – 则以下代码将不会执行:
$this->assertRegExp('/find this text/i',$element); // following code will not get executed if the text was not found // and the test will get marked as "failed" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |