Skip to content

Commit a44c71f

Browse files
committed
Restore PackedArray as invalid document in tests
1 parent 1b70949 commit a44c71f

19 files changed

+45
-25
lines changed

tests/Database/DatabaseFunctionalTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Database;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Collection;
67
use MongoDB\Database;
78
use MongoDB\Driver\BulkWrite;
@@ -124,7 +125,7 @@ public function testCommandAppliesTypeMapToCursor(): void
124125
/** @dataProvider provideInvalidDocumentValues */
125126
public function testCommandCommandArgumentTypeCheck($command): void
126127
{
127-
$this->expectException(TypeError::class);
128+
$this->expectException($command instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
128129
$this->database->command($command);
129130
}
130131

tests/Model/ChangeStreamIteratorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace MongoDB\Tests\Model;
99

10+
use MongoDB\BSON\PackedArray;
1011
use MongoDB\Collection;
1112
use MongoDB\Driver\Exception\LogicException;
13+
use MongoDB\Exception\InvalidArgumentException;
1214
use MongoDB\Model\ChangeStreamIterator;
1315
use MongoDB\Operation\Find;
1416
use MongoDB\Tests\CommandObserver;
@@ -51,7 +53,7 @@ public function testInitialResumeToken(): void
5153
/** @dataProvider provideInvalidDocumentValues */
5254
public function testInitialResumeTokenArgumentTypeCheck($initialResumeToken): void
5355
{
54-
$this->expectException(TypeError::class);
56+
$this->expectException($initialResumeToken instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
5557
new ChangeStreamIterator($this->collection->find(), 0, $initialResumeToken, null);
5658
}
5759

tests/Operation/BulkWriteTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Exception\InvalidArgumentException;
67
use MongoDB\Exception\UnsupportedValueException;
78
use MongoDB\Operation\BulkWrite;
@@ -288,7 +289,7 @@ public function testUpdateManyUpdateArgumentMissing(): void
288289
/** @dataProvider provideInvalidDocumentValues */
289290
public function testUpdateManyUpdateArgumentTypeCheck($update): void
290291
{
291-
$this->expectException(TypeError::class);
292+
$this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
292293
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
293294
[BulkWrite::UPDATE_MANY => [['x' => 1], $update]],
294295
]);
@@ -380,7 +381,7 @@ public function testUpdateOneUpdateArgumentMissing(): void
380381
/** @dataProvider provideInvalidDocumentValues */
381382
public function testUpdateOneUpdateArgumentTypeCheck($update): void
382383
{
383-
$this->expectException(TypeError::class);
384+
$this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
384385
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
385386
[BulkWrite::UPDATE_ONE => [['x' => 1], $update]],
386387
]);

tests/Operation/CountDocumentsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Exception\InvalidArgumentException;
67
use MongoDB\Operation\CountDocuments;
78
use TypeError;
@@ -11,7 +12,7 @@ class CountDocumentsTest extends TestCase
1112
/** @dataProvider provideInvalidDocumentValues */
1213
public function testConstructorFilterArgumentTypeCheck($filter): void
1314
{
14-
$this->expectException(TypeError::class);
15+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1516
new CountDocuments($this->getDatabaseName(), $this->getCollectionName(), $filter);
1617
}
1718

tests/Operation/CountTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Driver\ReadConcern;
67
use MongoDB\Exception\InvalidArgumentException;
78
use MongoDB\Operation\Count;
@@ -12,7 +13,7 @@ class CountTest extends TestCase
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorFilterArgumentTypeCheck($filter): void
1415
{
15-
$this->expectException(TypeError::class);
16+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1617
new Count($this->getDatabaseName(), $this->getCollectionName(), $filter);
1718
}
1819

tests/Operation/DatabaseCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Exception\InvalidArgumentException;
67
use MongoDB\Operation\DatabaseCommand;
78
use TypeError;
@@ -11,7 +12,7 @@ class DatabaseCommandTest extends TestCase
1112
/** @dataProvider provideInvalidDocumentValues */
1213
public function testConstructorCommandArgumentTypeCheck($command): void
1314
{
14-
$this->expectException(TypeError::class);
15+
$this->expectException($command instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1516
new DatabaseCommand($this->getDatabaseName(), $command);
1617
}
1718

tests/Operation/DeleteTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace MongoDB\Tests\Operation;
99

10+
use MongoDB\BSON\PackedArray;
1011
use MongoDB\Driver\WriteConcern;
1112
use MongoDB\Exception\InvalidArgumentException;
1213
use MongoDB\Operation\Delete;
@@ -17,7 +18,7 @@ class DeleteTest extends TestCase
1718
/** @dataProvider provideInvalidDocumentValues */
1819
public function testConstructorFilterArgumentTypeCheck($filter): void
1920
{
20-
$this->expectException(TypeError::class);
21+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
2122
new Delete($this->getDatabaseName(), $this->getCollectionName(), $filter, 0);
2223
}
2324

tests/Operation/DistinctTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Driver\ReadConcern;
67
use MongoDB\Driver\ReadPreference;
78
use MongoDB\Exception\InvalidArgumentException;
@@ -13,7 +14,7 @@ class DistinctTest extends TestCase
1314
/** @dataProvider provideInvalidDocumentValues */
1415
public function testConstructorFilterArgumentTypeCheck($filter): void
1516
{
16-
$this->expectException(TypeError::class);
17+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1718
new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', $filter);
1819
}
1920

tests/Operation/FindOneAndDeleteTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Driver\WriteConcern;
67
use MongoDB\Exception\InvalidArgumentException;
78
use MongoDB\Operation\FindOneAndDelete;
@@ -12,7 +13,7 @@ class FindOneAndDeleteTest extends TestCase
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorFilterArgumentTypeCheck($filter): void
1415
{
15-
$this->expectException(TypeError::class);
16+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1617
new FindOneAndDelete($this->getDatabaseName(), $this->getCollectionName(), $filter);
1718
}
1819

tests/Operation/FindOneAndReplaceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Driver\WriteConcern;
67
use MongoDB\Exception\InvalidArgumentException;
78
use MongoDB\Operation\FindOneAndReplace;
@@ -12,14 +13,14 @@ class FindOneAndReplaceTest extends TestCase
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorFilterArgumentTypeCheck($filter): void
1415
{
15-
$this->expectException(TypeError::class);
16+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1617
new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), $filter, []);
1718
}
1819

1920
/** @dataProvider provideInvalidDocumentValues */
2021
public function testConstructorReplacementArgumentTypeCheck($replacement): void
2122
{
22-
$this->expectException(TypeError::class);
23+
$this->expectException($replacement instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
2324
new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], $replacement);
2425
}
2526

tests/Operation/FindOneAndUpdateTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Driver\WriteConcern;
67
use MongoDB\Exception\InvalidArgumentException;
78
use MongoDB\Operation\FindOneAndUpdate;
@@ -12,14 +13,14 @@ class FindOneAndUpdateTest extends TestCase
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorFilterArgumentTypeCheck($filter): void
1415
{
15-
$this->expectException(TypeError::class);
16+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1617
new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), $filter, []);
1718
}
1819

1920
/** @dataProvider provideInvalidDocumentValues */
2021
public function testConstructorUpdateArgumentTypeCheck($update): void
2122
{
22-
$this->expectException(TypeError::class);
23+
$this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
2324
new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], $update);
2425
}
2526

tests/Operation/FindTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Driver\ReadConcern;
67
use MongoDB\Driver\ReadPreference;
78
use MongoDB\Exception\InvalidArgumentException;
@@ -13,7 +14,7 @@ class FindTest extends TestCase
1314
/** @dataProvider provideInvalidDocumentValues */
1415
public function testConstructorFilterArgumentTypeCheck($filter): void
1516
{
16-
$this->expectException(TypeError::class);
17+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1718
new Find($this->getDatabaseName(), $this->getCollectionName(), $filter);
1819
}
1920

tests/Operation/InsertOneTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Exception\InvalidArgumentException;
67
use MongoDB\Exception\UnsupportedValueException;
78
use MongoDB\Operation\InsertOne;
@@ -13,7 +14,7 @@ class InsertOneTest extends TestCase
1314
/** @dataProvider provideInvalidDocumentValues */
1415
public function testConstructorDocumentArgumentTypeCheck($document): void
1516
{
16-
$this->expectException(TypeError::class);
17+
$this->expectException($document instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1718
new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document);
1819
}
1920

tests/Operation/ReplaceOneTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Exception\InvalidArgumentException;
67
use MongoDB\Exception\UnsupportedValueException;
78
use MongoDB\Operation\ReplaceOne;
@@ -13,14 +14,14 @@ class ReplaceOneTest extends TestCase
1314
/** @dataProvider provideInvalidDocumentValues */
1415
public function testConstructorFilterArgumentTypeCheck($filter): void
1516
{
16-
$this->expectException(TypeError::class);
17+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1718
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['y' => 1]);
1819
}
1920

2021
/** @dataProvider provideInvalidDocumentValues */
2122
public function testConstructorReplacementArgumentTypeCheck($replacement): void
2223
{
23-
$this->expectException(TypeError::class);
24+
$this->expectException($replacement instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
2425
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement);
2526
}
2627

tests/Operation/UpdateManyTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Exception\InvalidArgumentException;
67
use MongoDB\Operation\UpdateMany;
78
use TypeError;
@@ -11,14 +12,14 @@ class UpdateManyTest extends TestCase
1112
/** @dataProvider provideInvalidDocumentValues */
1213
public function testConstructorFilterArgumentTypeCheck($filter): void
1314
{
14-
$this->expectException(TypeError::class);
15+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1516
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
1617
}
1718

1819
/** @dataProvider provideInvalidDocumentValues */
1920
public function testConstructorUpdateArgumentTypeCheck($update): void
2021
{
21-
$this->expectException(TypeError::class);
22+
$this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
2223
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
2324
}
2425

tests/Operation/UpdateOneTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Exception\InvalidArgumentException;
67
use MongoDB\Operation\UpdateOne;
78
use TypeError;
@@ -11,14 +12,14 @@ class UpdateOneTest extends TestCase
1112
/** @dataProvider provideInvalidDocumentValues */
1213
public function testConstructorFilterArgumentTypeCheck($filter): void
1314
{
14-
$this->expectException(TypeError::class);
15+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1516
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
1617
}
1718

1819
/** @dataProvider provideInvalidDocumentValues */
1920
public function testConstructorUpdateArgumentTypeCheck($update): void
2021
{
21-
$this->expectException(TypeError::class);
22+
$this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
2223
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
2324
}
2425

tests/Operation/UpdateSearchIndexTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Exception\InvalidArgumentException;
67
use MongoDB\Operation\UpdateSearchIndex;
78
use TypeError;
@@ -17,7 +18,7 @@ public function testConstructorIndexNameMustNotBeEmpty(): void
1718
/** @dataProvider provideInvalidDocumentValues */
1819
public function testConstructorIndexDefinitionMustBeADocument($definition): void
1920
{
20-
$this->expectException(TypeError::class);
21+
$this->expectException($definition instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
2122
new UpdateSearchIndex($this->getDatabaseName(), $this->getCollectionName(), 'index name', $definition);
2223
}
2324
}

tests/Operation/UpdateTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MongoDB\Tests\Operation;
44

5+
use MongoDB\BSON\PackedArray;
56
use MongoDB\Driver\WriteConcern;
67
use MongoDB\Exception\InvalidArgumentException;
78
use MongoDB\Operation\Update;
@@ -12,7 +13,7 @@ class UpdateTest extends TestCase
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorFilterArgumentTypeCheck($filter): void
1415
{
15-
$this->expectException(TypeError::class);
16+
$this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class);
1617
new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
1718
}
1819

tests/TestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use InvalidArgumentException;
66
use MongoDB\BSON\Document;
7+
use MongoDB\BSON\PackedArray;
78
use MongoDB\Codec\Codec;
89
use MongoDB\Driver\ReadConcern;
910
use MongoDB\Driver\ReadPreference;
@@ -224,7 +225,7 @@ protected function getInvalidBooleanValues(bool $includeNull = false): array
224225
*/
225226
protected function getInvalidDocumentValues(bool $includeNull = false): array
226227
{
227-
return array_merge([123, 3.14, 'foo', true], $includeNull ? [null] : []);
228+
return array_merge([123, 3.14, 'foo', true, PackedArray::fromPHP([])], $includeNull ? [null] : []);
228229
}
229230

230231
protected function getInvalidDocumentCodecValues(): array

0 commit comments

Comments
 (0)