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.
modifiers.within
verify(0.1 + 0.2)->within(0.01)->is()->equalTo(0.3);
verify(<float>)
equalTo() <assertions.value.equalTo>
modifiers.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');
verify(<string>)
equalTo() <assertions.value.equalTo>
contain() <assertions.value.string.contain>
equalToFile() <assertions.value.equalToFile>
verify_file()
equalTo() <assertions.file.equalTo>
contain() <assertions.file.contain>
equalToFile() <assertions.file.equalToFile>
modifiers.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.
verify(<string>)
equalTo() <assertions.value.equalTo>
contain() <assertions.value.string.contain>
equalToFile() <assertions.value.equalToFile>
verify_file()
equalTo() <assertions.file.equalTo>
contain() <assertions.file.contain>
equalToFile() <assertions.file.equalToFile>
modifiers.withoutOrder
verify([1, 2, 3])->withoutOrder()->is()->equalTo([3, 1, 2]);
verify(<array>)
equalTo() <assertions.value.equalTo>
modifiers.withoutIdentity
verify([$objectA])->withoutIdentity()->does()->contain($objectB);
verify(<array>)
contain() <assertions.value.array.contain>
modifiers.withoutType
verify(['1', '2'])->withoutType()->will()->contain(1);
verify(<array>)
contain() <assertions.value.array.contain>
modifiers.matching
verify_file('/some/file/to/test.sh')->has()->matching()->permissions(0711);
verify_file()
permission() <assertions.file.permission>
Modifiers can be chained <chaining>
inline with an assertion, so any assertion that supports both withoutCase() <modifiers.withoutCase>
and withoutLineEndings() <modifiers.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);