Chaining
Multiple conjunctions and assertions can be chained together, allowing developers to write multiple assertions about one subject very easily. For example:
verify($value)->is()->internalType('array')
->and()->has()->key('my_index')
->and()->will()->contain('my value');
The above performs three separate assertions against $value
in sequence, without having to redeclare our subject, and does so in a concise, easy to read syntax.
You can switch between positive and negative assertions on the fly; the condition will apply to whatever assertions follow it. For example:
verify($value)->will()->contain('value 1')
->and()->contain('value 2')
->and()->doesNot()->contain('value c')
->and()->doesNot()->contain('value d');
The above snippet will assert that $value
contains 'value 1'
and 'value 2'
, and does not contain 'value c'
or 'value d'
. It is worth noting that BeBat/Verify requires just a single positive or negative conjunction; any additional conjunction that does not change the assertion condition is optional. So the previous example could be simplified to:
verify($value)->will()->contain('value 1')->contain('value 2')
->doesNot()->contain('value c')->contain('value d');
Additional conjunctions are only required if you are changing to a positive or negative condition for the following assertion(s), or if you wish to add a descriptive message to the assertion:
verify($starsArray, 'Famous People')->will('have a Beatle')->contain('Ringo')
->will('have a cartoon')->contain('Bugs Bunny')
->willNot('have a pirate')->contain('Stede Bonnet');