Guest User

Untitled

a guest
May 27th, 2018
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. Index: Tests/Unit/Reflection/ObjectAccessTest.php
  2. ===================================================================
  3. --- Tests/Unit/Reflection/ObjectAccessTest.php (Revision 4470)
  4. +++ Tests/Unit/Reflection/ObjectAccessTest.php (Arbeitskopie)
  5. @@ -216,6 +216,20 @@
  6.  
  7. /**
  8. * @test
  9. + * @author Christopher Hlubek <hlubek@networkteam.com>
  10. + */
  11. + public function getSettablePropertyNamesReturnsPropertyNamesOfStdClass() {
  12. + $stdClassObject = new \stdClass();
  13. + $stdClassObject->property = 'string1';
  14. + $stdClassObject->property2 = NULL;
  15. +
  16. + $settablePropertyNames = \F3\FLOW3\Reflection\ObjectAccess::getSettablePropertyNames($stdClassObject);
  17. + $expectedPropertyNames = array('property', 'property2');
  18. + $this->assertEquals($expectedPropertyNames, $settablePropertyNames, 'getSettablePropertyNames returns not all settable properties.');
  19. + }
  20. +
  21. + /**
  22. + * @test
  23. * @author Sebastian Kurfürst <sebastian@typo3.org>
  24. */
  25. public function getGettablePropertiesReturnsTheCorrectValuesForAllProperties() {
  26. @@ -232,6 +246,23 @@
  27.  
  28. /**
  29. * @test
  30. + * @author Christopher Hlubek <hlubek@networkteam.com>
  31. + */
  32. + public function getGettablePropertiesReturnsPropertiesOfStdClass() {
  33. + $stdClassObject = new \stdClass();
  34. + $stdClassObject->property = 'string1';
  35. + $stdClassObject->property2 = NULL;
  36. + $stdClassObject->publicProperty2 = 42;
  37. + $allProperties = \F3\FLOW3\Reflection\ObjectAccess::getGettableProperties($stdClassObject);
  38. + $expectedProperties = array(
  39. + 'property' => 'string1',
  40. + 'property2' => NULL,
  41. + 'publicProperty2' => 42);
  42. + $this->assertEquals($expectedProperties, $allProperties, 'expectedProperties did not return the right values for the properties.');
  43. + }
  44. +
  45. + /**
  46. + * @test
  47. * @author Robert Lemke <robert@typo3.org>
  48. */
  49. public function isPropertySettableTellsIfAPropertyCanBeSet() {
  50. @@ -244,6 +275,19 @@
  51.  
  52. /**
  53. * @test
  54. + * @author Christopher Hlubek <hlubek@networkteam.com>
  55. + */
  56. + public function isPropertySettableWorksOnStdClass() {
  57. + $stdClassObject = new \stdClass();
  58. + $stdClassObject->property = 'foo';
  59. +
  60. + $this->assertTrue(\F3\FLOW3\Reflection\ObjectAccess::isPropertySettable($stdClassObject, 'property'));
  61. +
  62. + $this->assertFalse(\F3\FLOW3\Reflection\ObjectAccess::isPropertySettable($stdClassObject, 'undefinedProperty'));
  63. + }
  64. +
  65. + /**
  66. + * @test
  67. * @author Robert Lemke <robert@typo3.org>
  68. */
  69. public function isPropertyGettableTellsIfAPropertyCanBeRetrieved() {
  70. @@ -255,8 +299,22 @@
  71. $this->assertFalse(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject, 'writeOnlyMagicProperty'));
  72. }
  73.  
  74. +
  75. /**
  76. * @test
  77. + * @author Christopher Hlubek <hlubek@networkteam.com>
  78. + */
  79. + public function isPropertyGettableWorksOnStdClass() {
  80. + $stdClassObject = new \stdClass();
  81. + $stdClassObject->property = 'foo';
  82. +
  83. + $this->assertTrue(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($stdClassObject, 'property'));
  84. +
  85. + $this->assertFalse(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($stdClassObject, 'undefinedProperty'));
  86. + }
  87. +
  88. + /**
  89. + * @test
  90. * @author Sebastian Kurfürst <sebastian@typo3.org>
  91. */
  92. public function getPropertyPathCanRecursivelyGetPropertiesOfAnObject() {
  93.  
  94.  
  95. Index: Classes/Reflection/ObjectAccess.php
  96. ===================================================================
  97. --- Classes/Reflection/ObjectAccess.php (Revision 4470)
  98. +++ Classes/Reflection/ObjectAccess.php (Arbeitskopie)
  99. @@ -176,7 +176,7 @@
  100. */
  101. static public function getGettablePropertyNames($object) {
  102. if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1237301369);
  103. - $declaredPropertyNames = array_keys(get_class_vars(get_class($object)));
  104. + $declaredPropertyNames = array_keys(get_object_vars($object));
  105.  
  106. foreach (get_class_methods($object) as $methodName) {
  107. if (is_callable(array($object, $methodName))) {
  108. @@ -207,7 +207,7 @@
  109. */
  110. static public function getSettablePropertyNames($object) {
  111. if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1264022994);
  112. - $declaredPropertyNames = array_keys(get_class_vars(get_class($object)));
  113. + $declaredPropertyNames = array_keys(get_object_vars($object));
  114.  
  115. foreach (get_class_methods($object) as $methodName) {
  116. if (substr($methodName, 0, 3) === 'set' && is_callable(array($object, $methodName))) {
  117. @@ -230,7 +230,7 @@
  118. */
  119. static public function isPropertySettable($object, $propertyName) {
  120. if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1259828920);
  121. - if (array_search($propertyName, array_keys(get_class_vars(get_class($object)))) !== FALSE) return TRUE;
  122. + if (array_search($propertyName, array_keys(get_object_vars($object))) !== FALSE) return TRUE;
  123. return is_callable(array($object, self::buildSetterMethodName($propertyName)));
  124. }
  125.  
  126. @@ -244,7 +244,7 @@
  127. */
  128. static public function isPropertyGettable($object, $propertyName) {
  129. if (!is_object($object)) throw new \InvalidArgumentException('$object must be an object, ' . gettype($object). ' given.', 1259828921);
  130. - if (array_search($propertyName, array_keys(get_class_vars(get_class($object)))) !== FALSE) return TRUE;
  131. + if (array_search($propertyName, array_keys(get_object_vars($object))) !== FALSE) return TRUE;
  132. if (is_callable(array($object, 'get' . ucfirst($propertyName)))) return TRUE;
  133. return is_callable(array($object, 'is' . ucfirst($propertyName)));
  134. }
Add Comment
Please, Sign In to add comment