Created
June 9, 2010 08:44
-
-
Save hlubek/431229 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: Tests/Unit/Reflection/ObjectAccessTest.php | |
| =================================================================== | |
| --- Tests/Unit/Reflection/ObjectAccessTest.php (Revision 4470) | |
| +++ Tests/Unit/Reflection/ObjectAccessTest.php (Arbeitskopie) | |
| @@ -216,6 +216,20 @@ | |
| /** | |
| * @test | |
| + * @author Christopher Hlubek <[email protected]> | |
| + */ | |
| + public function getSettablePropertyNamesReturnsPropertyNamesOfStdClass() { | |
| + $stdClassObject = new \stdClass(); | |
| + $stdClassObject->property = 'string1'; | |
| + $stdClassObject->property2 = NULL; | |
| + | |
| + $settablePropertyNames = \F3\FLOW3\Reflection\ObjectAccess::getSettablePropertyNames($stdClassObject); | |
| + $expectedPropertyNames = array('property', 'property2'); | |
| + $this->assertEquals($expectedPropertyNames, $settablePropertyNames, 'getSettablePropertyNames returns not all settable properties.'); | |
| + } | |
| + | |
| + /** | |
| + * @test | |
| * @author Sebastian Kurfürst <[email protected]> | |
| */ | |
| public function getGettablePropertiesReturnsTheCorrectValuesForAllProperties() { | |
| @@ -232,6 +246,23 @@ | |
| /** | |
| * @test | |
| + * @author Christopher Hlubek <[email protected]> | |
| + */ | |
| + public function getGettablePropertiesReturnsPropertiesOfStdClass() { | |
| + $stdClassObject = new \stdClass(); | |
| + $stdClassObject->property = 'string1'; | |
| + $stdClassObject->property2 = NULL; | |
| + $stdClassObject->publicProperty2 = 42; | |
| + $allProperties = \F3\FLOW3\Reflection\ObjectAccess::getGettableProperties($stdClassObject); | |
| + $expectedProperties = array( | |
| + 'property' => 'string1', | |
| + 'property2' => NULL, | |
| + 'publicProperty2' => 42); | |
| + $this->assertEquals($expectedProperties, $allProperties, 'expectedProperties did not return the right values for the properties.'); | |
| + } | |
| + | |
| + /** | |
| + * @test | |
| * @author Robert Lemke <[email protected]> | |
| */ | |
| public function isPropertySettableTellsIfAPropertyCanBeSet() { | |
| @@ -244,6 +275,19 @@ | |
| /** | |
| * @test | |
| + * @author Christopher Hlubek <[email protected]> | |
| + */ | |
| + public function isPropertySettableWorksOnStdClass() { | |
| + $stdClassObject = new \stdClass(); | |
| + $stdClassObject->property = 'foo'; | |
| + | |
| + $this->assertTrue(\F3\FLOW3\Reflection\ObjectAccess::isPropertySettable($stdClassObject, 'property')); | |
| + | |
| + $this->assertFalse(\F3\FLOW3\Reflection\ObjectAccess::isPropertySettable($stdClassObject, 'undefinedProperty')); | |
| + } | |
| + | |
| + /** | |
| + * @test | |
| * @author Robert Lemke <[email protected]> | |
| */ | |
| public function isPropertyGettableTellsIfAPropertyCanBeRetrieved() { | |
| @@ -255,8 +299,22 @@ | |
| $this->assertFalse(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject, 'writeOnlyMagicProperty')); | |
| } | |
| + | |
| /** | |
| * @test | |
| + * @author Christopher Hlubek <[email protected]> | |
| + */ | |
| + public function isPropertyGettableWorksOnStdClass() { | |
| + $stdClassObject = new \stdClass(); | |
| + $stdClassObject->property = 'foo'; | |
| + | |
| + $this->assertTrue(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($stdClassObject, 'property')); | |
| + | |
| + $this->assertFalse(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($stdClassObject, 'undefinedProperty')); | |
| + } | |
| + | |
| + /** | |
| + * @test | |
| * @author Sebastian Kurfürst <[email protected]> | |
| */ | |
| public function getPropertyPathCanRecursivelyGetPropertiesOfAnObject() { | |
| Index: Classes/Reflection/ObjectAccess.php | |
| =================================================================== | |
| --- Classes/Reflection/ObjectAccess.php (Revision 4470) | |
| +++ Classes/Reflection/ObjectAccess.php (Arbeitskopie) | |
| @@ -176,7 +176,7 @@ | |
| */ | |
| static public function getGettablePropertyNames($object) { | |
| if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1237301369); | |
| - $declaredPropertyNames = array_keys(get_class_vars(get_class($object))); | |
| + $declaredPropertyNames = array_keys(get_object_vars($object)); | |
| foreach (get_class_methods($object) as $methodName) { | |
| if (is_callable(array($object, $methodName))) { | |
| @@ -207,7 +207,7 @@ | |
| */ | |
| static public function getSettablePropertyNames($object) { | |
| if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1264022994); | |
| - $declaredPropertyNames = array_keys(get_class_vars(get_class($object))); | |
| + $declaredPropertyNames = array_keys(get_object_vars($object)); | |
| foreach (get_class_methods($object) as $methodName) { | |
| if (substr($methodName, 0, 3) === 'set' && is_callable(array($object, $methodName))) { | |
| @@ -230,7 +230,7 @@ | |
| */ | |
| static public function isPropertySettable($object, $propertyName) { | |
| if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1259828920); | |
| - if (array_search($propertyName, array_keys(get_class_vars(get_class($object)))) !== FALSE) return TRUE; | |
| + if (array_search($propertyName, array_keys(get_object_vars($object))) !== FALSE) return TRUE; | |
| return is_callable(array($object, self::buildSetterMethodName($propertyName))); | |
| } | |
| @@ -244,7 +244,7 @@ | |
| */ | |
| static public function isPropertyGettable($object, $propertyName) { | |
| if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1259828921); | |
| - if (array_search($propertyName, array_keys(get_class_vars(get_class($object)))) !== FALSE) return TRUE; | |
| + if (array_search($propertyName, array_keys(get_object_vars($object))) !== FALSE) return TRUE; | |
| if (is_callable(array($object, 'get' . ucfirst($propertyName)))) return TRUE; | |
| return is_callable(array($object, 'is' . ucfirst($propertyName))); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment