Arrays.invokeMethod.phpt 520 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. use Nette\Utils\Arrays;
  4. use Tester\Assert;
  5. require __DIR__ . '/../bootstrap.php';
  6. class Test1
  7. {
  8. public function fn(...$args)
  9. {
  10. return static::class . ' ' . implode(',', $args);
  11. }
  12. }
  13. class Test2 extends Test1
  14. {
  15. }
  16. $list = [new Test1, 'key' => new Test2];
  17. Assert::same(
  18. ['Test1 a,b', 'key' => 'Test2 a,b'],
  19. Arrays::invokeMethod($list, 'fn', 'a', 'b'),
  20. );
  21. Assert::same(
  22. ['Test1 a,b', 'key' => 'Test2 a,b'],
  23. Arrays::invokeMethod(new ArrayIterator($list), 'fn', 'a', 'b'),
  24. );