From 3868c4d0b7aeaeb1ecc34f1765c44e7d0e973754 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Tue, 21 Dec 2021 20:25:29 +0100 Subject: [PATCH] Handle intersection types --- .../CollWithPHP81Types.php | 24 +++++++++++++++++++ ...faultPersistentCollectionGeneratorTest.php | 10 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP81Types.php diff --git a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP81Types.php b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP81Types.php new file mode 100644 index 0000000000..c367a652ba --- /dev/null +++ b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP81Types.php @@ -0,0 +1,24 @@ + + */ +class CollWithPHP81Types extends ArrayCollection +{ + /** + * @param Collection&ArrayCollection $param + * @return Collection&ArrayCollection + */ + public function intersection(Collection&ArrayCollection $param) : Collection&ArrayCollection + { + return $param; + } +} diff --git a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/DefaultPersistentCollectionGeneratorTest.php b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/DefaultPersistentCollectionGeneratorTest.php index a25de92a38..cc76ec00da 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/DefaultPersistentCollectionGeneratorTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/DefaultPersistentCollectionGeneratorTest.php @@ -55,4 +55,14 @@ public function testPHP80Types(): void $coll = new $class(new CollWithPHP80Types(), $this->dm, $this->uow); $this->assertInstanceOf(CollWithPHP80Types::class, $coll); } + + /** + * @requires PHP 8.1 + */ + public function testPHP81Types(): void + { + $class = $this->generator->loadClass(CollWithPHP81Types::class, Configuration::AUTOGENERATE_EVAL); + $coll = new $class(new CollWithPHP81Types(), $this->dm, $this->uow); + $this->assertInstanceOf(CollWithPHP81Types::class, $coll); + } }