Skip to content

[PhpUnitBridge] do not register the test listener twice #21787

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 27, 2017

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Feb 27, 2017

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

If the listener is already configured through the PHPUnit config, there
is no need to also enable it explicitly in the test runner.

@nicolas-grekas
Copy link
Member

As far as I remember correctly, the listener must be registered as soon as possible so that namespaced function injection work all the time (for Clock/DnsMock). If the double registration doesn't have any adverse side effect, I'd prefer be careful here, that can be tricky :)

@xabbuh
Copy link
Member Author

xabbuh commented Feb 27, 2017

I noticed this behaviour when working on #21786 (startTest() being called twice). If we need to keep the registration logic as is, I will look into another solution over there.

@xabbuh
Copy link
Member Author

xabbuh commented Feb 27, 2017

What we could do is creating the object before calling the parent method. This should trigger the registration of our ClockMock and DnsMock (see https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php#L70 and https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php#L75). The other calls of register() happen during execution of the listener inside startTestSuite() and startTest() anyway. We will then just decide later if we actually need to register the listener. That should work, shouldn't it?

If the listener is already configured through the PHPUnit config, there
is no need to also enable it explicitly in the test runner.
@xabbuh xabbuh force-pushed the test-listener-registration-2.8 branch from 5a27b3c to cee435f Compare February 27, 2017 20:00
@xabbuh
Copy link
Member Author

xabbuh commented Feb 27, 2017

So, the listener will now still be built before calling the parent method. However, it will only be actually registered if that did not happen through the PHPUnit config.

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.

👍

@fabpot
Copy link
Member

fabpot commented Feb 27, 2017

Thank you @xabbuh.

@fabpot fabpot merged commit cee435f into symfony:2.8 Feb 27, 2017
fabpot added a commit that referenced this pull request Feb 27, 2017
…abbuh)

This PR was merged into the 2.8 branch.

Discussion
----------

[PhpUnitBridge] do not register the test listener twice

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

If the listener is already configured through the PHPUnit config, there
is no need to also enable it explicitly in the test runner.

Commits
-------

cee435f do not register the test listener twice
@xabbuh xabbuh deleted the test-listener-registration-2.8 branch February 27, 2017 20:39

return parent::handleConfiguration($arguments);
if (!array_filter($arguments['listeners'], function ($listener) { return $listener instanceof SymfonyTestsListener; })) {
Copy link
Member

Choose a reason for hiding this comment

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

no need to filter the whole array. We should stop as soon as we find a SymfonyTestsListener even if it is the first one.

Copy link
Member

Choose a reason for hiding this comment

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

you're right - yet this is a non issue in practice, isn't it? this array is usually almost empty

This was referenced Mar 6, 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