Skip to content

Commit ccfc769

Browse files
committed
Remove unnecessary type assertions
1 parent a3082cd commit ccfc769

24 files changed

+49
-44
lines changed

src/Operation/FindOneAndUpdate.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
use MongoDB\Exception\UnsupportedException;
2424

2525
use function array_key_exists;
26-
use function is_array;
2726
use function is_integer;
28-
use function is_object;
2927
use function MongoDB\is_document;
3028
use function MongoDB\is_first_key_operator;
3129
use function MongoDB\is_pipeline;

src/Operation/UpdateMany.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
use MongoDB\Exception\UnsupportedException;
2424
use MongoDB\UpdateResult;
2525

26-
use function is_array;
27-
use function is_object;
2826
use function MongoDB\is_first_key_operator;
2927
use function MongoDB\is_pipeline;
3028

src/Operation/UpdateOne.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
use MongoDB\Exception\UnsupportedException;
2424
use MongoDB\UpdateResult;
2525

26-
use function is_array;
27-
use function is_object;
2826
use function MongoDB\is_first_key_operator;
2927
use function MongoDB\is_pipeline;
3028

tests/Database/DatabaseFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function testCommandAppliesTypeMapToCursor(): void
124124
/** @dataProvider provideInvalidDocumentValues */
125125
public function testCommandCommandArgumentTypeCheck($command): void
126126
{
127-
$this->expectException(InvalidArgumentException::class);
127+
$this->expectException(TypeError::class);
128128
$this->database->command($command);
129129
}
130130

tests/FunctionsTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use MongoDB\BSON\Document;
66
use MongoDB\BSON\PackedArray;
77
use MongoDB\Driver\WriteConcern;
8-
use MongoDB\Exception\InvalidArgumentException;
98
use MongoDB\Model\BSONArray;
109
use MongoDB\Model\BSONDocument;
10+
use TypeError;
1111

1212
use function MongoDB\apply_type_map_to_document;
1313
use function MongoDB\create_field_path_type_map;
@@ -115,8 +115,7 @@ public function provideDocumentsAndExpectedArrays(): array
115115
/** @dataProvider provideInvalidDocumentValuesForChecks */
116116
public function testDocumentToArrayArgumentTypeCheck($document): void
117117
{
118-
$this->expectException(InvalidArgumentException::class);
119-
$this->expectExceptionMessage('Expected $document to have type "document" (array or object)');
118+
$this->expectException(TypeError::class);
120119
document_to_array($document);
121120
}
122121

@@ -154,7 +153,7 @@ public function testIsFirstKeyOperator(callable $cast): void
154153
/** @dataProvider provideInvalidDocumentValuesForChecks */
155154
public function testIsFirstKeyOperatorArgumentTypeCheck($document): void
156155
{
157-
$this->expectException(InvalidArgumentException::class);
156+
$this->expectException(TypeError::class);
158157
is_first_key_operator($document);
159158
}
160159

tests/Model/ChangeStreamIteratorTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use MongoDB\Collection;
1111
use MongoDB\Driver\Exception\LogicException;
12-
use MongoDB\Exception\InvalidArgumentException;
1312
use MongoDB\Model\ChangeStreamIterator;
1413
use MongoDB\Operation\Find;
1514
use MongoDB\Tests\CommandObserver;
@@ -52,7 +51,7 @@ public function testInitialResumeToken(): void
5251
/** @dataProvider provideInvalidDocumentValues */
5352
public function testInitialResumeTokenArgumentTypeCheck($initialResumeToken): void
5453
{
55-
$this->expectException(InvalidArgumentException::class);
54+
$this->expectException(TypeError::class);
5655
new ChangeStreamIterator($this->collection->find(), 0, $initialResumeToken, null);
5756
}
5857

tests/Operation/BulkWriteTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use MongoDB\Exception\UnsupportedValueException;
77
use MongoDB\Operation\BulkWrite;
88
use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec;
9+
use TypeError;
910

1011
class BulkWriteTest extends TestCase
1112
{
@@ -287,8 +288,7 @@ public function testUpdateManyUpdateArgumentMissing(): void
287288
/** @dataProvider provideInvalidDocumentValues */
288289
public function testUpdateManyUpdateArgumentTypeCheck($update): void
289290
{
290-
$this->expectException(InvalidArgumentException::class);
291-
$this->expectExceptionMessage('Expected update operator(s) or non-empty pipeline for $operations[0]["updateMany"][1]');
291+
$this->expectException(TypeError::class);
292292
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
293293
[BulkWrite::UPDATE_MANY => [['x' => 1], $update]],
294294
]);
@@ -380,8 +380,7 @@ public function testUpdateOneUpdateArgumentMissing(): void
380380
/** @dataProvider provideInvalidDocumentValues */
381381
public function testUpdateOneUpdateArgumentTypeCheck($update): void
382382
{
383-
$this->expectException(InvalidArgumentException::class);
384-
$this->expectExceptionMessage('Expected update operator(s) or non-empty pipeline for $operations[0]["updateOne"][1]');
383+
$this->expectException(TypeError::class);
385384
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
386385
[BulkWrite::UPDATE_ONE => [['x' => 1], $update]],
387386
]);

tests/Operation/CountDocumentsTest.php

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

55
use MongoDB\Exception\InvalidArgumentException;
66
use MongoDB\Operation\CountDocuments;
7+
use TypeError;
78

89
class CountDocumentsTest extends TestCase
910
{
1011
/** @dataProvider provideInvalidDocumentValues */
1112
public function testConstructorFilterArgumentTypeCheck($filter): void
1213
{
13-
$this->expectException(InvalidArgumentException::class);
14+
$this->expectException(TypeError::class);
1415
new CountDocuments($this->getDatabaseName(), $this->getCollectionName(), $filter);
1516
}
1617

tests/Operation/CountTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
use MongoDB\Driver\ReadConcern;
66
use MongoDB\Exception\InvalidArgumentException;
77
use MongoDB\Operation\Count;
8+
use TypeError;
89

910
class CountTest extends TestCase
1011
{
1112
/** @dataProvider provideInvalidDocumentValues */
1213
public function testConstructorFilterArgumentTypeCheck($filter): void
1314
{
14-
$this->expectException(InvalidArgumentException::class);
15+
$this->expectException(TypeError::class);
1516
new Count($this->getDatabaseName(), $this->getCollectionName(), $filter);
1617
}
1718

tests/Operation/DatabaseCommandTest.php

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

55
use MongoDB\Exception\InvalidArgumentException;
66
use MongoDB\Operation\DatabaseCommand;
7+
use TypeError;
78

89
class DatabaseCommandTest extends TestCase
910
{
1011
/** @dataProvider provideInvalidDocumentValues */
1112
public function testConstructorCommandArgumentTypeCheck($command): void
1213
{
13-
$this->expectException(InvalidArgumentException::class);
14+
$this->expectException(TypeError::class);
1415
new DatabaseCommand($this->getDatabaseName(), $command);
1516
}
1617

tests/Operation/DeleteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DeleteTest extends TestCase
1717
/** @dataProvider provideInvalidDocumentValues */
1818
public function testConstructorFilterArgumentTypeCheck($filter): void
1919
{
20-
$this->expectException(InvalidArgumentException::class);
20+
$this->expectException(TypeError::class);
2121
new Delete($this->getDatabaseName(), $this->getCollectionName(), $filter, 0);
2222
}
2323

tests/Operation/DistinctTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
use MongoDB\Driver\ReadPreference;
77
use MongoDB\Exception\InvalidArgumentException;
88
use MongoDB\Operation\Distinct;
9+
use TypeError;
910

1011
class DistinctTest extends TestCase
1112
{
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorFilterArgumentTypeCheck($filter): void
1415
{
15-
$this->expectException(InvalidArgumentException::class);
16+
$this->expectException(TypeError::class);
1617
new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', $filter);
1718
}
1819

tests/Operation/FindOneAndDeleteTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
use MongoDB\Driver\WriteConcern;
66
use MongoDB\Exception\InvalidArgumentException;
77
use MongoDB\Operation\FindOneAndDelete;
8+
use TypeError;
89

910
class FindOneAndDeleteTest extends TestCase
1011
{
1112
/** @dataProvider provideInvalidDocumentValues */
1213
public function testConstructorFilterArgumentTypeCheck($filter): void
1314
{
14-
$this->expectException(InvalidArgumentException::class);
15+
$this->expectException(TypeError::class);
1516
new FindOneAndDelete($this->getDatabaseName(), $this->getCollectionName(), $filter);
1617
}
1718

tests/Operation/FindOneAndReplaceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
use MongoDB\Driver\WriteConcern;
66
use MongoDB\Exception\InvalidArgumentException;
77
use MongoDB\Operation\FindOneAndReplace;
8+
use TypeError;
89

910
class FindOneAndReplaceTest extends TestCase
1011
{
1112
/** @dataProvider provideInvalidDocumentValues */
1213
public function testConstructorFilterArgumentTypeCheck($filter): void
1314
{
14-
$this->expectException(InvalidArgumentException::class);
15+
$this->expectException(TypeError::class);
1516
new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), $filter, []);
1617
}
1718

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

tests/Operation/FindOneAndUpdateTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
use MongoDB\Driver\WriteConcern;
66
use MongoDB\Exception\InvalidArgumentException;
77
use MongoDB\Operation\FindOneAndUpdate;
8+
use TypeError;
89

910
class FindOneAndUpdateTest extends TestCase
1011
{
1112
/** @dataProvider provideInvalidDocumentValues */
1213
public function testConstructorFilterArgumentTypeCheck($filter): void
1314
{
14-
$this->expectException(InvalidArgumentException::class);
15+
$this->expectException(TypeError::class);
1516
new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), $filter, []);
1617
}
1718

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

tests/Operation/FindTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
use MongoDB\Driver\ReadPreference;
77
use MongoDB\Exception\InvalidArgumentException;
88
use MongoDB\Operation\Find;
9+
use TypeError;
910

1011
class FindTest extends TestCase
1112
{
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorFilterArgumentTypeCheck($filter): void
1415
{
15-
$this->expectException(InvalidArgumentException::class);
16+
$this->expectException(TypeError::class);
1617
new Find($this->getDatabaseName(), $this->getCollectionName(), $filter);
1718
}
1819

tests/Operation/InsertOneTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
use MongoDB\Exception\UnsupportedValueException;
77
use MongoDB\Operation\InsertOne;
88
use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec;
9+
use TypeError;
910

1011
class InsertOneTest extends TestCase
1112
{
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorDocumentArgumentTypeCheck($document): void
1415
{
15-
$this->expectException(InvalidArgumentException::class);
16+
$this->expectException(TypeError::class);
1617
new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document);
1718
}
1819

tests/Operation/MapReduceTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MongoDB\Tests\Operation;
46

57
use MongoDB\BSON\Document;
@@ -9,6 +11,7 @@
911
use MongoDB\Model\BSONDocument;
1012
use MongoDB\Operation\MapReduce;
1113
use stdClass;
14+
use TypeError;
1215

1316
class MapReduceTest extends TestCase
1417
{
@@ -18,7 +21,7 @@ public function testConstructorOutArgumentTypeCheck($out): void
1821
$map = new Javascript('function() { emit(this.x, this.y); }');
1922
$reduce = new Javascript('function(key, values) { return Array.sum(values); }');
2023

21-
$this->expectException(InvalidArgumentException::class);
24+
$this->expectException(TypeError::class);
2225
new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out);
2326
}
2427

tests/Operation/ReplaceOneTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
use MongoDB\Exception\UnsupportedValueException;
77
use MongoDB\Operation\ReplaceOne;
88
use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec;
9+
use TypeError;
910

1011
class ReplaceOneTest extends TestCase
1112
{
1213
/** @dataProvider provideInvalidDocumentValues */
1314
public function testConstructorFilterArgumentTypeCheck($filter): void
1415
{
15-
$this->expectException(InvalidArgumentException::class);
16+
$this->expectException(TypeError::class);
1617
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['y' => 1]);
1718
}
1819

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

tests/Operation/UpdateManyTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44

55
use MongoDB\Exception\InvalidArgumentException;
66
use MongoDB\Operation\UpdateMany;
7+
use TypeError;
78

89
class UpdateManyTest extends TestCase
910
{
1011
/** @dataProvider provideInvalidDocumentValues */
1112
public function testConstructorFilterArgumentTypeCheck($filter): void
1213
{
13-
$this->expectException(InvalidArgumentException::class);
14+
$this->expectException(TypeError::class);
1415
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
1516
}
1617

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

tests/Operation/UpdateOneTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44

55
use MongoDB\Exception\InvalidArgumentException;
66
use MongoDB\Operation\UpdateOne;
7+
use TypeError;
78

89
class UpdateOneTest extends TestCase
910
{
1011
/** @dataProvider provideInvalidDocumentValues */
1112
public function testConstructorFilterArgumentTypeCheck($filter): void
1213
{
13-
$this->expectException(InvalidArgumentException::class);
14+
$this->expectException(TypeError::class);
1415
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
1516
}
1617

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

tests/Operation/UpdateSearchIndexTest.php

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

55
use MongoDB\Exception\InvalidArgumentException;
66
use MongoDB\Operation\UpdateSearchIndex;
7+
use TypeError;
78

89
class UpdateSearchIndexTest extends TestCase
910
{
@@ -16,8 +17,7 @@ public function testConstructorIndexNameMustNotBeEmpty(): void
1617
/** @dataProvider provideInvalidDocumentValues */
1718
public function testConstructorIndexDefinitionMustBeADocument($definition): void
1819
{
19-
$this->expectException(InvalidArgumentException::class);
20-
$this->expectExceptionMessage('Expected $definition to have type "document"');
20+
$this->expectException(TypeError::class);
2121
new UpdateSearchIndex($this->getDatabaseName(), $this->getCollectionName(), 'index name', $definition);
2222
}
2323
}

0 commit comments

Comments
 (0)