8000 symfony/phpunit-bridge: also set APP_ENV in $_ENV by fancyweb · Pull Request #1014 · symfony/recipes · GitHub
[go: up one dir, main page]

Skip to content

symfony/phpunit-bridge: also set APP_ENV in $_ENV #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

fancyweb
Copy link
Contributor
Q A
License MIT
Doc issue/PR symfony/symfony-docs#...

Ref #561 (comment)

I just got a problem with this change, since APP_ENV exists in $_SERVER, Dotenv does not set it in $_ENV (https://github.com/symfony/dotenv/blob/46a528ca327e0cb7fa7493a98ed3aebef8a516ac/Dotenv.php#L195), so $_ENV['APP_ENV'] does not exist when running the tests. Could we set both (server and env) in the phpunit config?

More context: I used \Symfony\Component\Process\PhpProcess in one of my test, and was expecting to have the same env vars as the current test process in the executed code by PhpProcess (because according to the doc: $env The environment variables or null to use the same environment as the current PHP process), including the APP_ENV var.

But it doesn't work because $_ENV['APP_ENV'] does not exist + since putenv() is disabled by default in Dotenv, the Process code doesn't take it from $_SERVER (see https://github.com/symfony/process/blob/38f26c7d6ed535217ea393e05634cb0b244a1967/Process.php#L1665).

Or maybe we need to apply the same strategy in Process than in Dotenv, ie not using getenv() and instead exclude $_SERVER values whose key starts with HTTP_?

@github-actions
Copy link

Thanks for the PR 😍

How to test these changes in your application

  1. Define the SYMFONY_ENDPOINT environment variable:

    # On *nix and Mac
    export SYMFONY_ENDPOINT=https://api.github.com/repos/symfony/recipes/contents/index.json?ref=flex/pull-1014
    # On Windows
    SET SYMFONY_ENDPOINT=https://api.github.com/repos/symfony/recipes/contents/index.json?ref=flex/pull-1014
  2. Install the package(s) related to this recipe:

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

    # On *nix and Mac
    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.

phpunit/phpunit

4.7 vs 9.3
diff --git a/phpunit/phpunit/4.7/phpunit.xml.dist b/phpunit/phpunit/9.3/phpunit.xml.dist
index 71f7fa1..be0e514 100644
--- a/phpunit/phpunit/4.7/phpunit.xml.dist
+++ b/phpunit/phpunit/9.3/phpunit.xml.dist
@@ -6,6 +6,7 @@
          backupGlobals="false"
          colors="true"
          bootstrap="tests/bootstrap.php"
+         convertDeprecationsToExceptions="false"
 >
     <php>
         <ini name="display_errors" value="1" />
@@ -13,6 +14,8 @@
         <env name="APP_ENV" value="test" force="true" />
         <server name="APP_ENV" value="test" force="true" />
         <server name="SHELL_VERBOSITY" value="-1" />
+        <server name="SYMFONY_PHPUNIT_REMOVE" value="" />
+        <server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
     </php>
 
     <testsuites>
@@ -21,11 +24,11 @@
         </testsuite>
     </testsuites>
 
-    <filter>
-        <whitelist processUncoveredFilesFromWhitelist="true">
+    <coverage processUncoveredFiles="true">
+        <include>
             <directory suffix=".php">src</directory>
-        </whitelist>
-    </filter>
+        </include>
+    </coverage>
 
     <listeners>
         <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />

symfony/phpunit-bridge

3.3 vs 4.1
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 f7ea505..ab039d7 100644
--- a/symfony/phpunit-bridge/3.3/phpunit.xml.dist
+++ b/symfony/phpunit-bridge/4.1/phpunit.xml.dist
@@ -8,11 +8,12 @@
          bootstrap="tests/bootstrap.php"
 >
     <php>
-        <ini name="display_errors" value="1" />
         <ini name="error_reporting" value="-1" />
         <env name="APP_ENV" value="test" force="true" />
         <server name="APP_ENV" value="test" force="true" />
         <server name="SHELL_VERBOSITY" value="-1" />
+        <server name="SYMFONY_PHPUNIT_REMOVE" value="" />
+        <server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />
     </php>
 
     <testsuites>
@@ -22,8 +23,8 @@
     </testsuites>
 
     <filter>
-        <whitelist>
-            <directory>src</directory>
+        <whitelist processUncoveredFilesFromWhitelist="true">
+            <directory suffix=".php">src</directory>
         </whitelist>
     </filter>
 
4.1 vs 4.3
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
 <?php
 
-if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
-    echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
+if (!file_exists(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);
 }
 
@@ -10,4 +10,4 @@ if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
     putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
 }
 
-require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit';
+require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
diff --git a/symfony/phpunit-bridge/4.1/phpunit.xml.dist b/symfony/phpunit-bridge/4.3/phpunit.xml.dist
index ab039d7..0405f86 100644
--- a/symfony/phpunit-bridge/4.1/phpunit.xml.dist
+++ b/symfony/phpunit-bridge/4.3/phpunit.xml.dist
@@ -8,6 +8,7 @@
          bootstrap="tests/bootstrap.php"
 >
     <php>
+        <ini name="display_errors" value="1" />
         <ini name="error_reporting" value="-1" />
         <env name="APP_ENV" value="test" force="true" />
         <server name="APP_ENV" value="test" force="true" />
4.3 vs 5.1
diff --git a/symfony/phpunit-bridge/4.3/phpunit.xml.dist b/symfony/phpunit-bridge/5.1/phpunit.xml.dist
index 0405f86..45986d3 100644
--- a/symfony/phpunit-bridge/4.3/phpunit.xml.dist
+++ b/symfony/phpunit-bridge/5.1/phpunit.xml.dist
@@ -8,13 +8,12 @@
          bootstrap="tests/bootstrap.php"
 >
     <php>
-        <ini name="display_errors" value="1" />
         <ini name="error_reporting" value="-1" />
         <env name="APP_ENV" value="test" force="true" />
         <server name="APP_ENV" value="test" force="true" />
         <server name="SHELL_VERBOSITY" value="-1" />
         <server name="SYMFONY_PHPUNIT_REMOVE" value="" />
-        <server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />
+        <server name="SYMFONY_PHPUNIT_VERSION" value="8.5" />
     </php>
 
     <testsuites>
@@ -32,4 +31,11 @@
     <listeners>
         <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
     </listeners>
+
+    <!-- Run `composer require symfony/panther` before enabling this extension -->
+    <!--
+    <extensions>
+        <extension class="Symfony\Component\Panther\ServerExtension" />
+    </extensions>
+    -->
 </phpunit>
5.1 vs 5.3
diff --git a/symfony/phpunit-bridge/5.1/bin/phpunit b/symfony/phpunit-bridge/5.3/bin/phpunit
index 4d1ed05..f26f2c7 100755
--- a/symfony/phpunit-bridge/5.1/bin/phpunit
+++ b/symfony/phpunit-bridge/5.3/bin/phpunit
@@ -1,13 +1,19 @@
 #!/usr/bin/env php
 <?php
 
-if (!file_exists(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);
+if (!ini_get('date.timezone')) {
+    ini_set('date.timezone', 'UTC');
 }
 
-if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
-    putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
-}
+if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
+    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 45986d3..be0e514 100644
--- a/symfony/phpunit-bridge/5.1/phpunit.xml.dist
+++ b/symfony/phpunit-bridge/5.3/phpunit.xml.dist
@@ -2,18 +2,20 @@
 
 <!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
 <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:noNamespaceSchemaLocation="bin/.phpunit/phpunit.xsd"
+         xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
          backupGlobals="false"
          colors="true"
          bootstrap="tests/bootstrap.php"
+         convertDeprecationsToExceptions="false"
 >
     <php>
+        <ini name="display_errors" value="1" />
         <ini name="error_reporting" value="-1" />
         <env name="APP_ENV" value="test" force="true" />
         <server name="APP_ENV" value="test" force="true" />
         <server name="SHELL_VERBOSITY" value="-1" />
         <server name="SYMFONY_PHPUNIT_REMOVE" value="" />
-        <server name="SYMFONY_PHPUNIT_VERSION" value="8.5" />
+        <server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
     </php>
 
     <testsuites>
@@ -22,11 +24,11 @@
         </testsuite>
     </testsuites>
 
-    <filter>
-        <whitelist processUncoveredFilesFromWhitelist="true">
+    <coverage processUncoveredFiles="true">
+        <include>
             <directory suffix=".php">src</directory>
-        </whitelist>
-    </filter>
+        </include>
+    </coverage>
 
     <listeners>
         <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
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

@fancyweb
Copy link
Contributor Author

Closing in favor of symfony/symfony#43798.

@fancyweb fancyweb closed this Oct 28, 2021
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Oct 28, 2021
…exist (fancyweb)

This PR was merged into the 4.4 branch.

Discussion
----------

[Dotenv] Duplicate $_SERVER values in $_ENV if they don't exist

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Ref symfony/recipes#1014

`@nicolas`-grekas found the right approach and the patch. `$_SERVER` values that don't exist in `$_ENV` should be duplicated in `$_ENV` so both superglobals are coherent.

Commits
-------

08291b1 [Dotenv] Duplicate $_SERVER values in $_ENV if they don't exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0