Skip to content

Latest commit

 

History

History
88 lines (51 loc) · 5.48 KB

verifier-api.rst

File metadata and controls

88 lines (51 loc) · 5.48 KB

Verifier API

You can add functionality to BeBat/Verify by creating a custom assertion class, or "verifier". Your verifier can then be swapped in using the withVerifier() <extending.withVerifier> method. All verifiers must extend BeBat\Verify\API\Base, which provides common functionality for assertion methods. This page describes the public and protected methods built into BeBat\Verify\API\Base that are most relevant to creating a verifier, although it is not a complete list of every method that class includes.

Fluent Design

Your verifier should use a fluent interface, meaning all publicly available methods should return self. For your assertion methods, the easiest way to do this is to return a call to :phpBeBat\\Verify\\API\\Base::constraint with your assertion's constraint. If you need more flexibility with resolving your subject's value (such as reading it from a file) you may return :phpBeBat\\Verify\\API\\Base::performAssertion instead. Lastly, if your assertion is that two values are equal, you can us the :phpBeBat\\Verify\\API\\Base::performEqualToAssertion to simplify handling the various modifiers and edge cases that constraint supports. All three of these methods will also handle negative assertions for you, as well as resetting the classes internal state for the next assertion.