Skip to content
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

PHP options should be passed to child processes #4664

Closed
robsontenorio opened this issue May 5, 2021 · 15 comments
Closed

PHP options should be passed to child processes #4664

robsontenorio opened this issue May 5, 2021 · 15 comments
Labels
feature/process-isolation Issues related to running tests in separate PHP processes type/bug Something is broken

Comments

@robsontenorio
Copy link

Q A
PHPUnit version 9.5
PHP version 8.0.3
Installation Method Composer

Summary

Regression of #3506

@remicollet can you confirm?

@robsontenorio robsontenorio added the type/bug Something is broken label May 5, 2021
@robsontenorio robsontenorio reopened this May 6, 2021
@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@sebastianbergmann sebastianbergmann added the status/waiting-for-feedback Waiting for feedback from original reporter label May 6, 2021
@robsontenorio
Copy link
Author

robsontenorio commented May 6, 2021

Hi @sebastianbergmann ! Thanks for answering :)

Here is the minimal, self-contained, reproducing test case that shows my issue. README included.

https://github.com/robsontenorio/bug-phpunit

It seems php options are not passed to child proccess when using @runTestsInSeparateProcesses

php -d pcov.enabled=1 ./vendor/bin/phpunit .....

@sebastianbergmann sebastianbergmann removed the status/waiting-for-feedback Waiting for feedback from original reporter label May 7, 2021
@ktomk
Copy link
Contributor

ktomk commented May 8, 2021

@krakjoe:

Given $config is with sections (parse_ini_file(, true)) and $value is the name of the ini directive, $config[$value] never is the value of the directive of the same name as in $value.

$config = parse_ini_file($ini, true); -> $config = parse_ini_file($ini, false);

https://3v4l.org/TMrtr -> https://3v4l.org/B6TQY

@robsontenorio
Copy link
Author

Please, note pcov is disabled by default. As suggested on its docs.

I am enabling pcov on demand with “php -d pcov.enabled=1 ...”

@krakjoe
Copy link
Contributor

krakjoe commented May 8, 2021

Now that I look again, we're only interested in selected settings ...

        foreach ($files as $ini) {
            $config = parse_ini_file($ini, false);

            foreach ($values as $value) {
                $set = ini_get($value);

		        if ($set == null) {
			        continue;
		        }

                if ((!isset($config[$value]) || ($set != $config[$value]))) {
                    $diff[$value] = sprintf('%s=%s', $value, $set);
                }
            }
        }

That ought to do it ?

@sebastianbergmann sebastianbergmann added the feature/process-isolation Issues related to running tests in separate PHP processes label Jun 7, 2021
@ciltocruz
Copy link

What about this? My tests doesn't recognize xdebug extension when coverage is executed and my test has @runTestsInSeparateProcesses annotation...

@ktomk
Copy link
Contributor

ktomk commented Sep 7, 2021

What about this? My tests doesn't recognize xdebug extension when coverage is executed and my test has @runTestsInSeparateProcesses annotation...

until further traction, please try with the XDEBUG_MODE environment parameter (exported), it works across all processes in the same environment (as long as the PHP CLI config loads the xdebug extension by default), so it won't need the mode ini setting passed along explicitly via command-line args (explicitly by -d flags or via a temporary ini-file) @ciltocruz

@ciltocruz
Copy link

What about this? My tests doesn't recognize xdebug extension when coverage is executed and my test has @runTestsInSeparateProcesses annotation...

until further traction, please try with the XDEBUG_MODE environment parameter (exported), it works across all processes in the same environment (as long as the PHP CLI config loads the xdebug extension by default), so it won't need the mode ini setting passed along explicitly via command-line args (explicitly by -d flags or via a temporary ini-file) @ciltocruz

Thanks for your help, @ktomk.
This is only for Xdebug 3?

I am using PHPStorm on Windows... Maybe this could be a problem...

@ktomk
Copy link
Contributor

ktomk commented Sep 8, 2021

This is only for Xdebug 3?

Yes, the XDEBUG_MODE environment parameter is for the currently supported Xdebug version only and does not apply to Xdebug version 2.

I am using PHPStorm on Windows... Maybe this could be a problem...

Please see Environment Variables - Command Line area - PHPUnit ... maybe it helps.

@ciltocruz
Copy link

Hello, @ktomk

With the environment variable, my tests works.

Thanks for your help.

@dingo-d
Copy link

dingo-d commented Apr 2, 2022

Any words on fixing this issue?

@sebastianbergmann
Copy link
Owner

I do not have time to work on this myself, but I would take the time to review a pull request.

@sebastianbergmann
Copy link
Owner

@robsontenorio Can you verify that sebastianbergmann/environment#63 fixes this for you? Thanks!

@dingo-d
Copy link

dingo-d commented May 18, 2022

@sebastianbergmann I've tested the issue @robsontenorio reported (with his example from the link), when I put the PHPUnit to version ^8 I got

bash-5.1# php -d pcov.enabled=1 ./vendor/bin/phpunit
PHPUnit 8.5.26 #StandWithUkraine

  Warning - The configuration file did not pass validation!
  The following problems have been detected:

  Line 11:
  - Element 'coverage': This element is not expected.

  Test results may not be as expected.


..                                                                  2 / 2 (100%)

Time: 232 ms, Memory: 4.00 MB

When I set the PHPUnit to be ^9.5, the latest environment package gets pulled and the results are correct:

bash-5.1# php -d pcov.enabled=1 ./vendor/bin/phpunit
PHPUnit 9.5.20 #StandWithUkraine

..                                                                  2 / 2 (100%)

Time: 00:00.357, Memory: 10.00 MB

OK (2 tests, 2 assertions)

Generating code coverage report in Clover XML format ... done [00:00.018]

Generating code coverage report in HTML format ... done [00:00.156]

So I'd say that the issue is fixed.

@robsontenorio
Copy link
Author

Thanks @dingo-d !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/process-isolation Issues related to running tests in separate PHP processes type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

6 participants