BacktickToShellExecFixerTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. return [
  33. 'plain' => [
  34. '<?php shell_exec("ls -lah");',
  35. '<?php `ls -lah`;',
  36. ],
  37. 'with variables' => [
  38. '<?php shell_exec("$var1 ls ${var2} -lah {$var3} file1.txt {$var4[0]} file2.txt {$var5->call()}");',
  39. '<?php `$var1 ls ${var2} -lah {$var3} file1.txt {$var4[0]} file2.txt {$var5->call()}`;',
  40. ],
  41. 'with single quote' => [
  42. <<<'EOT'
  43. <?php
  44. `echo a\'b`;
  45. `echo 'ab'`;
  46. EOT
  47. ,
  48. ],
  49. 'with double quote' => [
  50. <<<'EOT'
  51. <?php
  52. `echo a\"b`;
  53. `echo 'a"b'`;
  54. EOT
  55. ,
  56. ],
  57. 'with backtick' => [
  58. <<<'EOT'
  59. <?php
  60. `echo 'a\`b'`;
  61. `echo a\\\`b`;
  62. EOT
  63. ,
  64. ],
  65. ];
  66. }
  67. }