- \PHPUnit_Framework_Constraint
abstract class (none) \ PHPUnit_Framework_Constraint
- All implemented interfaces:
- Countable, PHPUnit_Framework_SelfDescribing
- All known direct subclasses:
- PHPUnit_Framework_Constraint_And, PHPUnit_Framework_Constraint_ArrayHasKey, PHPUnit_Framework_Constraint_ArraySubset, PHPUnit_Framework_Constraint_Callback, PHPUnit_Framework_Constraint_ClassHasAttribute, PHPUnit_Framework_Constraint_Composite, PHPUnit_Framework_Constraint_Count, PHPUnit_Framework_Constraint_Exception, PHPUnit_Framework_Constraint_ExceptionCode, PHPUnit_Framework_Constraint_ExceptionMessage, PHPUnit_Framework_Constraint_ExceptionMessageRegExp, PHPUnit_Framework_Constraint_FileExists, PHPUnit_Framework_Constraint_GreaterThan, PHPUnit_Framework_Constraint_IsAnything, PHPUnit_Framework_Constraint_IsEmpty, PHPUnit_Framework_Constraint_IsEqual, PHPUnit_Framework_Constraint_IsFalse, PHPUnit_Framework_Constraint_IsIdentical, PHPUnit_Framework_Constraint_IsInstanceOf, PHPUnit_Framework_Constraint_IsJson, PHPUnit_Framework_Constraint_IsNull, PHPUnit_Framework_Constraint_IsTrue, PHPUnit_Framework_Constraint_IsType, PHPUnit_Framework_Constraint_JsonMatches, PHPUnit_Framework_Constraint_LessThan, PHPUnit_Framework_Constraint_Not, PHPUnit_Framework_Constraint_Or, PHPUnit_Framework_Constraint_PCREMatch, PHPUnit_Framework_Constraint_StringContains, PHPUnit_Framework_Constraint_StringEndsWith, PHPUnit_Framework_Constraint_StringStartsWith, PHPUnit_Framework_Constraint_TraversableContains, PHPUnit_Framework_Constraint_TraversableContainsOnly, PHPUnit_Framework_Constraint_Xor
Abstract base class for constraints. which are placed upon any value.
Method Summary
Name | Description |
---|---|
__construct() | |
additionalFailureDescription($other) | Return additional failure description where needed |
count() | Counts the number of constraint elements. |
evaluate($other, $description = "", $returnResult = false) | Evaluates the constraint for parameter $other |
fail($other, $description, ComparisonFailure $comparisonFailure = null) | Throws an exception for the given compared value and test description |
failureDescription($other) | Returns the description of the failure |
matches($other) | Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise. |
public function __construct()
protected function additionalFailureDescription($other)
Return additional failure description where needed
The function can be overridden to provide additional failure information like a diff
- Parameters:
mixed
- $other Evaluated value or object.- Returns:
- string
public function count()
Counts the number of constraint elements.
- Returns:
- integer
public function evaluate($other, $description = "", $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.
- Parameters:
mixed
- $other Value or object to evaluate.string
- $description Additional information about the testbool
- $returnResult Whether to return a result or throw an exception- Defaults:
description
=""
returnResult
=false
- Returns:
- mixed
- Throws:
- PHPUnit_Framework_ExpectationFailedException
protected function fail($other, $description, ComparisonFailure $comparisonFailure = null)
Throws an exception for the given compared value and test description
- Parameters:
mixed
- $other Evaluated value or object.string
- $description Additional information about the testSebastianBergmann\Comparator\ComparisonFailure
- $comparisonFailure- Defaults:
comparisonFailure
=null
- Throws:
- PHPUnit_Framework_ExpectationFailedException
protected function failureDescription($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.
To provide additional failure information additionalFailureDescription can be used.
- Parameters:
mixed
- $other Evaluated value or object.- Returns:
- string
protected function matches($other)
Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
This method can be overridden to implement the evaluation algorithm.
- Parameters:
mixed
- $other Value or object to evaluate.- Returns:
- bool