How to test if string contains another string in PHPUnit?

I can’t seem to find an assertion in PHPUnit that simply tests if a string is contained somewhere in another string. Trying to do something like this:

public function testRecipe() {

    $plaintext = get_bread_recipe();

    $this->assertStringContains('flour', $plaintext);

}

What real assertion would I put instead of assertStringContains ? I would prefer not having to worry about regex in this case because there is absolutely no need for it.

It’s so simple that there must be something I have overlooked, but I just can’t figure it out! Funny enough there is assertStringStartsWith() and assertStringEndsWith()!

Update: I know strpos() !== false could be used but I’m looking for something cleaner. If I just use vanilla PHP functions anyway what’s the whole point with all the assertions then…

Answer

2019 and PHPUnit 8.0 update

assertContains() is deprecated since PHPUnit 8.0, see issue #3425.


Now the specific method is recommended (see issue #3422):

$plaintext = 'I fell on the flour';
$this->assertStringContainsString('flour', $plaintext);

TIP: Upgrade instantly with Rector and PHPUnit 8.0 set.