diff --git a/src/Factory.php b/src/Factory.php index 5dc272461..d2f30ae17 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -175,11 +175,10 @@ public function collection( return $this->collectionFactoryAlias[$name]; } // Find by interface - if (\class_exists($name)) { - foreach ($this->collectionFactoryInterface as $interface => $factory) { - if (\is_subclass_of($name, $interface, true)) { - return $this->collectionFactoryAlias[$name] = $factory->withCollectionClass($name); - } + foreach ($this->collectionFactoryInterface as $interface => $factory) { + if (\is_a($name, $interface, true)) { + /** @var class-string $name */ + return $this->collectionFactoryAlias[$name] = $factory->withCollectionClass($name); } } return $this->collectionFactoryAlias[$name] = $this->factory->make($name); diff --git a/tests/ORM/Functional/Driver/Common/Relation/HasMany/HasManyCollectionsTest.php b/tests/ORM/Functional/Driver/Common/Relation/HasMany/HasManyCollectionsTest.php index f129558ed..38f1ebd7e 100644 --- a/tests/ORM/Functional/Driver/Common/Relation/HasMany/HasManyCollectionsTest.php +++ b/tests/ORM/Functional/Driver/Common/Relation/HasMany/HasManyCollectionsTest.php @@ -105,6 +105,18 @@ public function collectionTypesProvider(): array 'Alias Common Illuminate collection eager' => [ 'illuminate', false, \Illuminate\Support\Collection::class, ], + 'Interface Doctrine collection lazy' => [ + \Doctrine\Common\Collections\Collection::class, true, \Doctrine\Common\Collections\ArrayCollection::class, + ], + 'Interface Doctrine collection eager' => [ + \Doctrine\Common\Collections\Collection::class, false, \Doctrine\Common\Collections\ArrayCollection::class, + ], + 'Base Illuminate collection lazy' => [ + \Illuminate\Support\Collection::class, true, \Illuminate\Support\Collection::class, + ], + 'Base Illuminate collection eager' => [ + \Illuminate\Support\Collection::class, false, \Illuminate\Support\Collection::class, + ], 'Class Custom Doctrine collection lazy' => [ CustomCollection::class, true, CustomCollection::class, ],