Skip to content

Latest commit

 

History

History
182 lines (113 loc) · 5.02 KB

modifiers.rst

File metadata and controls

182 lines (113 loc) · 5.02 KB

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

modifiers.within

within()

verify(0.1 + 0.2)->within(0.01)->is()->equalTo(0.3);

Supported Assertion

  • verify(<float>)
    • equalTo() <assertions.value.equalTo>

modifiers.withoutCase

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

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

withoutOrder()

verify([1, 2, 3])->withoutOrder()->is()->equalTo([3, 1, 2]);

Supported Assertion

  • verify(<array>)
    • equalTo() <assertions.value.equalTo>

modifiers.withoutIdentity

withoutIdentity()

verify([$objectA])->withoutIdentity()->does()->contain($objectB);

Supported Assertion

  • verify(<array>)
    • contain() <assertions.value.array.contain>

modifiers.withoutType

withoutType()

verify(['1', '2'])->withoutType()->will()->contain(1);

Supported Assertion

  • verify(<array>)
    • contain() <assertions.value.array.contain>

modifiers.matching

matching()

verify_file('/some/file/to/test.sh')->has()->matching()->permissions(0711);

Supported Assertion

  • verify_file()
    • permission() <assertions.file.permission>

Chaining Modifiers

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