TYPO3 CMS  TYPO3_7-6
ObjectConverterTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script belongs to the Extbase framework. *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License as published by the *
9  * Free Software Foundation, either version 3 of the License, or (at your *
10  * option) any later version. *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
26 
31 {
35  protected $converter;
36 
41 
45  protected $mockObjectManager;
46 
50  protected $mockContainer;
51 
56  protected function setUp()
57  {
58  $this->mockReflectionService = $this->getMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
59  $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
60  $this->mockContainer = $this->getMock(\TYPO3\CMS\Extbase\Object\Container\Container::class);
61 
62  $this->converter = new ObjectConverter();
63  $this->inject($this->converter, 'reflectionService', $this->mockReflectionService);
64  $this->inject($this->converter, 'objectManager', $this->mockObjectManager);
65  $this->inject($this->converter, 'objectContainer', $this->mockContainer);
66  }
67 
71  public function checkMetadata()
72  {
73  $this->assertEquals(['array'], $this->converter->getSupportedSourceTypes(), 'Source types do not match');
74  $this->assertEquals('object', $this->converter->getSupportedTargetType(), 'Target type does not match');
75  $this->assertEquals(0, $this->converter->getPriority(), 'Priority does not match');
76  }
77 
81  public function dataProviderForCanConvert()
82  {
83  return [
84  // Is entity => cannot convert
85  [\TYPO3\CMS\Extbase\Tests\Fixture\Entity::class, false],
86  // Is valueobject => cannot convert
87  [\TYPO3\CMS\Extbase\Tests\Fixture\ValueObject::class, false],
88  // Is no entity and no value object => can convert
89  ['stdClass', true]
90  ];
91  }
92 
100  {
101  $this->assertEquals($expected, $this->converter->canConvertFrom('myInputData', $className));
102  }
103 
108  {
109  $this->mockReflectionService->expects($this->any())->method('hasMethod')->with('TheTargetType', 'setThePropertyName')->will($this->returnValue(false));
110  $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with('TheTargetType', '__construct')->will($this->returnValue([
111  'thePropertyName' => [
112  'type' => 'TheTypeOfSubObject',
113  'elementType' => null
114  ]
115  ]));
116  $this->mockContainer->expects($this->any())->method('getImplementationClassName')->will($this->returnValue('TheTargetType'));
117 
118  $configuration = new PropertyMappingConfiguration();
119  $configuration->setTypeConverterOptions(\TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter::class, []);
120  $this->assertEquals('TheTypeOfSubObject', $this->converter->getTypeOfChildProperty('TheTargetType', 'thePropertyName', $configuration));
121  }
122 }
inject($target, $name, $dependency)