gpt4 book ai didi

如果找到正则表达式文本,PHPUnit assertTrue?

转载 作者:可可西里 更新时间:2023-11-01 12:42:14 24 4
gpt4 key购买 nike

我正在使用 PHPUnit 并尝试检查页面上是否存在文本。 assertRegExp 有效,但使用 if 语句时出现错误 Failed asserting that null is true.

我知道 $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"

关于如果找到正则表达式文本,PHPUnit assertTrue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19040373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com