I'm using PHPUnit and trying to check if text exists on a page. The assertRegExp works but using the if statement I get the error Failed asserting that null is true.
I understand that $test is returning null, but I don't know how to have it return 1 or 0 or true/false if the text exists? Any help's appreciated thanks.
$element = $this->byCssSelector('body')->text();
$test = $this->assertRegExp('/find this text/i',$element);
if($this->assertTrue($test)){
echo 'text found';
}
else{
echo 'not found';
}
Use this method in newer phpunit versions:
$this->assertMatchesRegularExpression('/PATTERN/', $yourString);
assertRegExp()
will return nothing. If the assertion fails - meaning the text was not found - then the following code won't get executed:
$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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With