From 8be86e859f0e956baebfd2d96695aff8049299a2 Mon Sep 17 00:00:00 2001 From: Torben Hansen <derhansen@gmail.com> Date: Fri, 28 Jun 2024 19:25:34 +0200 Subject: [PATCH] [BUGFIX] Adapt ObjectConverter test with new symfony/property-info With symfony property-info 7.1.2, the type resolving for collections has been hardened. https://github.com/symfony/property-info/commit/d0bbc495f11ab99a1e2cbf04699331b88b3c1293 Our extbase ObjectConverter test for collections uses an anonymous class with an ObjectStorage property. The annotation for the property as well as the native property type is however not a FQCN. So the anonymous class has no information about, what FQCN the `ObjectStorage` class is. The change adds the FQCN for the ObjectStorage in the anonymous class, which resolves the failing test, and adds a test with a non-anymous class to test short namespaces still work. Resolves: #104254 Releases: main, 12.4, 11.5 Change-Id: Idc64e2533e0bc6d2dccc9724643247772f4f5d11 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85002 Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- Build/phpstan/phpstan-baseline.neon | 2 +- .../Functional/Property/Fixtures/Animals.php | 44 +++++++++++++++++++ .../TypeConverter/ObjectConverterTest.php | 34 +++++++++++--- 3 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 typo3/sysext/extbase/Tests/Functional/Property/Fixtures/Animals.php diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index 3319331d0062..bf45e2ecc379 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 000000000000..822cf6952a3f --- /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 b4cc953191bf..54fa3de528b4 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 */ -- GitLab