|
@@ -14,7 +14,6 @@ namespace PhpCsFixer\Tests\Linter;
|
|
|
|
|
|
use PhpCsFixer\Linter\ProcessLinter;
|
|
|
use PhpCsFixer\Test\AccessibleObject;
|
|
|
-use Symfony\Component\Process\ProcessUtils;
|
|
|
|
|
|
/**
|
|
|
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
|
|
@@ -31,20 +30,41 @@ final class ProcessLinterTest extends AbstractLinterTestCase
|
|
|
$this->assertTrue($this->createLinter()->isAsync());
|
|
|
}
|
|
|
|
|
|
- public function testPrepareCommandOnPhp()
|
|
|
+ /**
|
|
|
+ * @param string $executable
|
|
|
+ * @param string $file
|
|
|
+ * @param string $expected
|
|
|
+ *
|
|
|
+ * @testWith ["php", "foo.php", "'php' '-l' 'foo.php'"]
|
|
|
+ * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "'C:\\Program Files\\php\\php.exe' '-l' 'foo bar\\baz.php'"]
|
|
|
+ * @requires OS Linux
|
|
|
+ */
|
|
|
+ public function testPrepareCommandOnPhpOnLinux($executable, $file, $expected)
|
|
|
{
|
|
|
if (defined('HHVM_VERSION')) {
|
|
|
$this->markTestSkipped('Skip tests for PHP compiler when running on HHVM compiler.');
|
|
|
}
|
|
|
|
|
|
$this->assertSame(
|
|
|
- $this->fixEscape('"php" -l "foo.php"'),
|
|
|
- AccessibleObject::create(new ProcessLinter('php'))->prepareCommand('foo.php')
|
|
|
+ $expected,
|
|
|
+ AccessibleObject::create(new ProcessLinter($executable))->prepareProcess($file)->getCommandLine()
|
|
|
);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * @param string $executable
|
|
|
+ * @param string $file
|
|
|
+ * @param string $expected
|
|
|
+ *
|
|
|
+ * @testWith ["php", "foo.php", "php -l foo.php"]
|
|
|
+ * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
|
|
|
+ * @requires OS Win
|
|
|
+ */
|
|
|
+ public function testPrepareCommandOnPhpOnWindows($executable, $file, $expected)
|
|
|
+ {
|
|
|
$this->assertSame(
|
|
|
- $this->fixEscape('"C:\Program Files\php\php.exe" -l "foo bar\baz.php"'),
|
|
|
- AccessibleObject::create(new ProcessLinter('C:\Program Files\php\php.exe'))->prepareCommand('foo bar\baz.php')
|
|
|
+ $expected,
|
|
|
+ AccessibleObject::create(new ProcessLinter($executable))->prepareProcess($file)->getCommandLine()
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -55,8 +75,8 @@ final class ProcessLinterTest extends AbstractLinterTestCase
|
|
|
}
|
|
|
|
|
|
$this->assertSame(
|
|
|
- $this->fixEscape('"hhvm" --php -l "foo.php"'),
|
|
|
- AccessibleObject::create(new ProcessLinter('hhvm'))->prepareCommand('foo.php')
|
|
|
+ "'hhvm' '--php' '-l' 'foo.php'",
|
|
|
+ AccessibleObject::create(new ProcessLinter('hhvm'))->prepareProcess('foo.php')->getCommandLine()
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -67,31 +87,4 @@ final class ProcessLinterTest extends AbstractLinterTestCase
|
|
|
{
|
|
|
return new ProcessLinter();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Fix escaping character.
|
|
|
- *
|
|
|
- * Escape character may be different on various environments.
|
|
|
- * This method change used escape character into character that is default
|
|
|
- * for environment.
|
|
|
- *
|
|
|
- * @param string $value value to be fixed
|
|
|
- * @param string $usedEscapeChar used escape char, may be only ' or "
|
|
|
- *
|
|
|
- * @return string
|
|
|
- */
|
|
|
- private function fixEscape($value, $usedEscapeChar = '"')
|
|
|
- {
|
|
|
- static $escapeChar = null;
|
|
|
-
|
|
|
- if (null === $escapeChar) {
|
|
|
- $escapeChar = ProcessUtils::escapeArgument('x')[0];
|
|
|
- }
|
|
|
-
|
|
|
- if ($usedEscapeChar === $escapeChar) {
|
|
|
- return $value;
|
|
|
- }
|
|
|
-
|
|
|
- return str_replace($usedEscapeChar, $escapeChar, $value);
|
|
|
- }
|
|
|
}
|