Skip to content

Commit 0c9d130

Browse files
committed
PHPLIB-711: Unwrap BulkWriteException when evaluating isClientError
1 parent cefb05d commit 0c9d130

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests/UnifiedSpecTests/ExpectedError.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ public function assert(?Throwable $e = null): void
137137
assertNotNull($e);
138138

139139
if (isset($this->isClientError)) {
140-
if ($this->isClientError) {
141-
assertNotInstanceOf(ServerException::class, $e);
142-
} else {
143-
assertInstanceOf(ServerException::class, $e);
144-
}
140+
$this->assertIsClientError($e);
145141
}
146142

147143
if (isset($this->messageContains)) {
@@ -176,6 +172,21 @@ public function assert(?Throwable $e = null): void
176172
}
177173
}
178174

175+
private function assertIsClientError(Throwable $e): void
176+
{
177+
/* Note: BulkWriteException may proxy a previous exception. Unwrap it
178+
* to check the original error. */
179+
if ($e instanceof BulkWriteException && $e->getPrevious() !== null) {
180+
$e = $e->getPrevious();
181+
}
182+
183+
if ($this->isClientError) {
184+
assertNotInstanceOf(ServerException::class, $e);
185+
} else {
186+
assertInstanceOf(ServerException::class, $e);
187+
}
188+
}
189+
179190
private function assertCodeName(ServerException $e): void
180191
{
181192
/* BulkWriteException and ExecutionTimeoutException do not expose

0 commit comments

Comments
 (0)