Arrays.invoke.phpt 600 B

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