diff --git a/stubs/Collections.phpstub b/stubs/Collections.phpstub index 165465d..6b7ea0f 100644 --- a/stubs/Collections.phpstub +++ b/stubs/Collections.phpstub @@ -170,6 +170,7 @@ interface Collection extends Countable, IteratorAggregate, ArrayAccess interface Selectable { /** + * @psalm-mutation-free * @return Collection */ public function matching(Criteria $criteria); diff --git a/stubs/Criteria.phpstub b/stubs/Criteria.phpstub new file mode 100644 index 0000000..abe09ae --- /dev/null +++ b/stubs/Criteria.phpstub @@ -0,0 +1,24 @@ + + */ + public function orderBy(array $orderings) + { + } +} diff --git a/tests/acceptance/Criteria.feature b/tests/acceptance/Criteria.feature new file mode 100644 index 0000000..91e8285 --- /dev/null +++ b/tests/acceptance/Criteria.feature @@ -0,0 +1,58 @@ +Feature: Criteria + In order to use Doctrine Criteria + As a Psalm user + I need Psalm to typecheck Criteria + + Background: + Given I have Doctrine plugin enabled + And I have the following code preamble + """ + matching(Criteria::create()); + } + """ + When I run Psalm + Then I see no errors + + @Criteria::orderBy + Scenario: Order a Criteria in a pure context + Given I have the following code + """ + /** @psalm-pure */ + function foo(Selectable $collection): Collection + { + return $collection->matching(Criteria::create()->orderBy(['foo' => Criteria::ASC])); + } + """ + When I run Psalm + Then I see no errors + + @Criteria::orderBy + Scenario: Invalid sorting provided to matching + Given I have the following code + """ + /** @psalm-pure */ + function foo(Selectable $collection): Collection + { + return $collection->matching(Criteria::create()->orderBy(['foo' => 'bar'])); + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | todo | todo | + And I see no other errors