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()

Account for floating point errors
verify(0.1 + 0.2)->within(0.01)->is()->equalTo(0.3);

Supported Assertion

withoutCase()

Ignore case when comparing strings
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

withoutLineEndings()

Ignore line ending format when comparing strings
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

withoutOrder()

Ignore element ordering when comparing arrays
verify([1, 2, 3])->withoutOrder()->is()->equalTo([3, 1, 2]);

Supported Assertion

withoutIdentity()

Ignore object identity when comparing values
verify([$objectA])->withoutIdentity()->does()->contain($objectB);

Supported Assertion

withoutType()

Ignore data type when comparing values
verify(['1', '2'])->withoutType()->will()->contain(1);

Supported Assertion

matching()

Match a minimum set of permissions, rather than an exact value
verify_file('/some/file/to/test.sh')->has()->matching()->permissions(0711);

Supported Assertion

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);