ElseifFixerTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\Fixer\ControlStructure;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Leszek Prabucki <leszek.prabucki@gmail.com>
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\ControlStructure\ElseifFixer
  19. */
  20. final class ElseifFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param null|string $input
  25. *
  26. * @dataProvider provideTestFixCases
  27. */
  28. public function testFix($expected, $input = null)
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. public function provideTestFixCases()
  33. {
  34. return [
  35. ['<?php if ($some) { $test = true; } else { $test = false; }'],
  36. [
  37. '<?php if ($some) { $test = true; } elseif ($some !== "test") { $test = false; }',
  38. '<?php if ($some) { $test = true; } else if ($some !== "test") { $test = false; }',
  39. ],
  40. [
  41. '<?php if ($some) { $test = true; } elseif ($some !== "test") { $test = false; }',
  42. '<?php if ($some) { $test = true; } else if ($some !== "test") { $test = false; }',
  43. ],
  44. [
  45. '<?php $js = \'if (foo.a) { foo.a = "OK"; } else if (foo.b) { foo.b = "OK"; }\';',
  46. ],
  47. [
  48. '<?php
  49. if ($a) {
  50. $x = 1;
  51. } elseif ($b) {
  52. $x = 2;
  53. }',
  54. '<?php
  55. if ($a) {
  56. $x = 1;
  57. } else
  58. if ($b) {
  59. $x = 2;
  60. }',
  61. ],
  62. [
  63. '<?php
  64. if ($a) {
  65. } elseif/**/ ($b) {
  66. }
  67. ',
  68. '<?php
  69. if ($a) {
  70. } else /**/ if ($b) {
  71. }
  72. ',
  73. ],
  74. [
  75. '<?php
  76. if ($a) {
  77. } elseif//
  78. ($b) {
  79. }
  80. ',
  81. '<?php
  82. if ($a) {
  83. } else //
  84. if ($b) {
  85. }
  86. ',
  87. ],
  88. [
  89. '<?php if ($a) {} /**/elseif ($b){}',
  90. '<?php if ($a) {} /**/else if ($b){}',
  91. ],
  92. ['<?php if ($x) { foo(); } else if ($y): bar(); endif;'],
  93. ];
  94. }
  95. }