php - How to test if string contains another string in PHPUnit? -


i can't seem find assertion in phpunit tests if string contained somewhere in string. trying this:

public function testrecipe() {      $plaintext = get_bread_recipe();      $this->assertstringcontains('flour', $plaintext);  } 

what real assertion put instead of assertstringcontains ? prefer not having worry regex in case because there absolutely no need it.

it's simple there must have overlooked, can't figure out! funny enough there assertstringstartswith() , assertstringendswith()!

update: know strpos() !== false used i'm looking cleaner. if use vanilla php functions anyway what's whole point assertions then...

as tell assertcontains checking array contains value.

looking see if string contains substring, simplest query use assertregexp()

$this->assertregexp('/flour/', $plaintext); 

you need add delimiters.

if want have assertstringcontains assertion, can extend phpunit_framework_testcase , create own.

update

in latest version of phpunit, assertcontains work on strings.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -