The assertStringMatchesFormat() is a built in PHP function to test your php based features before deploying the application on your live application.
assertStringMatchesFormat(string $format, string $string[,
string $message = ''])
Reports an error identified by
$message if the
$string does not match the
assertStringMatchesFormat() function is the inverse of this assertion and takes the same arguments.
class StringMatchesFormatTest extends TestCase
public function testFailure()
$ phpunit StringMatchesFormatTest
PHPUnit 8.4.0 by Sebastian Bergmann and contributors.
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
Failed asserting that 'foo' matches PCRE pattern "/^[+-]?d+$/s".
Tests: 1, Assertions: 1, Failures: 1.
%e: Represents a directory separator, for example
%s: One or more of anything (character or white space) except the end of line character.
%S: Zero or more of anything (character or white space) except the end of line character.
%a: One or more of anything (character or white space) including the end of line character.
%A: Zero or more of anything (character or white space) including the end of line character.
%w: Zero or more white space characters.
%i: A signed integer value, for example
%d: An unsigned integer value, for example
%x: One or more hexadecimal character. That is, characters in the range
%f: A floating point number, for example:
%c: A single character of any sort.
%%: A literal percent character:
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.