Reflection.getPropertyDeclaringClass.overwrite.phpt 1005 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 $foo;
  12. }
  13. trait B
  14. {
  15. use A;
  16. protected $foo;
  17. }
  18. class C
  19. {
  20. use B;
  21. protected $foo;
  22. }
  23. class D extends C
  24. {
  25. protected $foo;
  26. }
  27. // Property in class
  28. Assert::same('D', Reflection::getPropertyDeclaringClass(new ReflectionProperty('D', 'foo'))->getName());
  29. // Property in class - wrong, but impossible to solve in PHP https://github.com/nette/di/issues/169
  30. Assert::same('A', Reflection::getPropertyDeclaringClass(new ReflectionProperty('C', 'foo'))->getName());
  31. // Property in trait - wrong, but impossible to solve in PHP https://github.com/nette/di/issues/169
  32. Assert::same('A', Reflection::getPropertyDeclaringClass(new ReflectionProperty('B', 'foo'))->getName());
  33. // Property in trait
  34. Assert::same('A', Reflection::getPropertyDeclaringClass(new ReflectionProperty('A', 'foo'))->getName());