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

Skip to content

phpunit-bridge ignores <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" /> in phpunit.xml #28519

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
soerenbernstein opened this issue Sep 19, 2018 · 4 comments

Comments

@soerenbernstein
Copy link
Contributor

Symfony version(s) affected: all ?

Description
phpunit-bridge ignores the value "disabled" for the environment variable SYMFONY_DEPRECATIONS_HELPER when set in phpunit.xml. The value "weak" works as expected.
Also, setting this environment variable in the shell works as expected.

Tested with phpunit-bridge-4.1.4

How to reproduce
set in phpunit.xml

<php>
  <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
</php>

and run a test which will cause a deprecation warning.

@soerenbernstein
Copy link
Contributor Author

I've fiddle around a bit. Maybe DeprecationErrorHandler.php:57 is missing a test for DeprecationErrorHandler::MODE_DISABLED?
At first glance it seems to fix the problem, but I'm not sure about possible side effects.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 20, 2018

"disabled" mode is taken into account in https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/bootstrap.php#L38 - as you can see, this comes earlier than reading the phpunit.xml file.
We could actually change https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php#L105 and read $_ENV['SYMFONY_DEPRECATIONS_HELPER'] there also.
Would you like to submit a PR doing so?

@soerenbernstein
Copy link
Contributor Author

Actually, getenv('SYMFONY_DEPRECATIONS_HELPER') in https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/bootstrap.php#L38 will only report environment variables from the shell at that moment. Parameters from phpunit.xml are probably not parsed yet?

As far as I understand the code - and I might be completely off on this - the problem is, that in https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php#L104 the mode parameter is reset to 0 because of https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php#L57 not recognizing "disabled" as a valid value for mode, trying to parse an integer, fails and falls back to 0.

In consequence mode will never be set to "disabled" in https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php#L105.

@nicolas-grekas
Copy link
Member

That's why I used $_ENV in my previous comment. Did you try using it?

nicolas-grekas added a commit that referenced this issue Sep 20, 2018
…g phpunit.xml file (soerenbernstein)

This PR was submitted for the master branch but it was squashed and merged into the 3.4 branch instead (closes #28524).

Discussion
----------

[PhpUnitBridge] fix disabling DeprecationErrorHandler using phpunit.xml file

Fixing #28519

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | don't know
| Fixed tickets | #28519
| License       | MIT

Commits
-------

3cd929b [PhpUnitBridge] fix disabling DeprecationErrorHandler using phpunit.xml file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants