Skip to content

[PhpUnitBridge] fix deprecation triggering test detection #24597

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
Oct 24, 2017

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Oct 17, 2017

Q A
Branch? 3.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #24548 (comment), #24568
License MIT
Doc PR

@xabbuh xabbuh added this to the 3.3 milestone Oct 17, 2017
@xabbuh xabbuh requested a review from nicolas-grekas October 17, 2017 17:17
@fabpot fabpot changed the base branch from master to 3.3 October 17, 2017 21:44
@nicolas-grekas
Copy link
Member

Would that fix and replace #24575 also?

@xabbuh
Copy link
Member Author

xabbuh commented Oct 18, 2017

I am not sure. I did not fully understand the issue that is going to be fixed in #24575.

ping @alexpott

@alexpott
Copy link
Contributor

I don't think this will fix #24575 but I'm pretty certain it will fix #24568

$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
$method = $trace[$i]['function'];
$Test = $UtilPrefix.'Test';
if (isset($trace[$i]['class']) && 'Symfony\Bridge\PhpUnit\SymfonyTestsListener' === $trace[$i]['class']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to deal with the fact that this might be the legacy version?
ie. \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener

Copy link
Member Author

Choose a reason for hiding this comment

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

That's no problem as the trait is called by the listener. That's why we see the listener here.

Copy link
Member

Choose a reason for hiding this comment

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

@xabbuh and that's precisely what @alexpott is saying: we have 2 listeners. you deal with only one of them.

Copy link
Member Author

Choose a reason for hiding this comment

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

hum indeed, fixed

} else {
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
$method = $trace[$i]['function'];
$Test = $UtilPrefix.'Test';
Copy link
Contributor

Choose a reason for hiding this comment

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

$Test is not assigned if the class is Symfony\Bridge\PhpUnit\SymfonyTestsListener. This might cause problems in the later if

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, fixed

@@ -264,9 +264,9 @@ public function endTest($test, $time)
unlink($this->runsInSeparateProcess);
foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
if ($deprecation[0]) {
trigger_error($deprecation[1], E_USER_DEPRECATED);
trigger_error(serialize(array('deprecation' => $deprecation[1], 'class' => $deprecation[2], 'method' => $deprecation[3])), E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the class and method here need to be determined by $test and not what's in $deprecation

Copy link
Contributor

Choose a reason for hiding this comment

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

This code happens to work for \Symfony\Bridge\PhpUnit\Tests\ProcessIsolationTest() because the deprecation takes place in the test method. However, that won't be the case for a deprecation occurring in non test code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, we don't want to show the code triggering the deprecation. But we want to display a summary of tests that lead to these deprecations. Because you either need to fix the code executed by these tests or you will have to add these tests to the legacy group.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I totally agree but that's not what is in $deprecation[2] and $deprecation[3]. These contain the code that has triggered the deprecation not the test. That's in $test.

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 don't think so. We filter the stack trace before serealizing the same way as we do when not running tests in isolation. Do you have an example that wouldn't work?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see I missed that :( sorry. I've tested with a deprecation in another file and you're correct that the stack trace filtering works. I kinda think that using $test is simpler but you're right it works.

@alexpott
Copy link
Contributor

If we go this route of adding the test and method to the deprecation thrown by ::endTest() then we also need to parse out the message in \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::handleError() so that the @expectedDeprecation annotation works.

@xabbuh
Copy link
Member Author

xabbuh commented Oct 18, 2017

Do you have an example of what wouldn't work otherwise? I mean the message is never touched, is it?

@alexpott
Copy link
Contributor

Here are the changes I think we need to address the points from my review:
alexpott@6f45707

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit da617e8 into symfony:3.3 Oct 24, 2017
nicolas-grekas added a commit that referenced this pull request Oct 24, 2017
…(xabbuh)

This PR was merged into the 3.3 branch.

Discussion
----------

[PhpUnitBridge] fix deprecation triggering test detection

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24548 (comment), #24568
| License       | MIT
| Doc PR        |

Commits
-------

da617e8 fix deprecation triggering test detection
@nicolas-grekas
Copy link
Member

@alexpott I'm merging because this fixes our builds on branches 2.7 and 2.8. But in alexpott@6f45707#commitcomment-25097923 there is one remaining question for you. Does this mean you identified another edge case?

@xabbuh xabbuh deleted the pr-24548 branch October 24, 2017 16:11
symfony-splitter pushed a commit to symfony/phpunit-bridge that referenced this pull request Oct 24, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

Fix deprecation triggering test deduction

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

<!--
- 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 3.4,
  legacy code removals go to 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.
-->
This PR is just testing some additions symfony/symfony#24597 - I want to see if the travis run is successful.

Commits
-------

5333680 Fix review points
nicolas-grekas added a commit that referenced this pull request Oct 24, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

Fix deprecation triggering test deduction

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

<!--
- 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 3.4,
  legacy code removals go to 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.
-->
This PR is just testing some additions #24597 - I want to see if the travis run is successful.

Commits
-------

5333680 Fix review points
@fabpot fabpot mentioned this pull request Oct 30, 2017
@fabpot fabpot mentioned this pull request Oct 30, 2017
@fabpot fabpot mentioned this pull request Nov 10, 2017
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