Skip to content

Stop relying on the $mode argument #21986

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

Merged
merged 1 commit into from
Mar 14, 2017

Conversation

greg0ire
Copy link
Contributor

When registering the error handler, simple-phpunit might be used, and in
that case, the bootstrap process will not have environment variables
defined inside phpunit.xml.dist . This means $mode might differ when
registering the error handler, and when an error is triggered.
This raises a question: should the $mode argument be removed to avoid
similar errors in the future?

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? yes/no
Deprecations? yes/no
Tests pass? yes/no
Fixed tickets #21980
License MIT
Doc PR n/a

When registering the error handler, simple-phpunit might be used, and in
that case, the bootstrap process will not have environment variables
defined inside phpunit.xml.dist . This means `$mode` might differ when
registering the error handler, and when an error is triggered.
This raises a question: should the $mode argument be removed to avoid
similar errors in the future?
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

should the $mode argument be removed to avoid
similar errors in the future?

The argument is used, so I'm not sure how that would look like without it. Not sure there is anything to do here.

@greg0ire
Copy link
Contributor Author

@nicolas-grekas it would imply doing the following change :

-$getMode = function () use ($mode) {
+$getMode = function () {
      static $memoizedMode = false;
 
      if (false !== $memoizedMode) {
          return $memoizedMode;
      }
-     if (false === $mode) {
-         $mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
-     }
+     $mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
      if (DeprecationErrorHandler::MODE_WEAK !== $mode && DeprecationErrorHandler::MODE_WEAK_VENDORS !== $mode && (!isset($mode[0]) || '/' !== $mode[0])) {
          $mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
      }
 
      return $memoizedMode = $mode;
 };

Not sure if dropping support for that kind of usage would be acceptable, so I think I see your point now.

@nicolas-grekas
Copy link
Member

The env var is not and should become the only way to configure the bridge.
This means there is nothing else to change to me :)

@greg0ire
Copy link
Contributor Author

Failed to parse your sentence 😕

@theofidry
Copy link
Contributor

should the $mode argument be removed to avoided

Not sure, I think it's fair to use if it has a valid value and try to get the env variable only if is false. So IMO nothing to change on that side.

When registering the error handler, simple-phpunit might be used

Actually the bug occurs with phpunit as well. Not just simple-phpunit (I didn't use it when reported the bug).

IMO this piece of could should work seamlessly with both PhpUnit and SimplePhpUnit. Two ways to avoid the issue you had [doing this kind of error]:

  • Have a proper review: the person in charge of it knows the potential risks and ought to try locally the changes if not obvious...
  • Have proper integration tests, but they are not trivial and may not be worth it. The first point may be enough

@greg0ire
Copy link
Contributor Author

greg0ire commented Mar 13, 2017

@nicolas-grekas Oh you meant "and should not"? If yes I understand and agree.

@greg0ire
Copy link
Contributor Author

@theofidry I did not reproduce the bug with phpunit though… did you? When you call phpunit, the bootstrap script is just vendor/autoload.php. When you use simple-phpunit… there are two bootstrap scripts?

@theofidry
Copy link
Contributor

theofidry commented Mar 13, 2017

@greg0ire I did in https://github.com/theofidry/phpunitbridge-demo1. Tbh I didn't even try with simple-phpunit... The bootstrap file is app/autoload.php (specified in phpunit.xml.dist).

@xabbuh
Copy link
Member

xabbuh commented Mar 13, 2017

Isn't this a bugfix and should then be merged into lower branches too?

@greg0ire
Copy link
Contributor Author

It's a bugfix, but the feature is not released yet

@xabbuh
Copy link
Member

xabbuh commented Mar 13, 2017

Sorry, missed that this change was introduced in #21539.

👍

@greg0ire
Copy link
Contributor Author

No problem, thanks for caring!

@nicolas-grekas
Copy link
Member

Thank you @greg0ire.

@nicolas-grekas nicolas-grekas merged commit 0d180d5 into symfony:master Mar 14, 2017
nicolas-grekas added a commit that referenced this pull request Mar 14, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

Stop relying on the $mode argument

When registering the error handler, simple-phpunit might be used, and in
that case, the bootstrap process will not have environment variables
defined inside phpunit.xml.dist . This means `$mode` might differ when
registering the error handler, and when an error is triggered.
This raises a question: should the $mode argument be removed to avoid
similar errors in the future?

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | yes/no
| Deprecations? | yes/no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes/no
| Fixed tickets | #21980
| License       | MIT
| Doc PR        | n/a

<!--
- Bug fixes must be submitted against the lowest branch where they apply
  (lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the master branch.
- Please fill in this template according to the PR you're about to submit.
- Replace this comment by a description of what your PR is solving.
-->

Commits
-------

0d180d5 Stop relying on the $mode argument
@greg0ire greg0ire deleted the stop_relying_on_mode branch March 14, 2017 07:37
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