Reflection.getDeclaringMethod.overwrite.phpt 945 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. use A;
  18. public function foo()
  19. {
  20. }
  21. }
  22. class C
  23. {
  24. use B;
  25. public function foo()
  26. {
  27. }
  28. }
  29. class D extends C
  30. {
  31. public function foo()
  32. {
  33. }
  34. }
  35. function get(ReflectionMethod $m)
  36. {
  37. $res = Reflection::getMethodDeclaringMethod($m);
  38. return $res->getDeclaringClass()->name . '::' . $res->name;
  39. }
  40. // Method in class
  41. Assert::same('D::foo', get(new ReflectionMethod('D', 'foo')));
  42. // Method in class - uses doccomment & file-line workaround
  43. Assert::same('C::foo', get(new ReflectionMethod('C', 'foo')));
  44. // Method in trait - uses doccomment & file-line workaround
  45. Assert::same('B::foo', get(new ReflectionMethod('B', 'foo')));
  46. // Method in trait
  47. Assert::same('A::foo', get(new ReflectionMethod('A', 'foo')));