Skip to content
Snippets Groups Projects
Commit 8be86e85 authored by Torben Hansen's avatar Torben Hansen Committed by Christian Kuhn
Browse files

[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: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 6e2f50ae
Branches
Tags
No related merge requests found
...@@ -2886,7 +2886,7 @@ parameters: ...@@ -2886,7 +2886,7 @@ parameters:
path: ../../typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php 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 count: 1
path: ../../typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php path: ../../typo3/sysext/extbase/Tests/Functional/Property/TypeConverter/ObjectConverterTest.php
......
<?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;
}
}
...@@ -19,12 +19,12 @@ namespace TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter; ...@@ -19,12 +19,12 @@ namespace TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface; use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Extbase\Property\Exception; use TYPO3\CMS\Extbase\Property\Exception;
use TYPO3\CMS\Extbase\Property\PropertyMapper; use TYPO3\CMS\Extbase\Property\PropertyMapper;
use TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration; use TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration;
use TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter; use TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter;
use TYPO3\CMS\Extbase\Tests\Functional\Property\Fixtures\Animal; 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\CMS\Extbase\Tests\Functional\Property\Fixtures\Cat;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
...@@ -154,22 +154,22 @@ class ObjectConverterTest extends FunctionalTestCase ...@@ -154,22 +154,22 @@ class ObjectConverterTest extends FunctionalTestCase
{ {
$class = new class () { $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; 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; $this->collection = $collection;
} }
...@@ -192,6 +192,26 @@ class ObjectConverterTest extends FunctionalTestCase ...@@ -192,6 +192,26 @@ class ObjectConverterTest extends FunctionalTestCase
self::assertSame('Lion', $result->getCollection()->current()->getName()); 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 * @test
*/ */
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment