yxorP Documentation

DocumentsMatchConstraint extends Constraint
in package
Uses ConstraintTrait

Constraint that checks if one document matches another.

The expected value is passed in the constructor.

Table of Contents

$comparatorFactory  : Factory
$ignoreExtraKeysInEmbedded  : bool
$ignoreExtraKeysInRoot  : bool
$lastFailure  : ComparisonFailure|null
$placeholders  : array<string|int, mixed>
$sortKeys  : bool
TODO: This is not currently used, but was preserved from the design of TestCase::assertMatchesDocument(), which would sort keys and then compare documents as JSON strings. If the TODO item in matches() is implemented to make document comparisons more efficient, we may consider supporting this option.
$value  : BSONArray|BSONDocument
__construct()  : mixed
Creates a new constraint.
assertBSONType()  : void
assertEquals()  : void
Compares two documents recursively.
doAdditionalFailureDescription()  : mixed
doEvaluate()  : mixed
doFailureDescription()  : mixed
doMatches()  : mixed
doToString()  : mixed
prepareBSON()  : BSONDocument|BSONArray
Prepare a BSON document or array for comparison.

Properties

$sortKeys

TODO: This is not currently used, but was preserved from the design of TestCase::assertMatchesDocument(), which would sort keys and then compare documents as JSON strings. If the TODO item in matches() is implemented to make document comparisons more efficient, we may consider supporting this option.

private bool $sortKeys = false

Methods

__construct()

Creates a new constraint.

public __construct(array<string|int, mixed>|object $value[, bool $ignoreExtraKeysInRoot = false ][, bool $ignoreExtraKeysInEmbedded = false ][, array<string|int, mixed> $placeholders = [] ]) : mixed
Parameters
$value : array<string|int, mixed>|object
$ignoreExtraKeysInRoot : bool = false

If true, ignore extra keys within the root document

$ignoreExtraKeysInEmbedded : bool = false

If true, ignore extra keys within embedded documents

$placeholders : array<string|int, mixed> = []

Placeholders for any value

Return values
mixed

assertBSONType()

private assertBSONType(string $expectedType, mixed $actualValue) : void
Parameters
$expectedType : string
$actualValue : mixed
Return values
void

assertEquals()

Compares two documents recursively.

private assertEquals(ArrayObject $expected, ArrayObject $actual, bool $ignoreExtraKeys[, string $keyPrefix = '' ]) : void
Parameters
$expected : ArrayObject
$actual : ArrayObject
$ignoreExtraKeys : bool
$keyPrefix : string = ''
Tags
throws
RuntimeException

if the documents do not match

Return values
void

doAdditionalFailureDescription()

private doAdditionalFailureDescription(mixed $other) : mixed
Parameters
$other : mixed
Return values
mixed

doEvaluate()

private doEvaluate(mixed $other[, mixed $description = '' ][, mixed $returnResult = false ]) : mixed
Parameters
$other : mixed
$description : mixed = ''
$returnResult : mixed = false
Return values
mixed

doFailureDescription()

private doFailureDescription(mixed $other) : mixed
Parameters
$other : mixed
Return values
mixed

prepareBSON()

Prepare a BSON document or array for comparison.

private prepareBSON(array<string|int, mixed>|object $bson, bool $isRoot[, bool $sortKeys = false ]) : BSONDocument|BSONArray

The argument will be converted to a BSONArray or BSONDocument based on its type and keys. Keys within documents will optionally be sorted. Each value within the array or document will then be prepared recursively.

Parameters
$bson : array<string|int, mixed>|object
$isRoot : bool

If true, ensure an array value is converted to a document

$sortKeys : bool = false
Tags
throws
InvalidArgumentException

if $bson is not an array or object

Return values
BSONDocument|BSONArray

Search results