Assertion Modifiers
The behavior of many assertions can be adjusted inline with the test. These modifiers can be used to control case sensitivity, account for floating point errors, or strictness when checking for object identity and datatypes.
Included Modifiers
within()
verify(0.1 + 0.2)->within(0.01)->is()->equalTo(0.3);
Supported Assertion
verify(<float>)
withoutCase()
verify('A String')->withoutCase()->is()->equalTo('a string');
verify('A String')->withoutCase()->will()->contain('string');
verify('a string')->withoutCase()->is()->equalToFile('/some/file.txt');
verify_file('/some/file.txt')->withoutCase()->is()->equalTo('a string');
verify_file('/some/file.txt')->withoutCase()->will()->contain('string');
verify_file('/some/file.txt')->withoutCase()->is()->equalToFile('/some/other/file.txt');
Supported Assertions
verify(<string>)
verify_file()
withoutLineEndings()
verify("a\nstring")->withoutLineEndings()->is()->equalTo("a\r\nstring");
verify("another\nstring")->withoutLineEndings()->will()->contain("other\r\nstring");
verify("a\r\nstring")->withoutLineEndings()->is()->equalToFile('/some/file.txt');
verify_file('/some/file.txt')->withoutLineEndings()->is()->equalTo("a\r\nstring")
verify_file('/some/file.txt')->withoutLineEndings()->will()->contain("other\r\nstring")
verify_file('/some/file.txt')->withoutLineEndings()->is()->equalToFile('/some/other/file.txt')
Attention
The withoutLineEndings()
modifier requires PHPUnit 10 or later.
Supported Assertions
verify(<string>)
verify_file()
withoutOrder()
verify([1, 2, 3])->withoutOrder()->is()->equalTo([3, 1, 2]);
Supported Assertion
verify(<array>)
withoutIdentity()
verify([$objectA])->withoutIdentity()->does()->contain($objectB);
Supported Assertion
verify(<array>)
withoutType()
verify(['1', '2'])->withoutType()->will()->contain(1);
Supported Assertion
verify(<array>)
matching()
verify_file('/some/file/to/test.sh')->has()->matching()->permissions(0711);
Supported Assertion
verify_file()
Chaining Modifiers
Modifiers can be chained inline with an assertion, so any assertion that supports both withoutCase()
and withoutLineEndings()
will support applying both modifiers simultaneously.
verify("A\n\rString")->withoutCase()->withoutLineEndings()
->is()->equalTo("a\nstring");
BeBat/Verify resets its internal state after each assertion, so if you are chaining modifiers along with multiple assertions, you must reapply the modifier each time.
verify(['1', '2', '3'])->will()->withoutType()->contain(1)
->and()->withoutType()->contain(2);