ObjectHelpers.getMagicProperites().phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Test: Nette\Utils\ObjectHelpers::getMagicProperties()
  4. */
  5. declare(strict_types=1);
  6. use Nette\Utils\ObjectHelpers;
  7. use Tester\Assert;
  8. require __DIR__ . '/../bootstrap.php';
  9. /**
  10. * @property int $getter
  11. * @property int $getter2 by ref
  12. * @property int $setter
  13. * @property A\B $both with typehint
  14. * @property int $missing
  15. * @property int $Upper
  16. * @property int $cAse
  17. * @property int $private
  18. * @property int $protected
  19. * @property int $static
  20. * @property-read int $read
  21. * @property-write int $write
  22. * @property-x int $invalid1
  23. * @property $invalid2
  24. * abc @property int $invalid3
  25. */
  26. class TestClass
  27. {
  28. public function getGetter()
  29. {
  30. }
  31. public function &isGetter2()
  32. {
  33. }
  34. public function setSetter()
  35. {
  36. }
  37. public function getBoth()
  38. {
  39. }
  40. public function setBoth()
  41. {
  42. }
  43. public function getUpper()
  44. {
  45. }
  46. public function getCase()
  47. {
  48. }
  49. private function getPrivate()
  50. {
  51. }
  52. protected function getProtected()
  53. {
  54. }
  55. public static function getStatic()
  56. {
  57. }
  58. public function getRead()
  59. {
  60. }
  61. public function setRead()
  62. {
  63. }
  64. public function getWrite()
  65. {
  66. }
  67. public function setWrite()
  68. {
  69. }
  70. public function getInvalid()
  71. {
  72. }
  73. public function getInvalid2()
  74. {
  75. }
  76. }
  77. Assert::same([], ObjectHelpers::getMagicProperties('stdClass'));
  78. Assert::same([
  79. 'getter' => 0b0011,
  80. 'getter2' => 0b0101,
  81. 'setter' => 0b1000,
  82. 'both' => 0b1011,
  83. 'Upper' => 0b0011,
  84. 'protected' => 0b0011,
  85. 'read' => 0b0011,
  86. 'write' => 0b1000,
  87. ], ObjectHelpers::getMagicProperties('TestClass'));
  88. /**
  89. * @property int $bar
  90. */
  91. class ParentClass
  92. {
  93. public function getFoo()
  94. {
  95. }
  96. }
  97. /**
  98. * @property int $foo
  99. */
  100. class ChildClass extends ParentClass
  101. {
  102. public function getBar()
  103. {
  104. }
  105. }
  106. Assert::same([], ObjectHelpers::getMagicProperties('ParentClass'));
  107. Assert::same(['foo' => 0b0011], ObjectHelpers::getMagicProperties('ChildClass'));