Skip to content

Commit

Permalink
Specify IndexOptions keys
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Nov 5, 2022
1 parent 5295286 commit fee2938
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
10 changes: 9 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,15 @@
* alsoLoadFields?: list<string>,
* }
* @psalm-type IndexKeys = array<string, mixed>
* @psalm-type IndexOptions = array<string, mixed>
* @psalm-type IndexOptions = array{
* background?: bool,
* unique?: bool,
* name?: string,
* partialFilterExpression?: mixed[],
* sparse?: bool,
* expireAfterSeconds?: int,
* storageEngine?: mixed[],
* }
* @psalm-type IndexMapping = array{
* keys: IndexKeys,
* options: IndexOptions
Expand Down
3 changes: 2 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
</LessSpecificImplementedReturnType>
</file>
<file src="lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php">
<InvalidArgument occurrences="2">
<InvalidArgument occurrences="3">
<code>$mapping</code>
<code>$mapping</code>
<code>$options</code>
</InvalidArgument>
<RedundantCondition occurrences="15">
<code>assert($attributes instanceof SimpleXMLElement)</code>
Expand Down
45 changes: 23 additions & 22 deletions tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

/**
* @psalm-import-type IndexMapping from ClassMetadata
* @psalm-import-type IndexOptions from ClassMetadata
*/
class SchemaManagerTest extends BaseTest
{
Expand Down Expand Up @@ -161,7 +162,7 @@ public static function getIndexCreationWriteOptions(): array
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getIndexCreationWriteOptions
*/
Expand Down Expand Up @@ -210,7 +211,7 @@ public function testEnsureIndexes(array $expectedWriteOptions, ?int $maxTimeMs,
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getIndexCreationWriteOptions
*/
Expand All @@ -232,7 +233,7 @@ public function testEnsureDocumentIndexes(array $expectedWriteOptions, ?int $max
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getIndexCreationWriteOptions
*/
Expand Down Expand Up @@ -276,7 +277,7 @@ public function testEnsureDocumentIndexesForGridFSFile(array $expectedWriteOptio
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getIndexCreationWriteOptions
*/
Expand All @@ -293,7 +294,7 @@ public function testEnsureDocumentIndexesWithTwoLevelInheritance(array $expected
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand All @@ -318,7 +319,7 @@ public function testUpdateDocumentIndexesShouldCreateMappedIndexes(array $expect
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -351,7 +352,7 @@ public function testUpdateDocumentIndexesShouldDeleteUnmappedIndexesBeforeCreati
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand All @@ -377,7 +378,7 @@ public function testDeleteIndexes(array $expectedWriteOptions, ?int $maxTimeMs,
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -421,7 +422,7 @@ public function testUpdateValidators(): void
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -472,7 +473,7 @@ public function testUpdateDocumentValidatorShouldThrowExceptionForMappedSupercla
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand All @@ -496,7 +497,7 @@ public function testUpdateDocumentValidatorReset(array $expectedWriteOptions, ?i
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -525,7 +526,7 @@ public function testCreateDocumentCollection(array $expectedWriteOptions, ?int $
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand All @@ -544,7 +545,7 @@ public function testCreateDocumentCollectionForFile(array $expectedWriteOptions,
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -589,7 +590,7 @@ public function testCreateDocumentCollectionWithValidator(array $expectedWriteOp
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -628,7 +629,7 @@ public function testCreateView(array $expectedWriteOptions, ?int $maxTimeMs, ?Wr
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -658,7 +659,7 @@ public function testCreateCollections(array $expectedWriteOptions, ?int $maxTime
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand All @@ -674,7 +675,7 @@ public function testDropCollections(array $expectedWriteOptions, ?int $maxTimeMs
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand All @@ -695,7 +696,7 @@ public function testDropDocumentCollection(array $expectedWriteOptions, ?int $ma
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -732,7 +733,7 @@ public function testDropDocumentCollectionForGridFSFile(array $expectedWriteOpti
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand All @@ -753,7 +754,7 @@ public function testDropView(array $expectedWriteOptions, ?int $maxTimeMs, ?Writ
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand All @@ -775,7 +776,7 @@ public function testDropDocumentDatabase(array $expectedWriteOptions, ?int $maxT
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*
* @dataProvider getWriteOptions
*/
Expand Down Expand Up @@ -1203,7 +1204,7 @@ private function getMockDatabase()
}

/**
* @param array<string, mixed> $expectedWriteOptions
* @psalm-param IndexOptions $expectedWriteOptions
*/
private function writeOptions(array $expectedWriteOptions): Constraint
{
Expand Down

0 comments on commit fee2938

Please sign in to comment.