final class ArrayValuesIdenticalTo extends AbstractConstraint

Constraint that accepts arrays having values equal to specified ones.

Compares only values present in the array of expectations. The === operator (identity) is used for comparison.

 $matcher = ArrayValuesIdenticalTo::create([
     'name' => 'John', 'age' => '21'
 ]);

 self::assertThat([
     'age' => '21',
     'name' => 'John',
 ], $matcher);

Traits

Methods

string
toString()

Returns a string representation of the constraint.

string
failureDescription(mixed $other)

Returns the description of the failure.

string
failureDescriptionInContext(Operator $operator, mixed $role, mixed $other)

Returns the description of the failure when this constraint appears in context of an $operator expression.

string
toStringInContext(Operator $operator, mixed $role)

Returns a custom string representation of the constraint object when it appears in context of an $operator expression.

Exporter
exporter()

No description

__construct(ComparatorInterface $comparator, SelectionInterface $expected, RecursiveUnwrapperInterface $unwrapper)

No description

getSelection()

Returns an instance of SelectionInterface which defines expected values.

getComparator()

Returns an instance of ComparatorInterface which implements comparison operator.

bool|null
evaluate(mixed $other, string $description = '', bool $returnResult = false)

Evaluates the constraint for parameter $other.

bool
matches(mixed $other)

Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.

create(array $expected)

No description

static void
validateExpectations(array $expected, int $argument, int $distance = 1)

No description

makeSelector()

Creates instance of ArrayValueSelector.

makeComparator()

Creates instance of IdentityComparator.

Details

abstract string toString()

Returns a string representation of the constraint.

Return Value

string

final 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.

Parameters

mixed $other

evaluated value or object

Return Value

string

final string failureDescriptionInContext(Operator $operator, mixed $role, mixed $other)

Returns the description of the failure when this constraint appears in context of an $operator expression.

The purpose of this method is to provide meaningful failue description in context of operators such as LogicalNot. Native PHPUnit constraints are supported out of the box by LogicalNot, but externally developed ones had no way to provide correct messages in this context.

The method shall return empty string, when it does not handle customization by itself.

Parameters

Operator $operator

the $operator of the expression

mixed $role

role of $this constraint in the $operator expression

mixed $other

evaluated value or object

Return Value

string

abstract protected string toStringInContext(Operator $operator, mixed $role)

Returns a custom string representation of the constraint object when it appears in context of an $operator expression.

The purpose of this method is to provide meaningful descriptive string in context of operators such as LogicalNot. Native PHPUnit constraints are supported out of the box by LogicalNot, but externally developed ones had no way to provide correct strings in this context.

The method shall return empty string, when it does not handle customization by itself.

Parameters

Operator $operator

the $operator of the expression

mixed $role

role of $this constraint in the $operator expression

Return Value

string

abstract protected Exporter exporter()

No description

Return Value

Exporter

in AbstractConstraint at line 55
final protected __construct(ComparatorInterface $comparator, SelectionInterface $expected, RecursiveUnwrapperInterface $unwrapper)

No description

Parameters

ComparatorInterface $comparator
SelectionInterface $expected
RecursiveUnwrapperInterface $unwrapper

in AbstractConstraint at line 68
final SelectionInterface getSelection()

Returns an instance of SelectionInterface which defines expected values.

Return Value

SelectionInterface

in AbstractConstraint at line 76
final ComparatorInterface getComparator()

Returns an instance of ComparatorInterface which implements comparison operator.

Return Value

ComparatorInterface

in AbstractConstraint at line 112
final 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.

Parameters

mixed $other
string $description
bool $returnResult

Return Value

bool|null

Exceptions

ExpectationFailedException
InvalidArgumentException
CircularDependencyException

in AbstractConstraint at line 174
final protected bool matches(mixed $other)

Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.

Parameters

mixed $other

value or object to evaluate

Return Value

bool

static ConstraintImplementationTrait create(array $expected)

No description

Parameters

array $expected

Return Value

ConstraintImplementationTrait

Exceptions

InvalidArgumentException

static protected void validateExpectations(array $expected, int $argument, int $distance = 1)

No description

Parameters

array $expected
int $argument
int $distance

Return Value

void

at line 53
static protected ValueSelectorInterface makeSelector()

Creates instance of ArrayValueSelector.

Return Value

ValueSelectorInterface

at line 45
static protected ComparatorInterface makeComparator()

Creates instance of IdentityComparator.

Return Value

ComparatorInterface