HasPregCaptures
final class HasPregCaptures extends Constraint
Constraint that accepts arrays of matches returned from preg_match()
having capture groups as specified in the array of expectations.
Checks only entries present in the array of expectations. Special values may be used in the expectations:
['foo' => false]
asserts that group'foo'
was not captured,['foo' => true]
asserts that group'foo'
was captured,['foo' => 'FOO']
asserts that group'foo'
was captured and it's value equals'FOO'
.
Boolean expectations (['foo' => true]
or ['foo' => false]
) work
properly only with arrays obtained from preg_match()
invoked with
PREG_UNMATCHED_AS_NULL
flag.
Methods
Initializes the constraint.
Returns a string representation of the constraint.
Evaluates the constraint for parameter $other.
Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
Returns the description of the failure.
Details
at line 68
static HasPregCaptures
create(array $expected, int $flags = PREG_OFFSET_CAPTURE | PREG_UNMATCHED_AS_NULL)
Initializes the constraint.
at line 78
string
toString()
Returns a string representation of the constraint.
at line 100
bool|null
evaluate(mixed $other, string $description = '', bool $returnResult = false)
Evaluates the constraint for parameter $other.
If $returnResult is set to false (the default), an exception is thrown in case of a failure. null is returned otherwise.
If $returnResult is true, the result of the evaluation is returned as a boolean value instead: true in case of success, false in case of a failure.
at line 133
protected bool
matches(mixed $other)
Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
at line 151
protected string
failureDescription(mixed $other)
Returns the description of the failure.
The beginning of failure messages is "Failed asserting that" in most cases. This method should return the second part of that sentence.