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

Skip to content

[PhpUnit] new PhpUnit bridge #13398

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
Feb 21, 2015
Merged

Conversation

nicolas-grekas
Copy link
Member

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.

}
],
"require": {
"php": ">=5.3.3"
Copy link
Member Author

Choose a reason for hiding this comment

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

Not 5.3.9 to allow standalone reuse on older projects

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
private static function hasColorSupport()
{
if (DIRECTORY_SEPARATOR == '\\') {
Copy link
Member

Choose a reason for hiding this comment

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

should be ===

},
"autoload": {
"psr-0": { "Symfony\\Component\\Testing\\": "" },
"files": [ "bootstrap.php" ]
Copy link
Member

Choose a reason for hiding this comment

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

this seems wrong to me. You want the bootstrap.php file to be loaded only when running the testsuite of your project, not when running your project locally (and you don't want to need to reinstall the project without dev requirements all the time during development

@nicolas-grekas nicolas-grekas force-pushed the testing-component branch 2 times, most recently from 8e58ddf to 25b69fd Compare January 13, 2015 14:54
}
],
"require": {
"php": ">=5.3.3"
Copy link
Contributor

Choose a reason for hiding this comment

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

">=5.3.9" is requirement since 6dc8979

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I overlooked the original comment on the "outdated diff", where it is sated that it is intentionally, so my last comment can be ignored

},
"autoload-dev": {
"files": [ "Resources/bootstrap/symfony.php" ]
},
Copy link
Member

Choose a reason for hiding this comment

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

you are aware that this won't be used when the package is required in another package? Dev config will only be tracked when the package is the root package.

@wouterj
Copy link
Member

wouterj commented Jan 14, 2015

I don't like it's name, as it doesn't really provide much testing help apart from easing the transition between 2.x and 3.x. Maybe we're going to need more utilities for this transition, what about renaming this component to have all this utilities?

wouterj referenced this pull request in FriendsOfSymfony/FOSHttpCacheBundle Jan 21, 2015
…reak the build if we treat deprecated as an error
@nicolas-grekas nicolas-grekas changed the title [Testing] new testing component [PhpUnit] new PhpUnit bridge Feb 11, 2015
@nicolas-grekas
Copy link
Member Author

Talking a bit with some others, I'm going to move this to src/Symfony/Bridge/PhpUnit

@nicolas-grekas nicolas-grekas force-pushed the testing-component branch 4 times, most recently from 2322d42 to 1d35ce6 Compare February 11, 2015 22:15

if (class_exists('Doctrine\Common\Annotations\AnnotationRegistry')) {
AnnotationRegistry::registerLoader('class_exists');
}
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

not needed. The MongoDB annotations are autoloadable, so this is enough to register them (registering class_exists in the AnnotationRegistry is enough as long as all your autoloaders are handling properly the case of a non-existant class, i.e. not breaking class_exists)

@nicolas-grekas nicolas-grekas force-pushed the testing-component branch 2 times, most recently from c636b94 to 5345d98 Compare February 16, 2015 10:02
@nicolas-grekas
Copy link
Member Author

README updated

"psr-0": { "Symfony\\Bridge\\PhpUnit\\": "" }
},
"target-dir": "Symfony/Bridge/PhpUnit",
"minimum-stability": "dev",
Copy link
Member

Choose a reason for hiding this comment

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

this seems a bit odd, as it has no dependencies

@nicolas-grekas nicolas-grekas force-pushed the testing-component branch 4 times, most recently from 20c61f3 to 5124a11 Compare February 18, 2015 06:57
PHPUnit Bridge
==============

Utilities for PHPUnit, especially user deprecation notices management.
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure that it was not what I proposed. We have a uniform way to describe each component in one sentence. So, it should be Provides utilities ...


Provides utilities for PHPUnit, especially user deprecation notices management.

It comesa with the following features:
Copy link
Member

Choose a reason for hiding this comment

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

typo comes

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

"license": "MIT",
"authors": [
{
"name": "Nicolas Grekas",
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what approach we are following here. But Form and PropertyAccess Component for example created by Bernhard have Fabien as author. So it's kinda inconsistent. I guess we should either only add the Symfony Community, or maybe all Mergers as author. This way it also helps as reference to find a contact person.

Copy link
Member Author

Choose a reason for hiding this comment

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

As a matter of fact, I'm the author of this component... @fabpot is the copyright owner mentionned in the LICENSE file, but I wrote the code. This is just plain descriptive truth. If someone else wrote some other component (or a significant non-trivial part of it), he/she should also be mentionned as author IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine because he already had things like this merged https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/VarDumper/composer.json#L10 and it just makes sense. If the other components were attributed to @fabpot well that is because it was ok with their authors perhaps.

@nicolas-grekas
Copy link
Member Author

Please note that I modified the .travis file to ignore tests in the legacy group. There are no tests tagged @group legacy right now, but this should happen because when removing legacy interface from 3.0, the legacy tests will not work anymore, when a 2.7 test uses a 3.0 component.
We could even add the annotation in all legacy tests right now. What do you think about it?


* 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

test suite output?

@fabpot
Copy link
Member

fabpot commented Feb 21, 2015

Thank you @nicolas-grekas.

@fabpot fabpot merged commit acac734 into symfony:2.7 Feb 21, 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
@nicolas-grekas nicolas-grekas deleted the testing-component branch March 1, 2015 10:12
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.

9 participants