Skip to content

Commit

Permalink
Expect BulkWriteException
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Sep 25, 2024
1 parent 9f4c1c8 commit d09eb5e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions tests/UnifiedSpecTests/ExpectedError.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use MongoDB\Driver\Exception\ExecutionTimeoutException;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Exception\ServerException;
use MongoDB\Driver\Exception\WriteException;
use MongoDB\Tests\UnifiedSpecTests\Constraint\Matches;
use PHPUnit\Framework\Assert;
use stdClass;
Expand Down Expand Up @@ -157,14 +156,14 @@ public function assert(?Throwable $e = null): void
}

if (isset($this->matchesResultDocument)) {
assertThat($e, logicalOr(isInstanceOf(CommandException::class), isInstanceOf(WriteException::class)));
assertThat($e, logicalOr(isInstanceOf(CommandException::class), isInstanceOf(BulkWriteException::class)));

if ($e instanceof CommandException) {
assertThat($e->getResultDocument(), $this->matchesResultDocument, 'CommandException result document matches');
} elseif ($e instanceof WriteException) {
} elseif ($e instanceof BulkWriteException) {
$writeErrors = $e->getWriteResult()->getErrorReplies();
assertCount(1, $writeErrors);
assertThat($writeErrors[0], $this->matchesResultDocument, 'WriteException result document matches');
assertThat($writeErrors[0], $this->matchesResultDocument, 'BulkWriteException result document matches');
}
}

Expand Down

0 comments on commit d09eb5e

Please sign in to comment.