Reflection.getPropertyDeclaringClass.phpt 889 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Reflection::getPropertyDeclaringClass
  4. */
  5. declare(strict_types=1);
  6. use Nette\Utils\Reflection;
  7. use Tester\Assert;
  8. require __DIR__ . '/../bootstrap.php';
  9. trait A
  10. {
  11. protected $bar;
  12. }
  13. trait B
  14. {
  15. use A;
  16. protected $foo;
  17. }
  18. trait E
  19. {
  20. protected $baz;
  21. }
  22. class C
  23. {
  24. use B;
  25. use E;
  26. protected $own;
  27. }
  28. class D extends C
  29. {
  30. }
  31. // Property in trait
  32. Assert::same('B', Reflection::getPropertyDeclaringClass(new ReflectionProperty('D', 'foo'))->getName());
  33. // Property in parent trait
  34. Assert::same('A', Reflection::getPropertyDeclaringClass(new ReflectionProperty('D', 'bar'))->getName());
  35. // Property in class itself
  36. Assert::same('C', Reflection::getPropertyDeclaringClass(new ReflectionProperty('D', 'own'))->getName());
  37. // Property in second trait
  38. Assert::same('E', Reflection::getPropertyDeclaringClass(new ReflectionProperty('D', 'baz'))->getName());