Skip to content

Commit

Permalink
Fix psalm build
Browse files Browse the repository at this point in the history
These new errors are because a bug in psalm with get_class
see vimeo/psalm#9607, they will be
gone once we use ::class
  • Loading branch information
franmomu committed Apr 5, 2023
1 parent ae67490 commit 6c94ac4
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 111 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"doctrine/coding-standard": "^11.0",
"jmikola/geojson": "^1.0",
"phpbench/phpbench": "^1.0.0@dev",
"phpstan/phpstan": "^1.9.4",
"phpstan/phpstan": "^1.10.11",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5.5 || ^10.0.15",
"squizlabs/php_codesniffer": "^3.5",
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
"vimeo/psalm": "^5.7.7"
"vimeo/psalm": "^5.9.0"
},
"suggest": {
"ext-bcmath": "Decimal128 type support"
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ parameters:
path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

-
message: "#^Parameter \\#2 \\$options of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:addIndex\\(\\) expects array\\{background\\?\\: bool, bits\\?\\: int, default_language\\?\\: string, expireAfterSeconds\\?\\: int, language_override\\?\\: string, min\\?\\: float, max\\?\\: float, name\\?\\: string, \\.\\.\\.\\}, array\\<string, non\\-empty\\-array\\<string, array\\<int\\|string, mixed\\>\\|bool\\|float\\|int\\|string\\|null\\>\\|bool\\|float\\|int\\|string\\|null\\> given\\.$#"
message: "#^Parameter \\#2 \\$options of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:addIndex\\(\\) expects array\\{background\\?\\: bool, bits\\?\\: int, default_language\\?\\: string, expireAfterSeconds\\?\\: int, language_override\\?\\: string, min\\?\\: float, max\\?\\: float, name\\?\\: string, \\.\\.\\.\\}, array\\<string, non\\-empty\\-array\\<string, array\\<int\\<0, max\\>\\|string, mixed\\>\\|bool\\|float\\|int\\|string\\|null\\>\\|bool\\|float\\|int\\|string\\|null\\> given\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

Expand Down
310 changes: 205 additions & 105 deletions psalm-baseline.xml

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<file name="lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup/Match.php" />
<file name="lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php" />
<file name="tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/User.php" />
<!-- Remove CollWithPHP81Types once Psalm supports native intersection https://github.com/vimeo/psalm/issues/6413 -->
<file name="tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/DefaultPersistentCollectionGeneratorTest.php" />
<file name="tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP81Types.php" />
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
Expand Down
3 changes: 3 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,20 @@ public function testDifferentStoreAsDbReferences(): void
self::assertInstanceOf(ObjectId::class, $dbRef);

$dbRef = $this->dm->createReference($r, $class->associationMappings['ref2']);
self::assertIsArray($dbRef);
self::assertCount(2, $dbRef);
self::assertArrayHasKey('$ref', $dbRef);
self::assertArrayHasKey('$id', $dbRef);

$dbRef = $this->dm->createReference($r, $class->associationMappings['ref3']);
self::assertIsArray($dbRef);
self::assertCount(3, $dbRef);
self::assertArrayHasKey('$ref', $dbRef);
self::assertArrayHasKey('$id', $dbRef);
self::assertArrayHasKey('$db', $dbRef);

$dbRef = $this->dm->createReference($r, $class->associationMappings['ref4']);
self::assertIsArray($dbRef);
self::assertCount(1, $dbRef);
self::assertArrayHasKey('id', $dbRef);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ public function testPrimeReferencesInvokesPrimer(): void
$this->dm->flush();
$this->dm->clear();

/** @var array<int, array<int, mixed>> $invokedArgs */
$invokedArgs = [];
$primer = static function (DocumentManager $dm, ClassMetadata $class, array $ids, array $hints) use (&$invokedArgs) {
$invokedArgs[] = func_get_args();
Expand All @@ -395,6 +396,8 @@ public function testPrimeReferencesInvokesPrimer(): void
->getQuery()
->toArray();

self::assertIsArray($invokedArgs[0]);
self::assertIsArray($invokedArgs[1]);
self::assertCount(2, $invokedArgs, 'Primer was invoked once for each referenced class.');
self::assertArrayHasKey(Query::HINT_READ_PREFERENCE, $invokedArgs[0][3], 'Primer was invoked with UnitOfWork hints from original query.');
self::assertSame($readPreference, $invokedArgs[0][3][Query::HINT_READ_PREFERENCE], 'Primer was invoked with UnitOfWork hints from original query.');
Expand Down
3 changes: 3 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/ShardKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function testUpdateAfterSave(): void
self::assertSame('update', $lastQuery->getCommandName());

$command = $lastQuery->getCommand();
self::assertIsArray($command->updates);
self::assertCount(1, $command->updates);
self::assertEquals($o->key, $command->updates[0]->q->k);
}
Expand All @@ -71,6 +72,7 @@ public function testUpsert(): void
self::assertSame('update', $lastQuery->getCommandName());

$command = $lastQuery->getCommand();
self::assertIsArray($command->updates);
self::assertCount(1, $command->updates);
self::assertEquals($o->key, $command->updates[0]->q->k);
self::assertTrue($command->updates[0]->upsert);
Expand All @@ -89,6 +91,7 @@ public function testRemove(): void
self::assertSame('delete', $lastQuery->getCommandName());

$command = $lastQuery->getCommand();
self::assertIsArray($command->deletes);
self::assertCount(1, $command->deletes);
self::assertEquals($o->key, $command->deletes[0]->q->k);
}
Expand Down

0 comments on commit 6c94ac4

Please sign in to comment.