NoClosingTagFixerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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\PhpTag;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\PhpTag\NoClosingTagFixer
  18. */
  19. final class NoClosingTagFixerTest extends AbstractFixerTestCase
  20. {
  21. /**
  22. * @dataProvider provideWithFullOpenTagCases
  23. */
  24. public function testWithFullOpenTag(string $expected, ?string $input = null): void
  25. {
  26. $this->doTest($expected, $input);
  27. }
  28. /**
  29. * @dataProvider provideWithShortOpenTagCases
  30. */
  31. public function testWithShortOpenTag(string $expected, ?string $input = null): void
  32. {
  33. if (!\ini_get('short_open_tag')) {
  34. self::markTestSkipped('The short_open_tag option is required to be enabled.');
  35. }
  36. $this->doTest($expected, $input);
  37. }
  38. public static function provideWithFullOpenTagCases(): iterable
  39. {
  40. yield [
  41. '<?php echo \'Foo\';',
  42. '<?php echo \'Foo\'; ?>',
  43. ];
  44. yield [
  45. '<?php echo \'Foo\';',
  46. '<?php echo \'Foo\';?>',
  47. ];
  48. yield [
  49. '<?php echo \'Foo\'; ?> PLAIN TEXT',
  50. ];
  51. yield [
  52. 'PLAIN TEXT<?php echo \'Foo\'; ?>',
  53. ];
  54. yield [
  55. '<?php
  56. echo \'Foo\';',
  57. '<?php
  58. echo \'Foo\';
  59. ?>',
  60. ];
  61. yield [
  62. '<?php echo \'Foo\'; ?>
  63. <p><?php echo \'this is a template\'; ?></p>
  64. <?php echo \'Foo\'; ?>',
  65. ];
  66. yield [
  67. '<?php echo "foo";',
  68. '<?php echo "foo" ?>',
  69. ];
  70. yield [
  71. '<?php
  72. class foo
  73. {
  74. public function bar()
  75. {
  76. echo "Here I am!";
  77. }
  78. }',
  79. '<?php
  80. class foo
  81. {
  82. public function bar()
  83. {
  84. echo "Here I am!";
  85. }
  86. }?>',
  87. ];
  88. yield [
  89. '<?php
  90. function bar()
  91. {
  92. echo "Here I am!";
  93. }',
  94. '<?php
  95. function bar()
  96. {
  97. echo "Here I am!";
  98. }?>',
  99. ];
  100. yield [
  101. '<?php
  102. if (true) {
  103. echo "Here I am!";
  104. }',
  105. '<?php
  106. if (true) {
  107. echo "Here I am!";
  108. }?>',
  109. ];
  110. yield 'Trailing linebreak, priority issue with SingleBlankLineAtEofFixer.' => [
  111. '<?php echo 1;',
  112. "<?php echo 1;\n?>\n",
  113. ];
  114. yield 'Trailing comment.' => [
  115. '<?php echo 1;// test',
  116. "<?php echo 1;// test\n?>",
  117. ];
  118. yield 'No code' => [
  119. '<?php ',
  120. '<?php ?>',
  121. ];
  122. yield 'No code, only comment' => [
  123. '<?php /* license */',
  124. '<?php /* license */ ?>',
  125. ];
  126. yield [
  127. '<?php ?>aa',
  128. ];
  129. }
  130. public static function provideWithShortOpenTagCases(): iterable
  131. {
  132. yield [
  133. '<? echo \'Foo\';',
  134. '<? echo \'Foo\'; ?>',
  135. ];
  136. yield [
  137. '<? echo \'Foo\';',
  138. '<? echo \'Foo\';?>',
  139. ];
  140. yield [
  141. '<? echo \'Foo\'; ?>
  142. <p><? echo \'this is a template\'; ?></p>
  143. <? echo \'Foo\'; ?>',
  144. ];
  145. yield [
  146. '<? /**/', '<? /**/?>',
  147. ];
  148. yield [
  149. '<?= "somestring"; ?> <?= "anotherstring"; ?>',
  150. ];
  151. yield [
  152. '<?= 1;',
  153. '<?= 1; ?>',
  154. ];
  155. }
  156. }