AbstractFunctionReferenceFixerTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests;
  12. use PhpCsFixer\Test\AccessibleObject;
  13. use PhpCsFixer\Tokenizer\Tokens;
  14. use PHPUnit\Framework\TestCase;
  15. /**
  16. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\AbstractFunctionReferenceFixer
  21. */
  22. final class AbstractFunctionReferenceFixerTest extends TestCase
  23. {
  24. /**
  25. * @param string $code
  26. * @param int $openIndex
  27. * @param int $closeIndex
  28. * @param array $arguments
  29. *
  30. * @dataProvider provideCases
  31. */
  32. public function testCountArguments($code, $openIndex, $closeIndex, array $arguments)
  33. {
  34. $tokens = Tokens::fromCode($code);
  35. $mock = new AccessibleObject($this->getMockForAbstractClass(\PhpCsFixer\AbstractFunctionReferenceFixer::class));
  36. $this->assertSame(count($arguments), $mock->countArguments($tokens, $openIndex, $closeIndex));
  37. $this->assertSame($arguments, $mock->getArguments($tokens, $openIndex, $closeIndex));
  38. }
  39. public function provideCases()
  40. {
  41. return [
  42. ['<?php fnc();', 2, 3, []],
  43. ['<?php fnc($a);', 2, 4, [3 => 3]],
  44. ['<?php fnc($a, $b);', 2, 7, [3 => 3, 5 => 6]],
  45. ['<?php fnc($a, $b = array(1,2), $c = 3);', 2, 23, [3 => 3, 5 => 15, 17 => 22]],
  46. ];
  47. }
  48. }