63 $this->mockReflectionService = $this->getMock(
'TYPO3\CMS\Extbase\Reflection\ReflectionService');
64 $this->
inject($this->converter,
'reflectionService', $this->mockReflectionService);
66 $this->mockPersistenceManager = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface');
67 $this->
inject($this->converter,
'persistenceManager', $this->mockPersistenceManager);
69 $this->mockObjectManager = $this->getMock(
'TYPO3\CMS\Extbase\Object\ObjectManagerInterface');
70 $this->mockObjectManager->expects($this->any())
72 ->will($this->returnCallback(
function() {
73 $args = func_get_args();
74 $reflectionClass = new \ReflectionClass(array_shift($args));
76 return $reflectionClass->newInstance();
78 return $reflectionClass->newInstanceArgs($args);
81 $this->
inject($this->converter,
'objectManager', $this->mockObjectManager);
83 $this->mockContainer = $this->getMock(
'\TYPO3\CMS\Extbase\Object\Container\Container');
84 $this->
inject($this->converter,
'objectContainer', $this->mockContainer);
91 $this->assertEquals(array(
'integer',
'string',
'array'), $this->converter->getSupportedSourceTypes(),
'Source types do not match');
92 $this->assertEquals(
'object', $this->converter->getSupportedTargetType(),
'Target type does not match');
93 $this->assertEquals(1, $this->converter->getPriority(),
'Priority does not match');
101 array(TRUE, FALSE, TRUE),
103 array(FALSE, TRUE, TRUE),
105 array(FALSE, FALSE, FALSE),
117 eval(
"class {$className} extends Tx_Extbase_DomainObject_AbstractEntity {}");
118 } elseif ($isValueObject) {
119 eval(
"class {$className} extends Tx_Extbase_DomainObject_AbstractValueObject {}");
121 eval(
"class {$className} {}");
123 $this->assertEquals($expected, $this->converter->canConvertFrom(
'myInputData', $className));
132 '__identity' =>
'someIdentity',
139 $this->assertEquals($expected, $this->converter->getSourceChildPropertiesToBeConverted($source));
146 $mockSchema = $this->getMockBuilder(
'TYPO3\\CMS\\Extbase\\Reflection\\ClassSchema')->disableOriginalConstructor()->getMock();
147 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'TheTargetType')->will($this->returnValue($mockSchema));
149 $this->mockContainer->expects($this->any())->method(
'getImplementationClassName')->will($this->returnValue(
'TheTargetType'));
150 $mockSchema->expects($this->any())->method(
'hasProperty')->with(
'thePropertyName')->will($this->returnValue(TRUE));
151 $mockSchema->expects($this->any())->method(
'getProperty')->with(
'thePropertyName')->will($this->returnValue(array(
152 'type' =>
'TheTypeOfSubObject',
153 'elementType' => NULL
156 $this->assertEquals(
'TheTypeOfSubObject', $this->converter->getTypeOfChildProperty(
'TheTargetType',
'thePropertyName', $configuration));
163 $this->mockReflectionService->expects($this->never())->method(
'getClassSchema');
164 $this->mockContainer->expects($this->any())->method(
'getImplementationClassName')->will($this->returnValue(
'foo'));
168 $this->assertEquals(
'Foo\Bar', $this->converter->getTypeOfChildProperty(
'foo',
'thePropertyName', $configuration));
176 $object = new \stdClass();
178 $this->mockPersistenceManager->expects($this->any())->method(
'getObjectByIdentifier')->with($identifier)->will($this->returnValue($object));
179 $this->assertSame($object, $this->converter->convertFrom($identifier,
'MySpecialType'));
187 $object = new \stdClass();
189 $this->mockPersistenceManager->expects($this->any())->method(
'getObjectByIdentifier')->with($identifier)->will($this->returnValue($object));
190 $this->assertSame($object, $this->converter->convertFrom($identifier,
'MySpecialType'));
197 $identifier =
'12345';
198 $object = new \stdClass();
201 '__identity' => $identifier
203 $this->mockPersistenceManager->expects($this->any())->method(
'getObjectByIdentifier')->with($identifier)->will($this->returnValue($object));
204 $this->assertSame($object, $this->converter->convertFrom($source,
'MySpecialType'));
212 $identifier =
'12345';
213 $object = new \stdClass();
214 $object->someProperty =
'asdf';
217 '__identity' => $identifier,
220 $this->mockPersistenceManager->expects($this->any())->method(
'getObjectByIdentifier')->with($identifier)->will($this->returnValue($object));
221 $this->converter->convertFrom($source,
'MySpecialType');
229 $configuration = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration();
230 $configuration->setTypeConverterOptions(
'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\PersistentObjectConverter', $typeConverterOptions);
231 return $configuration;
240 $mockClassSchema = $this->getMock(
'TYPO3\\CMS\\Extbase\\Reflection\\ClassSchema', array(), array(
'Dummy'));
241 $mockClassSchema->expects($this->any())->method(
'getIdentityProperties')->will($this->returnValue(array(
'key1' =>
'someType')));
242 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'SomeType')->will($this->returnValue($mockClassSchema));
244 $mockConstraint = $this->getMockBuilder(
'TYPO3\CMS\Extbase\Persistence\Generic\Qom\Comparison')->disableOriginalConstructor()->getMock();
246 $mockObject = new \stdClass();
247 $mockQuery = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
248 $mockQueryResult = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
249 $mockQueryResult->expects($this->any())->method(
'count')->will($this->returnValue($numberOfResults));
250 $mockQueryResult->expects($howOftenIsGetFirstCalled)->method(
'getFirst')->will($this->returnValue($mockObject));
251 $mockQuery->expects($this->any())->method(
'equals')->with(
'key1',
'value1')->will($this->returnValue($mockConstraint));
252 $mockQuery->expects($this->any())->method(
'matching')->with($mockConstraint)->will($this->returnValue($mockQuery));
253 $mockQuery->expects($this->any())->method(
'execute')->will($this->returnValue($mockQueryResult));
255 $this->mockPersistenceManager->expects($this->any())->method(
'createQueryForType')->with(
'SomeType')->will($this->returnValue($mockQuery));
266 $this->mockReflectionService->expects($this->never())->method(
'getClassSchema');
271 $actual = $this->converter->convertFrom($source,
'SomeType');
272 $this->assertNull($actual);
285 $this->mockPersistenceManager->expects($this->any())->method(
'getObjectByIdentifier')->with(666)->will($this->throwException(
new \
TYPO3\CMS\Extbase\Property\
Exception\DuplicateObjectException));
286 $this->converter->convertFrom($source,
'SomeType');
297 $this->converter->convertFrom($source,
'MySpecialType');
307 $convertedChildProperties = array(
310 $expectedObject = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters();
311 $expectedObject->property1 =
'bar';
313 $this->mockReflectionService->expects($this->any())->method(
'getMethodParameters')->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters',
'__construct')->will($this->throwException(
new \ReflectionException()));
314 $this->mockObjectManager->expects($this->any())->method(
'getClassNameByObjectName')->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters')->will($this->returnValue(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters'));
316 $result = $this->converter->convertFrom($source,
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters', $convertedChildProperties, $configuration);
317 $this->assertEquals($expectedObject,
$result);
328 $object = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters();
329 $convertedChildProperties = array(
330 'propertyNotExisting' =>
'bar' 332 $this->mockObjectManager->expects($this->any())->method(
'get')->with(
'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithSetters')->will($this->returnValue($object));
333 $this->mockReflectionService->expects($this->any())->method(
'getMethodParameters')->with(
'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithSetters',
'__construct')->will($this->returnValue(array()));
335 $result = $this->converter->convertFrom($source,
'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithSetters', $convertedChildProperties, $configuration);
336 $this->assertSame($object,
$result);
346 $convertedChildProperties = array(
347 'property1' =>
'param1',
350 $expectedObject = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor(
'param1');
351 $expectedObject->setProperty2(
'bar');
353 $this->mockReflectionService
354 ->expects($this->any())
355 ->method(
'getMethodParameters')
356 ->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor',
'__construct')
357 ->will($this->returnValue(array(
358 'property1' => array(
'optional' => FALSE)
360 $this->mockReflectionService
361 ->expects($this->any())
362 ->method(
'hasMethod')
363 ->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor',
'__construct')
364 ->will($this->returnValue(TRUE));
365 $this->mockObjectManager->expects($this->any())->method(
'getClassNameByObjectName')->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor')->will($this->returnValue(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor'));
366 $this->mockContainer->expects($this->any())->method(
'getImplementationClassName')->will($this->returnValue(
'TYPO3\\CMS\Extbase\\Tests\\Fixture\\ClassWithSettersAndConstructor'));
368 $result = $this->converter->convertFrom($source,
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor', $convertedChildProperties, $configuration);
369 $this->assertEquals($expectedObject,
$result);
370 $this->assertEquals(
'bar', $expectedObject->getProperty2());
380 $expectedObject = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor(
'thisIsTheDefaultValue');
382 $this->mockReflectionService->expects($this->any())->method(
'getMethodParameters')->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor',
'__construct')->will($this->returnValue(array(
383 'property1' => array(
'optional' => TRUE,
'defaultValue' =>
'thisIsTheDefaultValue')
385 $this->mockReflectionService
386 ->expects($this->any())
387 ->method(
'hasMethod')
388 ->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor',
'__construct')
389 ->will($this->returnValue(TRUE));
390 $this->mockObjectManager->expects($this->any())->method(
'getClassNameByObjectName')->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor')->will($this->returnValue(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor'));
391 $this->mockContainer->expects($this->any())->method(
'getImplementationClassName')->will($this->returnValue(
'TYPO3\\CMS\Extbase\\Tests\\Fixture\\ClassWithSettersAndConstructor'));
393 $result = $this->converter->convertFrom($source,
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor', array(), $configuration);
394 $this->assertEquals($expectedObject,
$result);
405 $object = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor(
'param1');
406 $convertedChildProperties = array(
410 $this->mockReflectionService->expects($this->any())->method(
'getMethodParameters')->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor',
'__construct')->will($this->returnValue(array(
411 'property1' => array(
'optional' => FALSE)
413 $this->mockReflectionService
414 ->expects($this->any())
415 ->method(
'hasMethod')
416 ->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor',
'__construct')
417 ->will($this->returnValue(TRUE));
418 $this->mockObjectManager->expects($this->any())->method(
'getClassNameByObjectName')->with(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor')->will($this->returnValue(
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor'));
419 $this->mockContainer->expects($this->any())->method(
'getImplementationClassName')->will($this->returnValue(
'TYPO3\\CMS\Extbase\\Tests\\Fixture\\ClassWithSettersAndConstructor'));
421 $result = $this->converter->convertFrom($source,
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor', $convertedChildProperties, $configuration);
422 $this->assertSame($object,
$result);
430 $result = $this->converter->convertFrom($source,
'TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor');
convertFromShouldFetchObjectFromPersistenceIfuidStringIsGiven()
inject($target, $name, $dependency)
convertFromShouldThrowExceptionIfMoreThanOneObjectWasFound()
buildConfiguration($typeConverterOptions)
const CONFIGURATION_CREATION_ALLOWED
convertFromShouldFetchObjectFromPersistenceIfOnlyIdentityArrayGiven()
convertFromShouldThrowExceptionIfObjectNeedsToBeCreatedButConfigurationIsNotSet()
convertFromShouldCreateObjectWhenThereAreOptionalConstructorParameters()
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
convertFromShouldReturnNullForEmptyString()
convertFromShouldCreateObject()
getSourceChildPropertiesToBeConvertedReturnsAllPropertiesExceptTheIdentityProperty()
canConvertFromReturnsTrueIfClassIsTaggedWithEntityOrValueObject($isEntity, $isValueObject, $expected)
setupMockQuery($numberOfResults, $howOftenIsGetFirstCalled)
getTypeOfChildPropertyShouldUseConfiguredTypeIfItWasSet()
convertFromShouldFetchObjectFromPersistenceIfUuidStringIsGiven()
dataProviderForCanConvert()
const CONFIGURATION_TARGET_TYPE
convertFromShouldThrowExceptionIfRequiredConstructorParameterWasNotFound()
convertFromShouldCreateObjectWhenThereAreConstructorParameters()
convertFromShouldReturnExceptionIfNoMatchingObjectWasFound()
convertFromShouldThrowExceptionIfObjectNeedsToBeModifiedButConfigurationIsNotSet()
convertFromShouldThrowExceptionIfPropertyOnTargetObjectCouldNotBeSet()
getTypeOfChildPropertyShouldUseReflectionServiceToDetermineType()