NoMultilineWhitespaceAroundDoubleArrowFixerTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 Carlos Cirello <carlos.cirello.nl@gmail.com>
  16. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  17. * @author Graham Campbell <hello@gjcampbell.co.uk>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer
  22. *
  23. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer>
  24. */
  25. final class NoMultilineWhitespaceAroundDoubleArrowFixerTest 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{0: string, 1?: string}>
  36. */
  37. public static function provideFixCases(): iterable
  38. {
  39. yield [
  40. '<?php
  41. $arr = array(
  42. $a => array(1),
  43. $a => array(0 => array())
  44. );',
  45. '<?php
  46. $arr = array(
  47. $a =>
  48. array(1),
  49. $a =>
  50. array(0 =>
  51. array())
  52. );',
  53. ];
  54. yield [
  55. '<?php
  56. $a = array(
  57. "aaaaaa" => "b",
  58. "c" => "d",
  59. "eeeeee" => array(),
  60. "ggg" => array(),
  61. "hh" => [],
  62. );',
  63. '<?php
  64. $a = array(
  65. "aaaaaa" => "b",
  66. "c"
  67. =>
  68. "d",
  69. "eeeeee" => array(),
  70. "ggg" =>
  71. array(),
  72. "hh" =>
  73. [],
  74. );',
  75. ];
  76. yield [
  77. '<?php
  78. $hello = array(
  79. "foo" =>
  80. // hello there
  81. "value",
  82. "hi" =>
  83. /*
  84. * Description.
  85. */1,
  86. "ha" =>
  87. /**
  88. * Description.
  89. */
  90. array()
  91. );',
  92. ];
  93. yield [
  94. '<?php
  95. $fn = fn() => null;',
  96. '<?php
  97. $fn = fn()
  98. =>
  99. null;',
  100. ];
  101. yield [
  102. '<?php
  103. $foo = [
  104. 1 /* foo */ => $one,
  105. 2 => $two
  106. ];',
  107. '<?php
  108. $foo = [
  109. 1 /* foo */
  110. =>
  111. $one,
  112. 2
  113. =>
  114. $two
  115. ];',
  116. ];
  117. yield [
  118. '<?php
  119. $foo = [
  120. 1 // foo
  121. => $one,
  122. 2 => $two,
  123. ];',
  124. '<?php
  125. $foo = [
  126. 1 // foo
  127. =>
  128. $one,
  129. 2
  130. =>
  131. $two,
  132. ];',
  133. ];
  134. }
  135. }