BacktickToShellExecFixerTest.php 1.6 KB

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