BacktickToShellExecFixerTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Filippo Tessarotto <zoeslam@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Alias\BacktickToShellExecFixer
  20. */
  21. final class BacktickToShellExecFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. public static function provideFixCases(): iterable
  31. {
  32. yield 'plain' => [
  33. '<?php shell_exec("ls -lah");',
  34. '<?php `ls -lah`;',
  35. ];
  36. yield 'with variables' => [
  37. '<?php shell_exec("$var1 ls ${var2} -lah {$var3} file1.txt {$var4[0]} file2.txt {$var5->call()}");',
  38. '<?php `$var1 ls ${var2} -lah {$var3} file1.txt {$var4[0]} file2.txt {$var5->call()}`;',
  39. ];
  40. yield 'with single quote' => [
  41. <<<'EOT'
  42. <?php
  43. `echo a\'b`;
  44. `echo 'ab'`;
  45. EOT
  46. ,
  47. ];
  48. yield 'with double quote' => [
  49. <<<'EOT'
  50. <?php
  51. `echo a\"b`;
  52. `echo 'a"b'`;
  53. EOT
  54. ,
  55. ];
  56. yield 'with backtick' => [
  57. <<<'EOT'
  58. <?php
  59. `echo 'a\`b'`;
  60. `echo a\\\`b`;
  61. EOT
  62. ,
  63. ];
  64. }
  65. }