diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index 3319331d0062bbf4baf27baf2e39e23fcb239761..bf45e2ecc379526cbc6aa8c631bb59412ced0c5a 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -2886,7 +2886,7 @@ parameters: path: ../../typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php - - message: "#^Property class@anonymous/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest\\.php\\:337\\:\\:\\$name is unused\\.$#" + message: "#^Property class@anonymous/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest\\.php\\:357\\:\\:\\$name is unused\\.$#" count: 1 path: ../../typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php diff --git a/typo3/sysext/extbase/Tests/Functional/Property/Fixtures/Animals.php b/typo3/sysext/extbase/Tests/Functional/Property/Fixtures/Animals.php new file mode 100644 index 0000000000000000000000000000000000000000..822cf6952a3f8931b376048f09d58470fe6e7bec --- /dev/null +++ b/typo3/sysext/extbase/Tests/Functional/Property/Fixtures/Animals.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +namespace TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures; + +use TYPO3\CMS\Extbase\Persistence\ObjectStorage; + +class Animals +{ + /** + * @var ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> + */ + protected ObjectStorage $collection; + + /** + * @return ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> + */ + public function getCollection(): ObjectStorage + { + return $this->collection; + } + + /** + * @param ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> $collection + */ + public function setCollection(ObjectStorage $collection): void + { + $this->collection = $collection; + } +} diff --git a/typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php b/typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php index b4cc953191bf2d28faa5b42ee385bb00fd660c3e..54fa3de528b43ca045d02a387393985a4cc0674b 100644 --- a/typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php +++ b/typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php @@ -19,12 +19,12 @@ namespace TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface; -use TYPO3\CMS\Extbase\Persistence\ObjectStorage; use TYPO3\CMS\Extbase\Property\Exception; use TYPO3\CMS\Extbase\Property\PropertyMapper; use TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration; use TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter; use TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal; +use TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animals; use TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Cat; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; @@ -154,22 +154,22 @@ class ObjectConverterTest extends FunctionalTestCase { $class = new class () { /** - * @var ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> + * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> */ - protected ObjectStorage $collection; + protected \TYPO3\CMS\Extbase\Persistence\ObjectStorage $collection; /** - * @return ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> + * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> */ - public function getCollection(): ObjectStorage + public function getCollection(): \TYPO3\CMS\Extbase\Persistence\ObjectStorage { return $this->collection; } /** - * @param ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> $collection + * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal> $collection */ - public function setCollection(ObjectStorage $collection): void + public function setCollection(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $collection): void { $this->collection = $collection; } @@ -192,6 +192,26 @@ class ObjectConverterTest extends FunctionalTestCase self::assertSame('Lion', $result->getCollection()->current()->getName()); } + /** + * @test + */ + public function collectionTypesAreConsideredInMappingWithShortObjectStorageNamespaceAndNonAnonymousClass(): void + { + $propertyMapper = $this->get(PropertyMapper::class); + $propertyMapperConfiguration = new PropertyMappingConfiguration(); + $propertyMapperConfiguration->allowAllProperties(); + $propertyMapperConfiguration->forProperty('collection.*')->allowAllProperties(); + $result = $propertyMapper->convert( + ['collection' => [['name' => 'Zebra'], ['name' => 'Lion']]], + Animals::class, + $propertyMapperConfiguration + ); + self::assertSame(2, $result->getCollection()->count()); + self::assertSame('Zebra', $result->getCollection()->current()->getName()); + $result->getCollection()->next(); + self::assertSame('Lion', $result->getCollection()->current()->getName()); + } + /** * @test */