Reflection.getDeclaringMethod.insteadof.phpt 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Reflection::getDeclaringMethod
  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. public function foo()
  12. {
  13. }
  14. }
  15. trait B
  16. {
  17. public function foo()
  18. {
  19. }
  20. }
  21. class C
  22. {
  23. use A;
  24. use B {
  25. B::foo insteadof A;
  26. }
  27. }
  28. class D
  29. {
  30. use A;
  31. use B {
  32. B::foo insteadof A;
  33. }
  34. public function foo()
  35. {
  36. }
  37. }
  38. function get(ReflectionMethod $m)
  39. {
  40. $res = Reflection::getMethodDeclaringMethod($m);
  41. return $res->getDeclaringClass()->name . '::' . $res->name;
  42. }
  43. // Method in class
  44. Assert::same('D::foo', get(new ReflectionMethod('D', 'foo')));
  45. // Method in trait - uses doccomment & file-line workaround
  46. Assert::same('B::foo', get(new ReflectionMethod('C', 'foo')));
  47. // Method in trait
  48. Assert::same('B::foo', get(new ReflectionMethod('B', 'foo')));
  49. // Method in trait
  50. Assert::same('A::foo', get(new ReflectionMethod('A', 'foo')));