ProcessLinterTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\Linter;
  12. use PhpCsFixer\Linter\ProcessLinter;
  13. use PhpCsFixer\Test\AccessibleObject;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Linter\ProcessLinter
  20. * @covers \PhpCsFixer\Linter\ProcessLintingResult
  21. */
  22. final class ProcessLinterTest extends AbstractLinterTestCase
  23. {
  24. public function testIsAsync()
  25. {
  26. $this->assertTrue($this->createLinter()->isAsync());
  27. }
  28. /**
  29. * @param string $executable
  30. * @param string $file
  31. * @param string $expected
  32. *
  33. * @testWith ["php", "foo.php", "'php' '-l' 'foo.php'"]
  34. * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "'C:\\Program Files\\php\\php.exe' '-l' 'foo bar\\baz.php'"]
  35. * @requires OS Linux
  36. */
  37. public function testPrepareCommandOnPhpOnLinux($executable, $file, $expected)
  38. {
  39. if (defined('HHVM_VERSION')) {
  40. $this->markTestSkipped('Skip tests for PHP compiler when running on HHVM compiler.');
  41. }
  42. $this->assertSame(
  43. $expected,
  44. AccessibleObject::create(new ProcessLinter($executable))->prepareProcess($file)->getCommandLine()
  45. );
  46. }
  47. /**
  48. * @param string $executable
  49. * @param string $file
  50. * @param string $expected
  51. *
  52. * @testWith ["php", "foo.php", "php -l foo.php"]
  53. * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
  54. * @requires OS Win
  55. */
  56. public function testPrepareCommandOnPhpOnWindows($executable, $file, $expected)
  57. {
  58. $this->assertSame(
  59. $expected,
  60. AccessibleObject::create(new ProcessLinter($executable))->prepareProcess($file)->getCommandLine()
  61. );
  62. }
  63. public function testPrepareCommandOnHhvm()
  64. {
  65. if (!defined('HHVM_VERSION')) {
  66. $this->markTestSkipped('Skip tests for HHVM compiler when running on PHP compiler.');
  67. }
  68. $this->assertSame(
  69. "'hhvm' '--php' '-l' 'foo.php'",
  70. AccessibleObject::create(new ProcessLinter('hhvm'))->prepareProcess('foo.php')->getCommandLine()
  71. );
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. protected function createLinter()
  77. {
  78. return new ProcessLinter();
  79. }
  80. }