Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for env, server and ini settings in parallel test runs #28995

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

Conversation

alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented Oct 26, 2018

Q A
Branch? 4.3
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #28895 ( maybe related: #28726, symfony/recipes#476 )
License MIT

This fixes problems with $_SERVER and ENV Variables in parallel test runs and that the bootstrap script was not called in parallel test runs.

Currently was most of the logic based on the main phpunit.xml.dist file. This did require me to rewrite the logic based that there are multiple phpunit.xml.dist files. As passing the configuration file via --configuration flag phpunit seems correctly read the env and server configuration and use the correct bootstrap file.

See with the following test setup which does not work and how this script fixes the errors
https://github.com/alexander-schranz/symfony-phpunit-test.

Checklist:

  • fixed env vars in parallel test runs
  • fixed force attribute of env vars in parallel test runs
  • fixed server vars in parallel test runs
  • fixed ini_set in parallel test runs
  • fixed call of bootstrap file in parallel test runs
  • fixed different phpunit version in parallel test runs
  • added functional tests for simple-phpunit script
  • fixed problem when install was canceled before in middle of phpunit installation
  • fixed different SYMFONY_PHPUNIT_REMOVE variable in parallel test runs

@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch from aaf5916 to 80298a9 Compare October 26, 2018 17:25
@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Oct 26, 2018

Cannot reproduce the CI error locally: ./phpunit install -> Cannot open file "install.php".

Any hint? /cc @nicolas-grekas

@alexander-schranz alexander-schranz changed the title Fixed env and server vars in parallel test suites Fixed env and server vars in parallel test suites and allow different phpunit version Oct 26, 2018
@alexander-schranz alexander-schranz changed the title Fixed env and server vars in parallel test suites and allow different phpunit version Fixed different phpunit configurations in parallel test runs Oct 26, 2018
@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch from 697ac35 to f52ec82 Compare October 26, 2018 20:18
@nicolas-grekas
Copy link
Member

Thats' a pretty big change. Shouldn't we consider it as a new feature?
Note that we should use anonymous functions instead of global ones as we shouldn't pollute the global function space.

@alexander-schranz alexander-schranz changed the title Fixed different phpunit configurations in parallel test runs Added support for env var and ini settings in parallel test runs Oct 27, 2018
@alexander-schranz alexander-schranz changed the title Added support for env var and ini settings in parallel test runs Added support for env, server and ini settings in parallel test runs Oct 27, 2018
@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Oct 27, 2018

@nicolas-grekas did change it to anonymous functions. from my case we can consider it as a new feature, but not sure what to add/change at the documentation because think most people think that the phpunit config variables would also be used in parallel test runs?

Could now reproduce and fix the travis ci bug locally by changing the ./phpunit file using the new simple-phpunit binary:

diff --git a/phpunit b/phpunit
index f4b80ed064..e88c75c331 100755
--- a/phpunit
+++ b/phpunit
@@ -11,4 +11,5 @@ if (\PHP_VERSION_ID >= 70000 && !getenv('SYMFONY_PHPUNIT_VERSION')) {
     putenv('SYMFONY_PHPUNIT_VERSION=6.5');
 }
 putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
-require __DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit';
+require __DIR__.'/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit';

Should we maybe use always the simple-phpunit from repository not from vendor to avoid this kind of problems for contributors?

But can't reproduce the current error its really hard to understand what the travis script does, would be better as a php script that you can run it also locally on all operation systems.

@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch 11 times, most recently from b95c00c to 0a205e8 Compare October 27, 2018 21:15
@nicolas-grekas
Copy link
Member

Should we maybe use always the simple-phpunit from repository not from vendor to avoid this kind of problems for contributors?

nope, the reason being that we want to use the latest version of the bridge to test the lowest maintained Symfony versions (2.8 for now, so PHP 5.3.3 should still be supported).
At the end of November, 2.8 will be released so that we'll be able to bump the minimum PHP version of the bridge to PHP 5.5.9.

if (false !== $value = getenv($name)) {
return $value;
}
global $argv, $argc, $PHP, $getEnvVar;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about passing them as contexts for functions rather than using a global ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Taluu followed your suggestion and did avoid any usage of global

@Taluu
Copy link
Contributor

Taluu commented Oct 29, 2018

@nicolas-grekas Using anonymous functions like that and globalizing their containers (variables) like this, I wonder if using the global function scope wouldn't be better... Or maybe adding a namespace in the simple-phpunit file, to restrict these functions in said namespace could be better ?

@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch from 17c4180 to de5eaf2 Compare December 2, 2018 23:08
@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch 2 times, most recently from d0bb431 to fe4e2ba Compare December 20, 2018 16:34
@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch 2 times, most recently from 7de6e17 to fe9b089 Compare January 13, 2019 14:55
@alexander-schranz alexander-schranz changed the title Added support for env, server and ini settings in parallel test runs Add support for env, server and ini settings in parallel test runs Jan 14, 2019
@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch from fe9b089 to ef60bdb Compare January 16, 2019 23:00
@alexander-schranz
Copy link
Contributor Author

@nicolas-grekas any news to this?

@nicolas-grekas
Copy link
Member

Please rebase.

@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch 3 times, most recently from cd48c3d to 1cebd48 Compare January 28, 2019 08:27
@alexander-schranz
Copy link
Contributor Author

@nicolas-grekas done.

@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch from 1cebd48 to fb08ec5 Compare February 6, 2019 22:43
@fabpot
Copy link
Member

fabpot commented Mar 4, 2019

@nicolas-grekas I think we're waiting for you here :)

@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch from fb08ec5 to 8a90931 Compare March 11, 2019 21:38
@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Apr 2, 2019

@nicolas-grekas if you have time we could have also a look at this at the EU-FOSSA Hackathon

@nicolas-grekas
Copy link
Member

Sure, please rebase meanwhile ;)

@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch from 8a90931 to de43901 Compare April 7, 2019 10:09
@alexander-schranz alexander-schranz force-pushed the bugfix/fixed-env-server-vars-parallel-testsuites branch from de43901 to 07674a4 Compare April 7, 2019 10:18
@fabpot
Copy link
Member

fabpot commented Apr 8, 2019

@nicolas-grekas Rebase done ;)

@nicolas-grekas
Copy link
Member

I feel like the expectations implemented by this PR are wrong, here is why:
running this with the original phpunit doesn't read the phpunit.xml.dist in the subdirectories.

Try running e.g. phpunit src/Symfony/Bundle/FrameworkBundle/ - this doesn't read src/Symfony/Bundle/FrameworkBundle/phpunit.xml.dist - thus doesn't read its bootstrap.php

Running ./phpunit src/Symfony/Bundle/FrameworkBundle/ should produce the same result.

@alexander-schranz
Copy link
Contributor Author

@nicolas-grekas didn't know that the original phpunit allows to give a folder 🙈 thought that was a symfony only feature. Yeah it definitly make sense that the result then is the same as using the original phpunit file.

@nicolas-grekas
Copy link
Member

Closing as discussed, thanks.

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants