66
77use Doctrine \Common \Collections \Collection ;
88use Doctrine \Common \Collections \Criteria ;
9+ use Doctrine \Common \Collections \Order ;
10+ use Doctrine \Common \Collections \Selectable ;
911use Doctrine \ORM \Mapping \Column ;
1012use Doctrine \ORM \Mapping \Entity ;
1113use Doctrine \ORM \Mapping \GeneratedValue ;
1719use PHPUnit \Framework \Attributes \Group ;
1820
1921use function assert ;
22+ use function class_exists ;
2023
2124#[Group('GH7767 ' )]
2225class GH7767Test extends OrmFunctionalTestCase
@@ -54,7 +57,9 @@ public function testMatchingOverrulesCollectionOrdering(): void
5457 $ parent = $ this ->_em ->find (GH7767ParentEntity::class, 1 );
5558 assert ($ parent instanceof GH7767ParentEntity);
5659
57- $ children = $ parent ->getChildren ()->matching (Criteria::create ()->orderBy (['position ' => 'DESC ' ]));
60+ $ children = $ parent ->getChildren ()->matching (
61+ Criteria::create ()->orderBy (['position ' => class_exists (Order::class) ? Order::Descending : 'DESC ' ]),
62+ );
5863
5964 self ::assertEquals (300 , $ children [0 ]->position );
6065 self ::assertEquals (200 , $ children [1 ]->position );
@@ -70,7 +75,7 @@ class GH7767ParentEntity
7075 #[GeneratedValue]
7176 private int $ id ;
7277
73- /** @psalm-var Collection<int, GH7767ChildEntity> */
78+ /** @psalm-var Collection<int, GH7767ChildEntity>&Selectable<int, GH7767ChildEntity> */
7479 #[OneToMany(targetEntity: GH7767ChildEntity::class, mappedBy: 'parent ' , fetch: 'EXTRA_LAZY ' , cascade: ['persist ' ])]
7580 #[OrderBy(['position ' => 'ASC ' ])]
7681 private $ children ;
@@ -80,7 +85,7 @@ public function addChild(int $position): void
8085 $ this ->children [] = new GH7767ChildEntity ($ this , $ position );
8186 }
8287
83- /** @psalm-return Collection<int, GH7767ChildEntity> */
88+ /** @psalm-return Collection<int, GH7767ChildEntity>&Selectable<int, GH7767ChildEntity> */
8489 public function getChildren (): Collection
8590 {
8691 return $ this ->children ;
0 commit comments