Browse Source

minor #3134 Allow Symfony 4 (keradus, garak)

This PR was merged into the 2.2 branch.

Discussion
----------

Allow Symfony 4

See #3124

Commits
-------

7269aab3 ProcessLinterProcessBuilder - stop using ProcessBuilder
392b3934 Allow Symfony 4
Dariusz Ruminski 7 years ago
parent
commit
628c2f0733

+ 2 - 1
.travis.yml

@@ -47,6 +47,7 @@ jobs:
             install:
                 # Composer: enforce given Symfony components version
                 - 'if [ "$SYMFONY_VERSION" != "" ]; then sed -i "s/\"symfony\/\([^\"]*\)\": \"^2[^\"]*\"/\"symfony\/\1\": \"$SYMFONY_VERSION\"/g" composer.json; fi'
+                - 'if [ "$MIN_STABILITY" != "" ]; then composer config minimum-stability $MIN_STABILITY; fi'
 
                 - travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
                 - composer info -D | sort
@@ -78,7 +79,7 @@ jobs:
         -
             <<: *STANDARD_TEST_JOB
             php: 7.1
-            env: PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER=1
+            env: PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER=1 SYMFONY_VERSION="^4.0" MIN_STABILITY=dev
 
         -
             <<: *STANDARD_TEST_JOB

+ 8 - 8
composer.json

@@ -21,24 +21,24 @@
         "doctrine/annotations": "^1.2",
         "gecko-packages/gecko-php-unit": "^2.0",
         "sebastian/diff": "^1.4",
-        "symfony/console": "^2.4 || ^3.0",
-        "symfony/event-dispatcher": "^2.1 || ^3.0",
-        "symfony/filesystem": "^2.4 || ^3.0",
-        "symfony/finder": "^2.2 || ^3.0",
-        "symfony/options-resolver": "^2.6 || ^3.0",
+        "symfony/console": "^2.4 || ^3.0 || ^4.0",
+        "symfony/event-dispatcher": "^2.1 || ^3.0 || ^4.0",
+        "symfony/filesystem": "^2.4 || ^3.0 || ^4.0",
+        "symfony/finder": "^2.2 || ^3.0 || ^4.0",
+        "symfony/options-resolver": "^2.6 || ^3.0 || ^4.0",
         "symfony/polyfill-php54": "^1.0",
         "symfony/polyfill-php55": "^1.3",
         "symfony/polyfill-php70": "^1.0",
         "symfony/polyfill-php72": "^1.4",
-        "symfony/process": "^2.3 || ^3.0",
-        "symfony/stopwatch": "^2.5 || ^3.0"
+        "symfony/process": "^2.3 || ^3.0 || ^4.0",
+        "symfony/stopwatch": "^2.5 || ^3.0 || ^4.0"
     },
     "require-dev": {
         "johnkary/phpunit-speedtrap": "^1.0.1",
         "justinrainbow/json-schema": "^5.0",
         "phpunit/phpunit": "^4.8.35 || ^5.4.3",
         "php-coveralls/php-coveralls": "^1.0.2",
-        "symfony/phpunit-bridge": "^3.2.2"
+        "symfony/phpunit-bridge": "^3.2.2 || ^4.0"
     },
     "suggest": {
         "ext-mbstring": "For handling non-UTF8 characters in cache signature.",

+ 6 - 10
src/Linter/ProcessLinterProcessBuilder.php

@@ -13,7 +13,6 @@
 namespace PhpCsFixer\Linter;
 
 use Symfony\Component\Process\Process;
-use Symfony\Component\Process\ProcessBuilder;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
@@ -42,14 +41,11 @@ final class ProcessLinterProcessBuilder
      */
     public function build($path)
     {
-        // @TODO change at 2.4 to:
-        // return ProcessBuilder::create(['-l', $path])->setPrefix($this->executable)->getProcess();
-
-        $arguments = array('-l', $path);
-        if (defined('HHVM_VERSION')) {
-            array_unshift($arguments, '--php');
-        }
-
-        return ProcessBuilder::create($arguments)->setPrefix($this->executable)->getProcess();
+        return new Process(sprintf(
+            '"%s"%s -l "%s"',
+            $this->executable,
+            defined('HHVM_VERSION') ? ' --php' : '',
+            $path
+        ));
     }
 }

+ 4 - 4
tests/Linter/ProcessLinterProcessBuilderTest.php

@@ -29,8 +29,8 @@ final class ProcessLinterProcessBuilderTest extends TestCase
      * @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'"]
+     * @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|Darwin
      */
     public function testPrepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
@@ -53,7 +53,7 @@ final class ProcessLinterProcessBuilderTest extends TestCase
      * @param string $file
      * @param string $expected
      *
-     * @testWith ["php", "foo.php", "php -l foo.php"]
+     * @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
      */
@@ -79,7 +79,7 @@ final class ProcessLinterProcessBuilderTest extends TestCase
         $builder = new ProcessLinterProcessBuilder('hhvm');
 
         $this->assertSame(
-            "'hhvm' '--php' '-l' 'foo.php'",
+            '"hhvm" --php -l "foo.php"',
             $builder->build('foo.php')->getCommandLine()
         );
     }