symfony / recipes

Symfony Recipes Repository
https://github.com/symfony/recipes/blob/flex/main/RECIPES.md
MIT License
956 stars 472 forks source link

Fix bin/phpunit for PHPUnit 10 #1249

Closed derrabus closed 8 months ago

derrabus commented 8 months ago
Q A
License MIT
Doc issue/PR N/A

Fixes #1248.

Our bin/phpunit calls the PHPUnit from the vendor folder, if we use Composer to install PHPUnit. Instead of calling require on PHPUnit's entrypoint directly, we call internal PHPUnit classes to bootstrap the CLI runner.

The reason for that was that PHPUnit's bin script contains a shebang (#!/usr/bin/env php) which would be output on PHP 7. On PHP 8 however, that limitation is gone and with it the reason for our workaround. Calling require on PHPUnit's entrypoint makes the bin/phpunit script more resilient against future internal changes in PHPUnit and allows the script to function with PHPUnit 10.

github-actions[bot] commented 8 months ago

Thanks for the PR 😍

How to test these changes in your application

  1. Define the SYMFONY_ENDPOINT environment variable:

    # On Unix-like (BSD, Linux and macOS)
    export SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1249/index.json
    # On Windows
    SET SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1249/index.json
  2. Install the package(s) related to this recipe:

    composer req 'symfony/flex:^1.16'
    composer req 'symfony/phpunit-bridge:^6.3'
  3. Don't forget to unset the SYMFONY_ENDPOINT environment variable when done:

    # On Unix-like (BSD, Linux and macOS)
    unset SYMFONY_ENDPOINT
    # On Windows
    SET SYMFONY_ENDPOINT=

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes. I'm going keep this comment up to date with any updates of the attached patch.

symfony/phpunit-bridge

3.3 vs 4.1 ```diff diff --git a/symfony/phpunit-bridge/3.3/.env.test b/symfony/phpunit-bridge/4.1/.env.test index 24a43c0..9e7162f 100644 --- a/symfony/phpunit-bridge/3.3/.env.test +++ b/symfony/phpunit-bridge/4.1/.env.test @@ -2,3 +2,5 @@ KERNEL_CLASS='App\Kernel' APP_SECRET='$ecretf0rt3st' SYMFONY_DEPRECATIONS_HELPER=999999 +PANTHER_APP_ENV=panther +PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots diff --git a/symfony/phpunit-bridge/3.3/bin/phpunit b/symfony/phpunit-bridge/4.1/bin/phpunit index 0b79fd4..63dae24 100755 --- a/symfony/phpunit-bridge/3.3/bin/phpunit +++ b/symfony/phpunit-bridge/4.1/bin/phpunit @@ -6,12 +6,6 @@ if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-php exit(1); } -if (false === getenv('SYMFONY_PHPUNIT_VERSION')) { - putenv('SYMFONY_PHPUNIT_VERSION=6.5'); -} -if (false === getenv('SYMFONY_PHPUNIT_REMOVE')) { - putenv('SYMFONY_PHPUNIT_REMOVE=symfony/yaml'); -} if (false === getenv('SYMFONY_PHPUNIT_DIR')) { putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit'); } diff --git a/symfony/phpunit-bridge/3.3/phpunit.xml.dist b/symfony/phpunit-bridge/4.1/phpunit.xml.dist index 294a559..d81f0c3 100644 --- a/symfony/phpunit-bridge/3.3/phpunit.xml.dist +++ b/symfony/phpunit-bridge/4.1/phpunit.xml.dist @@ -8,10 +8,11 @@ bootstrap="tests/bootstrap.php" > - + + @@ -21,8 +22,8 @@ - - src + + src ```
4.1 vs 4.3 ```diff diff --git a/symfony/phpunit-bridge/4.1/bin/phpunit b/symfony/phpunit-bridge/4.3/bin/phpunit index 63dae24..4d1ed05 100755 --- a/symfony/phpunit-bridge/4.1/bin/phpunit +++ b/symfony/phpunit-bridge/4.3/bin/phpunit @@ -1,8 +1,8 @@ #!/usr/bin/env php + ```
4.3 vs 5.1 ```diff diff --git a/symfony/phpunit-bridge/4.3/phpunit.xml.dist b/symfony/phpunit-bridge/5.1/phpunit.xml.dist index 5766779..40593c6 100644 --- a/symfony/phpunit-bridge/4.3/phpunit.xml.dist +++ b/symfony/phpunit-bridge/5.1/phpunit.xml.dist @@ -8,12 +8,11 @@ bootstrap="tests/bootstrap.php" > - - + @@ -31,4 +30,9 @@ + + ```
5.1 vs 5.3 ```diff diff --git a/symfony/phpunit-bridge/5.1/bin/phpunit b/symfony/phpunit-bridge/5.3/bin/phpunit index 4d1ed05..692bacc 100755 --- a/symfony/phpunit-bridge/5.1/bin/phpunit +++ b/symfony/phpunit-bridge/5.3/bin/phpunit @@ -1,13 +1,23 @@ #!/usr/bin/env php = 80000) { + require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit'; + } else { + define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php'); + require PHPUNIT_COMPOSER_INSTALL; + PHPUnit\TextUI\Command::main(); + } +} else { + if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) { + echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n"; + exit(1); + } -require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php'; + require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php'; +} diff --git a/symfony/phpunit-bridge/5.1/manifest.json b/symfony/phpunit-bridge/5.3/manifest.json index a2ed0cb..4fb292b 100644 --- a/symfony/phpunit-bridge/5.1/manifest.json +++ b/symfony/phpunit-bridge/5.3/manifest.json @@ -6,7 +6,6 @@ "tests/": "tests/" }, "gitignore": [ - ".phpunit", ".phpunit.result.cache", "/phpunit.xml" ], diff --git a/symfony/phpunit-bridge/5.1/phpunit.xml.dist b/symfony/phpunit-bridge/5.3/phpunit.xml.dist index 40593c6..23ea5cf 100644 --- a/symfony/phpunit-bridge/5.1/phpunit.xml.dist +++ b/symfony/phpunit-bridge/5.3/phpunit.xml.dist @@ -2,17 +2,19 @@ + - + @@ -21,11 +23,11 @@ - - + + src - - + + diff --git a/symfony/phpunit-bridge/5.1/post-install.txt b/symfony/phpunit-bridge/5.3/post-install.txt index 2db39ab..e9da2a6 100644 --- a/symfony/phpunit-bridge/5.1/post-install.txt +++ b/symfony/phpunit-bridge/5.3/post-install.txt @@ -1,2 +1,3 @@ * Write test cases in the tests/ folder - * Run php bin/phpunit + * Use MakerBundle's make:test command as a shortcut! + * Run the tests with php bin/phpunit ```
5.3 vs 6.3 ```diff diff --git a/symfony/phpunit-bridge/5.3/manifest.json b/symfony/phpunit-bridge/6.3/manifest.json index 4fb292b..482a1a4 100644 --- a/symfony/phpunit-bridge/5.3/manifest.json +++ b/symfony/phpunit-bridge/6.3/manifest.json @@ -9,5 +9,8 @@ ".phpunit.result.cache", "/phpunit.xml" ], + "conflict": { + "phpunit/phpunit": "<9.6" + }, "aliases": ["simple-phpunit"] } diff --git a/symfony/phpunit-bridge/5.3/phpunit.xml.dist b/symfony/phpunit-bridge/6.3/phpunit.xml.dist index 23ea5cf..6c4bfed 100644 --- a/symfony/phpunit-bridge/5.3/phpunit.xml.dist +++ b/symfony/phpunit-bridge/6.3/phpunit.xml.dist @@ -33,8 +33,6 @@ - ```