|
6 | 6 | use MongoDB\BSON\Regex;
|
7 | 7 | use MongoDB\Driver\ReadPreference;
|
8 | 8 | use Alcaeus\MongoDbAdapter\Tests\TestCase;
|
9 |
| -use MongoId; |
10 |
| -use PHPUnit\Framework\Error\Warning; |
11 | 9 | use function extension_loaded;
|
12 | 10 | use function strcasecmp;
|
13 | 11 |
|
@@ -56,12 +54,21 @@ public function testCreateRecord()
|
56 | 54 |
|
57 | 55 | public function testInsertInvalidData()
|
58 | 56 | {
|
| 57 | + // Workaround for PHPUnit 10 |
| 58 | + set_error_handler(static function ($errno, $errstr) { |
| 59 | + throw new \Exception($errstr, $errno); |
| 60 | + }, E_ALL); |
| 61 | + |
59 | 62 | // Dirty hack to support both PHPUnit 5.x and 6.x
|
60 |
| - $this->expectWarning(); |
61 |
| - $this->expectWarningMessage('MongoCollection::insert(): expects parameter 1 to be an array or object, integer given'); |
| 63 | + $this->expectException(\Exception::class); |
| 64 | + $this->expectExceptionMessage('MongoCollection::insert(): expects parameter 1 to be an array or object, integer given'); |
62 | 65 |
|
63 |
| - $document = 8; |
64 |
| - $this->getCollection()->insert($document); |
| 66 | + try { |
| 67 | + $document = 8; |
| 68 | + $this->getCollection()->insert($document); |
| 69 | + } finally { |
| 70 | + restore_error_handler(); |
| 71 | + } |
65 | 72 | }
|
66 | 73 |
|
67 | 74 | public function testInsertEmptyArray()
|
@@ -195,7 +202,7 @@ public function testInsertDuplicate()
|
195 | 202 | unset($document['_id']);
|
196 | 203 |
|
197 | 204 | $this->expectException(\MongoDuplicateKeyException::class);
|
198 |
| - $this->expectErrorMessageMatches('/E11000 duplicate key error .* mongo-php-adapter\.test/'); |
| 205 | + $this->expectExceptionMessageMatches('/E11000 duplicate key error .* mongo-php-adapter\.test/'); |
199 | 206 | $this->expectExceptionCode(11000);
|
200 | 207 | $collection->insert($document);
|
201 | 208 | }
|
@@ -303,7 +310,7 @@ public function testBatchInsertException()
|
303 | 310 | $documents = [['_id' => $id, 'foo' => 'bar'], ['_id' => $id, 'foo' => 'bleh']];
|
304 | 311 |
|
305 | 312 | $this->expectException(\MongoDuplicateKeyException::class);
|
306 |
| - $this->expectErrorMessageMatches('/E11000 duplicate key error .* mongo-php-adapter.test.*_id_/'); |
| 313 | + $this->expectExceptionMessageMatches('/E11000 duplicate key error .* mongo-php-adapter.test.*_id_/'); |
307 | 314 | $this->expectExceptionCode(11000);
|
308 | 315 |
|
309 | 316 | $this->getCollection()->batchInsert($documents);
|
@@ -415,7 +422,7 @@ public function testUpdateReplaceOne()
|
415 | 422 | public function testUpdateReplaceMultiple()
|
416 | 423 | {
|
417 | 424 | $this->expectException(\MongoWriteConcernException::class);
|
418 |
| - $this->expectErrorMessageMatches('/multi update only works with \$ operators/', 9); |
| 425 | + $this->expectExceptionMessageMatches('/multi update only works with \$ operators/', 9); |
419 | 426 | $this->getCollection()->update(['foo' => 'bar'], ['foo' => 'foo'], ['multiple' => true]);
|
420 | 427 | }
|
421 | 428 |
|
|
0 commit comments