Skip to content

Commit 88bf036

Browse files
committed
Use DocumentsMatchConstraint in assertMatchesDocument method
1 parent 020d4b9 commit 88bf036

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

tests/TestCase.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use MongoDB\Driver\WriteConcern;
1212
use MongoDB\Model\BSONArray;
1313
use MongoDB\Model\BSONDocument;
14+
use MongoDB\Tests\SpecTests\DocumentsMatchConstraint;
1415
use PHPUnit\Framework\TestCase as BaseTestCase;
1516
use ReflectionClass;
1617
use stdClass;
@@ -96,27 +97,7 @@ protected static function getDatabaseName(): string
9697
*/
9798
public function assertMatchesDocument($expectedDocument, $actualDocument): void
9899
{
99-
$normalizedExpectedDocument = $this->normalizeBSON($expectedDocument);
100-
$normalizedActualDocument = $this->normalizeBSON($actualDocument);
101-
102-
$extraKeys = [];
103-
104-
/* Avoid unsetting fields while we're iterating on the ArrayObject to
105-
* work around https://bugs.php.net/bug.php?id=70246 */
106-
foreach ($normalizedActualDocument as $key => $value) {
107-
if (! $normalizedExpectedDocument->offsetExists($key)) {
108-
$extraKeys[] = $key;
109-
}
110-
}
111-
112-
foreach ($extraKeys as $key) {
113-
$normalizedActualDocument->offsetUnset($key);
114-
}
115-
116-
$this->assertEquals(
117-
Document::fromPHP($normalizedExpectedDocument)->toRelaxedExtendedJSON(),
118-
Document::fromPHP($normalizedActualDocument)->toRelaxedExtendedJSON(),
119-
);
100+
(new DocumentsMatchConstraint($expectedDocument, true, true))->evaluate($actualDocument);
120101
}
121102

122103
/**

0 commit comments

Comments
 (0)