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

Skip to content

turned deprecation notices as fatal when running unit tests #13644

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

fabpot
Copy link
Member

@fabpot fabpot commented Feb 10, 2015

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

<!-- Disable E_USER_DEPRECATED until 3.0 -->
<!-- php -r 'echo -1 & ~E_USER_DEPRECATED;' -->
<ini name="error_reporting" value="-16385"/>
<ini name="error_reporting" value="-1" />
Copy link
Member

Choose a reason for hiding this comment

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

I suggest removing this entirely from the phpunit config (as done before the change avoiding deprecation failures). What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

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

agree

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's great to set the expectation here, code should work fine with the highest level of error reporting (it was unsafe to rely on the PHP setting IMO).

Copy link
Member

Choose a reason for hiding this comment

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

Explicit better than implicite here for me also

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't that the default value that phpunit sets anyway?

Copy link
Member

Choose a reason for hiding this comment

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

I think not: phpunit just keeps values from php.ini

Copy link
Contributor

Choose a reason for hiding this comment

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

True, I just tested it. It uses whatever is configured in your own php.ini which by default probably does not enable all errors because PHPs default is not so strict. So I agree it should be set explicitly to -1.

@Tobion
Copy link
Contributor

Tobion commented Feb 10, 2015

I think this should be done in the 2.3 branch. For some reason the deprecations are also ignored in the components 2.3 branches even though there are no deprecations triggered at all. So <ini name="error_reporting" value="-1" /> should be set in all phpunit.xml.dist starting in 2.3

Edit: PR for 2.3 #13652

@Tobion
Copy link
Contributor

Tobion commented Feb 10, 2015

I guess the reason is that tests in symfony components/bundles that require other symfony components will also trigger deprecation warnings when it uses the >=2.7 version of them.
This shows that the <2.7 branch of symfony bundles will not be compatible with the >=2.7 branch of symfony components because internal code still triggers deprecations warnings. The problem is that our fixes has mostly only been applied to the 2.7 branch where we triggered the deprecations.

For example, the 2.3 branch of FrameworkBundle will still trigger deprecations when used with the 2.7 branch of Routing component. This is because https://github.com/symfony/symfony/pull/13361/files#diff-e0e88bc9bb34bea0301096304e2701b5 was only fixed in 2.7 but not in 2.3.

To avoid this problem in the future, I think it makes more sense to add deprecation triggers IMMEDIATLY when it was actually marked as that. This will allow us to see code fragments in symfony we need to change to not trigger deprecation warnings immediatly. Our current process is really hard to maintain as we add triggers later and then only realize we need to fix other calling parts in older branches.

@Tobion
Copy link
Contributor

Tobion commented Feb 10, 2015

One solution is to backport many fixes to older branches which is quite alot of work.
Or we say in our composer dependencies that <2.7 is not compatible with >=2.7.
E.g. FrameworkBundle 2.3-2.6 requires symfony/routing: ~2.3, <2.7

@fabpot
Copy link
Member Author

fabpot commented Feb 17, 2015

see #13398

@fabpot fabpot closed this Feb 17, 2015
fabpot added a commit that referenced this pull request Feb 21, 2015
This PR was merged into the 2.7 branch.

Discussion
----------

[PhpUnit] new PhpUnit bridge

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #13644
| License       | MIT
| Doc PR        | -

From the proposed README:

PHPUnit Bridge
==============

Provides utilities for PHPUnit, especially user deprecation notices management.

It comes with the following features:

 * disable the garbage collector;
 * auto-register `class_exists` to load Doctrine annotations;
 * print a user deprecation notices summary at the end of the test suite.

Handling user deprecation notices is sensitive to the SYMFONY_DEPRECATIONS_HELPER
environment variable. This env var configures 3 behaviors depending on its value:

 * when set to `strict`, all but legacy-tagged deprecation notices will make tests
   fail. This is the recommended mode for best forward compatibility.
 * `weak` on the contrary will make tests ignore all deprecation notices.
   This is the recommended mode for legacy projects that must use deprecated
   interfaces for backward compatibility reasons.
 * any other value will respect the current error reporting level.

All three modes will display a summary of deprecation notices at the end of the
test suite, split in two groups:

 * **Legacy** deprecation notices denote tests that explicitly test some legacy
   interfaces. In all 3 modes, deprecation notices triggered in a legacy-tagged
   test do never make a test fail. There are four ways to mark a test as legacy:
    - make its class start with the `Legacy` prefix;
    - make its method start with `testLegacy`;
    - make its data provider start with `provideLegacy` or `getLegacy`;
    - add the `@group legacy` annotation to its class or method.
 * **Remaining/Other** deprecation notices are all other (non-legacy)
   notices, grouped by message, test class and method.

Usage
-----

Add this bridge to the `require-dev` section of your composer.json file
(not in `require`) with e.g.
`composer require --dev "symfony/phpunit-bridge"`.

When running `phpunit`, you will see a summary of deprecation notices at the end
of the test suite.

Deprecation notices in the **Remaining/Other** section need some thought.
You have to decide either to:

 * update your code to not use deprecated interfaces anymore, thus gaining better
   forward compatibility;
 * or move them to the **Legacy** section (by using one of the above way).

After reviewing them, you should silence deprecations in the **Legacy** section
if you think they are triggered by tests dedicated to testing deprecated
interfaces. To do so, add the following line at the beginning of your legacy
test case or in the `setUp()` method of your legacy test class:
`$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);`

Last but not least, you should then configure your C.I. to the reporting mode
that is appropriated to your project by setting SYMFONY_DEPRECATIONS_HELPER to
`strict`, `weak` or empty. It is recommended to start with `weak` mode, upgrade
your code as described above, then when the *Remaining/Other* sections are empty,
move to `strict` to keep forward compatibility on the long run.

Commits
-------

acac734 [PhpUnitBridge] new bridge for testing with PHPUnit
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.

4 participants