‪TYPO3CMS  ‪main
ObjectStorageConverterTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪ObjectStorageConverterTest extends FunctionalTestCase
28 {
29  protected bool ‪$initializeDatabase = false;
30 
31  #[Test]
32  public function ‪convertReturnsObjectStorage(): void
33  {
34  $propertyMapperConfiguration = new ‪PropertyMappingConfiguration();
35  $propertyMapperConfiguration->allowAllProperties();
36  $propertyMapperConfiguration->forProperty('foo')->allowAllProperties();
37 
38  $propertyMapper = $this->get(PropertyMapper::class);
39 
40  $objectStorage = $propertyMapper->convert(
41  [
42  'foo' => ['color' => 'black'],
43  ],
44  ObjectStorage::class . '<' . Cat::class . '>',
45  $propertyMapperConfiguration
46  );
47 
48  self::assertInstanceOf(ObjectStorage::class, $objectStorage);
49  self::assertCount(1, $objectStorage);
50 
51  $cat = $objectStorage->current();
52  self::assertInstanceOf(Cat::class, $cat);
53  self::assertSame('black', $cat->getColor());
54  }
55 
56  #[Test]
58  {
59  $propertyMapperConfiguration = new ‪PropertyMappingConfiguration();
60  $propertyMapperConfiguration->forProperty('foo')->allowAllProperties();
61 
62  $propertyMapper = $this->get(PropertyMapper::class);
63 
64  $objectStorage = $propertyMapper->convert(
65  'foo',
66  ObjectStorage::class . '<' . Cat::class . '>',
67  $propertyMapperConfiguration
68  );
69 
70  self::assertInstanceOf(ObjectStorage::class, $objectStorage);
71  self::assertCount(0, $objectStorage);
72  }
73 }
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\ObjectStorageConverterTest\convertReturnsObjectStorage
‪convertReturnsObjectStorage()
Definition: ObjectStorageConverterTest.php:32
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\ObjectStorageConverterTest
Definition: ObjectStorageConverterTest.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\ObjectStorageConverterTest\$initializeDatabase
‪bool $initializeDatabase
Definition: ObjectStorageConverterTest.php:29
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:34
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter
Definition: ArrayConverterTest.php:18
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
Definition: PropertyMappingConfiguration.php:22
‪TYPO3\CMS\Extbase\Property\PropertyMapper
Definition: PropertyMapper.php:30
‪TYPO3Tests\TypeConverterTest\Domain\Model\Cat
Definition: Cat.php:21
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\ObjectStorageConverterTest\getSourceChildPropertiesToBeConvertedReturnsEmptyArrayIfSourceIsAString
‪getSourceChildPropertiesToBeConvertedReturnsEmptyArrayIfSourceIsAString()
Definition: ObjectStorageConverterTest.php:57