NormalizeIndexBraceFixerTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\ArrayNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\ArrayNotation\NormalizeIndexBraceFixer
  20. *
  21. * @requires PHP <8.0
  22. *
  23. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ArrayNotation\NormalizeIndexBraceFixer>
  24. */
  25. final class NormalizeIndexBraceFixerTest extends AbstractFixerTestCase
  26. {
  27. /**
  28. * @dataProvider provideFixCases
  29. */
  30. public function testFix(string $expected, ?string $input = null): void
  31. {
  32. $this->doTest($expected, $input);
  33. }
  34. /**
  35. * @return iterable<array{string, string}>
  36. */
  37. public static function provideFixCases(): iterable
  38. {
  39. yield [
  40. '<?php echo $arr[$index];',
  41. '<?php echo $arr{$index};',
  42. ];
  43. yield [
  44. '<?php echo $nestedArray[$index][$index2][$index3][$index4];',
  45. '<?php echo $nestedArray{$index}{$index2}[$index3]{$index4};',
  46. ];
  47. yield [
  48. '<?php echo $array[0]->foo . $collection->items[1]->property;',
  49. '<?php echo $array{0}->foo . $collection->items{1}->property;',
  50. ];
  51. }
  52. }