25 $this->dummyObject = new \TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithGettersAndSetters();
26 $this->dummyObject->setProperty(
'string1');
27 $this->dummyObject->setAnotherProperty(42);
28 $this->dummyObject->shouldNotBePickedUp = TRUE;
36 $this->assertEquals($property,
'string1');
44 $this->assertEquals($property, 42,
'A property of a given object was not returned correctly.');
52 $this->assertEquals($property,
'unexposed',
'A property of a given object was not returned correctly.');
59 $this->dummyObject->unknownProperty =
'unknown';
61 $this->assertEquals($property,
'unknown',
'A property of a given object was not returned correctly.');
93 $this->assertTrue($property);
116 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($this->dummyObject,
'protectedProperty', 42));
123 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($this->dummyObject,
'unexposedProperty',
'was set anyway', TRUE));
124 $this->assertAttributeEquals(
'was set anyway',
'unexposedProperty', $this->dummyObject);
131 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($this->dummyObject,
'unknownProperty',
'was set anyway', TRUE));
132 $this->assertAttributeEquals(
'was set anyway',
'unknownProperty', $this->dummyObject);
140 $this->assertEquals($this->dummyObject->getProperty(), 4242,
'setProperty does not work with setter.');
148 $this->assertEquals($this->dummyObject->publicProperty, 4242,
'setProperty does not work with public property.');
155 $arrayObject = new \ArrayObject();
159 $this->assertEquals(4242, $arrayObject[
'publicProperty']);
160 $this->assertEquals(
'value', $array[
'key']);
167 $arrayObject = new \ArrayObject(array(
'key' =>
'value'));
169 $this->assertEquals(
'value', $actual,
'getProperty does not work with ArrayObject property.');
176 $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
177 $objectStorage->key =
'value';
179 $this->assertEquals(
'value', $actual,
'getProperty does not work with ObjectStorage property.');
186 $arrayAccessInstance = new \TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\ArrayAccessClass(array(
'key' =>
'value'));
188 $this->assertEquals(
'value', $actual,
'getProperty does not work with Array Access property.');
195 $array = array(
'key' =>
'value');
197 $this->assertEquals($expected,
'value',
'getProperty does not work with Array property.');
204 $array = array(
'parent' => array(
'key' =>
'value'));
206 $this->assertEquals(
'value', $actual,
'getPropertyPath does not work with Array property.');
213 $array = array(
'parent' =>
new \ArrayObject(array(
'key' =>
'value')));
215 $this->assertEquals(
'value', $actual,
'getPropertyPath does not work with Array Access property.');
222 $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
223 $exampleObject = new \stdClass();
224 $exampleObject->key =
'value';
225 $exampleObject2 = new \stdClass();
226 $exampleObject2->key =
'value2';
227 $objectStorage->attach($exampleObject);
228 $objectStorage->attach($exampleObject2);
230 'parent' => $objectStorage,
232 $this->assertSame(
'value', \
TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($array,
'parent.0.key'));
233 $this->assertSame(
'value2', \
TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($array,
'parent.1.key'));
240 $objectStorage = new \SplObjectStorage();
241 $exampleObject = new \stdClass();
242 $exampleObject->key =
'value';
243 $exampleObject2 = new \stdClass();
244 $exampleObject2->key =
'value2';
245 $objectStorage->attach($exampleObject);
246 $objectStorage->attach($exampleObject2);
248 'parent' => $objectStorage,
250 $this->assertSame(
'value', \
TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($array,
'parent.0.key'));
251 $this->assertSame(
'value2', \
TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($array,
'parent.1.key'));
259 $expectedPropertyNames = array(
'anotherProperty',
'booleanProperty',
'property',
'property2',
'publicProperty',
'publicProperty2');
260 $this->assertEquals($gettablePropertyNames, $expectedPropertyNames,
'getGettablePropertyNames returns not all gettable properties.');
268 $expectedPropertyNames = array(
'anotherProperty',
'property',
'property2',
'publicProperty',
'publicProperty2',
'writeOnlyMagicProperty');
269 $this->assertEquals($settablePropertyNames, $expectedPropertyNames,
'getSettablePropertyNames returns not all settable properties.');
276 $stdClassObject = new \stdClass();
277 $stdClassObject->property =
'string1';
278 $stdClassObject->property2 = NULL;
280 $expectedPropertyNames = array(
'property',
'property2');
281 $this->assertEquals($expectedPropertyNames, $settablePropertyNames,
'getSettablePropertyNames returns not all settable properties.');
289 $expectedProperties = array(
290 'anotherProperty' => 42,
291 'booleanProperty' => TRUE,
292 'property' =>
'string1',
294 'publicProperty' => NULL,
295 'publicProperty2' => 42
297 $this->assertEquals($allProperties, $expectedProperties,
'expectedProperties did not return the right values for the properties.');
304 $stdClassObject = new \stdClass();
305 $stdClassObject->property =
'string1';
306 $stdClassObject->property2 = NULL;
307 $stdClassObject->publicProperty2 = 42;
309 $expectedProperties = array(
310 'property' =>
'string1',
312 'publicProperty2' => 42
314 $this->assertEquals($expectedProperties, $allProperties,
'expectedProperties did not return the right values for the properties.');
321 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($this->dummyObject,
'writeOnlyMagicProperty'));
322 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($this->dummyObject,
'publicProperty'));
323 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($this->dummyObject,
'property'));
324 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($this->dummyObject,
'privateProperty'));
325 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($this->dummyObject,
'shouldNotBePickedUp'));
332 $stdClassObject = new \stdClass();
333 $stdClassObject->property =
'foo';
334 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($stdClassObject,
'property'));
335 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($stdClassObject,
'undefinedProperty'));
342 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject,
'publicProperty'));
343 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject,
'property'));
344 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject,
'booleanProperty'));
345 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject,
'privateProperty'));
346 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject,
'writeOnlyMagicProperty'));
347 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject,
'shouldNotBePickedUp'));
354 $arrayObject = new \ArrayObject();
355 $arrayObject[
'key'] =
'v';
356 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($arrayObject,
'key'));
357 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($arrayObject,
'undefinedKey'));
364 $stdClassObject = new \stdClass();
365 $stdClassObject->property =
'foo';
366 $this->assertTrue(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($stdClassObject,
'property'));
367 $this->assertFalse(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($stdClassObject,
'undefinedProperty'));
374 $alternativeObject = new \TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithGettersAndSetters();
375 $alternativeObject->setProperty(
'test');
376 $this->dummyObject->setProperty2($alternativeObject);
379 $this->assertEquals($expected, $actual);
386 $alternativeObject = new \TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithGettersAndSetters();
387 $alternativeObject->setProperty(
new \stdClass());
388 $this->dummyObject->setProperty2($alternativeObject);
389 $this->assertNull(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($this->dummyObject,
'property2.property.not.existing'));
396 $string =
'Hello world';
397 $this->assertNull(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($string,
'property2'));
404 $object = new \stdClass();
405 $object->foo =
'Hello World';
406 $this->assertNull(\
TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($object,
'foo.bar'));
getPropertyPathCanAccessPropertiesOfAnExtbaseObjectStorageObject()
getPropertyReturnsExpectedValueForUnknownPropertyIfForceDirectAccessIsTrue()
setPropertyReturnsFalseIfPropertyIsNotAccessible()
getPropertyPathCanAccessPropertiesOfAnObjectImplementingArrayAccess()
getGettablePropertiesReturnsPropertiesOfStdClass()
getPropertyTriesToCallABooleanGetterMethodIfItExists()
getPropertyReturnsExpectedValueForGetterProperty()
getGettablePropertyNamesReturnsAllPropertiesWhichAreAvailable()
isPropertyGettableWorksOnArrayAccessObjects()
getPropertyPathReturnsNullIfSubjectIsNoObject()
isPropertyGettableWorksOnStdClass()
setPropertyCanDirectlySetValuesInAnArrayObjectOrArray()
setPropertyWorksWithPublicProperty()
getPropertyPathCanRecursivelyGetPropertiesOfAnObject()
setPropertySetsValueIfPropertyIsNotAccessibleWhenForceDirectAccessIsTrue()
getPropertyReturnsExpectedValueForPublicProperty()
setPropertySetsValueIfPropertyDoesNotExistWhenForceDirectAccessIsTrue()
static getSettablePropertyNames($object)
getPropertyCanAccessPropertiesOfAnObjectImplementingArrayAccess()
getPropertyCanAccessPropertiesOfAnArrayObject()
static getGettableProperties($object)
getPropertyPathCanAccessPropertiesOfAnSplObjectStorageObject()
getPropertyReturnsPropertyNotAccessibleExceptionForNotExistingPropertyIfForceDirectAccessIsTrue()
setPropertyThrowsExceptionIfThePropertyNameIsNotAString()
static setProperty(&$subject, $propertyName, $propertyValue, $forceDirectAccess=FALSE)
getSettablePropertyNamesReturnsPropertyNamesOfStdClass()
getPropertyPathReturnsNullIfSubjectOnPathIsNoObject()
setPropertyCallsASetterMethodToSetThePropertyValueIfOneIsAvailable()
isPropertySettableWorksOnStdClass()
getPropertyCanAccessPropertiesOfAnArray()
getSettablePropertyNamesReturnsAllPropertiesWhichAreAvailable()
isPropertyGettableTellsIfAPropertyCanBeRetrieved()
getPropertyCanAccessPropertiesOfAnObjectStorageObject()
static getPropertyPath($subject, $propertyPath)
getPropertyPathReturnsNullForNonExistingPropertyPath()
getPropertyThrowsExceptionIfThePropertyNameIsNotAString()
getPropertyReturnsThrowsExceptionIfPropertyDoesNotExist()
static getGettablePropertyNames($object)
isPropertySettableTellsIfAPropertyCanBeSet()
getPropertyReturnsThrowsExceptionIfArrayKeyDoesNotExist()
getGettablePropertiesReturnsTheCorrectValuesForAllProperties()
getPropertyReturnsExpectedValueForUnexposedPropertyIfForceDirectAccessIsTrue()
getPropertyPathCanAccessPropertiesOfAnArray()
static getProperty($subject, $propertyName, $forceDirectAccess=FALSE)