TestCase.php 774 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace tests;
  3. /**
  4. * This is the base class for all yii framework unit tests.
  5. */
  6. abstract class TestCase extends \PHPUnit\Framework\TestCase
  7. {
  8. /**
  9. * Invokes a inaccessible method.
  10. * @param $object
  11. * @param $method
  12. * @param array $args
  13. * @param bool $revoke whether to make method inaccessible after execution
  14. * @return mixed
  15. */
  16. protected function invokeMethod($object, $method, $args = [], $revoke = true)
  17. {
  18. $reflection = new \ReflectionObject($object);
  19. $method = $reflection->getMethod($method);
  20. $method->setAccessible(true);
  21. $result = $method->invokeArgs($object, $args);
  22. if ($revoke) {
  23. $method->setAccessible(false);
  24. }
  25. return $result;
  26. }
  27. }