EregToPregFixerTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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\Alias;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Matteo Beccati <matteo@beccati.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Alias\EregToPregFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Alias\EregToPregFixer>
  22. */
  23. final class EregToPregFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return iterable<int|string, array{0: string, 1?: string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield ['<?php $x = 1;'];
  38. yield ['<?php $x = "ereg";'];
  39. yield ['<?php $x = ereg("[A-Z]"."foo", $m);'];
  40. yield ['<?php $x = ereg("^*broken", $m);'];
  41. yield ['<?php $x = Foo::split("[A-Z]", $m);'];
  42. yield ['<?php $x = $foo->split("[A-Z]", $m);'];
  43. yield ['<?php $x = Foo\split("[A-Z]", $m);'];
  44. yield [
  45. '<?php $x = preg_match(\'/[A-Z]/D\');',
  46. '<?php $x = ereg(\'[A-Z]\');',
  47. ];
  48. yield [
  49. '<?php $x = preg_match(\'/[A-Z]/D\', $m);',
  50. '<?php $x = ereg(\'[A-Z]\', $m);',
  51. ];
  52. yield [
  53. '<?php $x = preg_match("/[A-Z]/D", $m);',
  54. '<?php $x = ereg("[A-Z]", $m);',
  55. ];
  56. yield [
  57. '<?php $x = preg_match("/[A-Z]/Di", $m);',
  58. '<?php $x = eregi("[A-Z]", $m);',
  59. ];
  60. yield [
  61. '<?php $x = preg_match("#/[AZ]#D", $m);',
  62. '<?php $x = ereg("/[AZ]", $m);',
  63. ];
  64. yield [
  65. '<?php $x = preg_match("#[AZ]/#D", $m);',
  66. '<?php $x = ereg("[AZ]/", $m);',
  67. ];
  68. yield [
  69. '<?php $x = preg_match("!#[A]/!D", $m);',
  70. '<?php $x = ereg("#[A]/", $m);',
  71. ];
  72. yield [
  73. '<?php $x = preg_match("!##[A\!]//!D", $m);',
  74. '<?php $x = ereg("##[A!]//", $m);',
  75. ];
  76. yield [
  77. '<?php $x = preg_match("/##[A!!]\/\//D", $m);',
  78. '<?php $x = ereg("##[A!!]//", $m);',
  79. ];
  80. yield [
  81. '<?php $x = preg_match("#\#\#[A!!]///#D", $m);',
  82. '<?php $x = ereg("##[A!!]///", $m);',
  83. ];
  84. yield [
  85. '<?php $x = preg_replace("/[A-Z]/D", "", $m);',
  86. '<?php $x = ereg_replace("[A-Z]", "", $m);',
  87. ];
  88. yield [
  89. '<?php $x = preg_replace("/[A-Z]/Di", "", $m);',
  90. '<?php $x = eregi_replace("[A-Z]", "", $m);',
  91. ];
  92. yield [
  93. '<?php $x = preg_split("/[A-Z]/D", $m);',
  94. '<?php $x = split("[A-Z]", $m);',
  95. ];
  96. yield [
  97. '<?php $x = preg_split("/[A-Z]/Di", $m);',
  98. '<?php $x = spliti("[A-Z]", $m);',
  99. ];
  100. yield 'binary lowercase' => [
  101. '<?php $x = preg_split(b"/[A-Z]/Di", $m);',
  102. '<?php $x = spliti(b"[A-Z]", $m);',
  103. ];
  104. yield 'binary uppercase' => [
  105. '<?php $x = preg_split(B"/[A-Z]/Di", $m);',
  106. '<?php $x = spliti(B"[A-Z]", $m);',
  107. ];
  108. }
  109. /**
  110. * @dataProvider provideFix81Cases
  111. *
  112. * @requires PHP 8.1
  113. */
  114. public function testFix81(string $expected, ?string $input = null): void
  115. {
  116. $this->doTest($expected, $input);
  117. }
  118. /**
  119. * @return iterable<array{string}>
  120. */
  121. public static function provideFix81Cases(): iterable
  122. {
  123. yield [
  124. '<?php $x = spliti(...);',
  125. ];
  126. }
  127. }