Skip to content
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

Fix TestRunner compatibility to PhpUnit 8 #30085

Conversation

alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented Feb 5, 2019

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets related to: #30055
License MIT
Doc PR -

Modify the installed phpunit version to be compatibility with the symfony custom TestRunner. This is sure not the best way but maybe currently the fastest way to support PhpUnit 8. The hack should be removed as soon as there is another way to implement a custom Runner.

@alexander-schranz alexander-schranz force-pushed the feature/phpunit-8-runner-compatibility branch 5 times, most recently from 3e4a969 to 0e36059 Compare February 6, 2019 00:15
@alexander-schranz alexander-schranz changed the title Fix PhpUnit 8 runner compatibility Fix test runner compatibility to PhpUnit 8 Feb 6, 2019
@alexander-schranz alexander-schranz changed the title Fix test runner compatibility to PhpUnit 8 Fix TestRunner compatibility to PhpUnit 8 Feb 6, 2019
@alexander-schranz alexander-schranz force-pushed the feature/phpunit-8-runner-compatibility branch from 0e36059 to 353ba54 Compare February 6, 2019 00:32
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Feb 7, 2019
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.

Before merging, we should be sure there is really no alternatives - we should also report the issue to Sebastian so that he knows some extensibility point is now missing. Could you please have a look?

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit Outdated Show resolved Hide resolved
@kunicmarko20
Copy link

kunicmarko20 commented Feb 7, 2019

Isn't it a better solution to check phpunit version here:

if (false) {
class TestRunner
{
}
}

and then provide the class with or without final? (if it is even possible like that)

@nicolas-grekas
Copy link
Member

@kunicmarko20 could you please have a look if that would be possible? Can you find any other alternative?

@alexander-schranz
Copy link
Contributor Author

@nicolas-grekas is it maybe possible to remove the TestRunner and move this logic to the Test Command?

@fabpot
Copy link
Member

fabpot commented Apr 1, 2019

@nicolas-grekas @alexander-schranz How can we move forward here?

@alexander-schranz
Copy link
Contributor Author

Will have a look at it, at the EU-FOSSA Hackathon.

@ostrolucky
Copy link
Contributor

Could this help? https://github.com/dg/bypass-finals

@alexander-schranz
Copy link
Contributor Author

@ostrolucky think we don't want to remove all finals.

Maybe there is some suggestion by @sebastianbergmann how we could automatically register the SymfonyListener programmatically now. Did create an issue at the phpunit repository sebastianbergmann/phpunit#3594

#EU-FOSSA

@sebastianbergmann
Copy link
Contributor

As I already wrote in sebastianbergmann/phpunit#3594 (comment) (why do we have to discuss the same issue in different places?), "automatically registereing" is not possible, and intentionally so: the test runner should not be extended through inheritance but by hooking into certain events. You can find the available hooks here.

What you should do is implement a class that implements one or more of these Hook interfaces. Then have PHPUnit load that class through its configuration file. PHPUnit will then register the hooks.

I can only advise against "hacking around" or "extending" the PHPUnit test runner and then, again and again, update your workarounds when internal implementation details of PHPUnit change. Please do not rely on private implementation details.

In #30085 (review) @nicolas-grekas wrote

we should also report the issue to Sebastian so that he knows some extensibility point is now missing

Yes, please: let me know if you are missing an extension point. While working on https://github.com/Roave/no-leaks @Ocramius ran into limitations of the current hooks provided and we plan to work on this in the future.

On a related note, the whole idea of phpunit-bridge is a mystery to me. I do not know what problem(s) you are trying to solve with it. It would be great if somebody could explain that at some point to me. It might be that there are solutions in there for problems that could be solved differently, either inside PHPUnit or in Symfony. I am not conviced that the best medium for this explanation would be a ticket or email. This should, ideally, be a real conversation. Maybe somebody from Symfony can come to a PHPUnit code sprint (there is one in Würzburg this month) or I can come to a Symfony code sprint.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 6, 2019

Meeting in person would be great for sure! I'm pretty busy this spring so not sure I can join the next sprint but let's tell each other if we see any opportunity!

The bridge creates an alternative "phpunit binary" that provides some extra features out of the box. With inheritance, it was possible to wire a different behavior by default, but now I'm not sure we can (I didn't have a deeper look). Which features? some extra annotations (@expectedDeprecation, @time-sensitive, etc) and some extra behaviors: the deprecations report that is displayed after running the tests, or a record/replay feature for skipped tests, maybe some more.

The extra features related to annotations work with a line in config files, but the extra behaviors are shipped out of the box when using the bridge.

That's why there is this specific bootstrapping extra layer, which is closed now, with final.

@alexander-schranz alexander-schranz force-pushed the feature/phpunit-8-runner-compatibility branch 2 times, most recently from 349ac1e to 343f4d4 Compare April 7, 2019 13:01
@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Apr 7, 2019

Analysed more the current state and I think I could fix it by moving the logic from the TestRunner to the Command.

#EUFOSSA

@nicolas-grekas
Copy link
Member

if it works, perfect :)
wasn't TestRunnerForV6 reference somewhere?

@xabbuh
Copy link
Member

xabbuh commented Apr 7, 2019

Can we also remove the src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php file?

@derrabus
Copy link
Member

derrabus commented Apr 7, 2019

@xabbuh It's still used in the CommandForV5, isn't it?

@alexander-schranz alexander-schranz force-pushed the feature/phpunit-8-runner-compatibility branch from 343f4d4 to 3bf78a0 Compare April 7, 2019 13:54
@alexander-schranz
Copy link
Contributor Author

@xabbuh done and move the v5 testrunner logic also to the commandforv5

return new TestRunnerForV5($this->arguments['loader']);
$listener = new SymfonyTestsListenerForV5();

$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : array();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas but here the long array syntax is correct or not?

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.

cool, thanks for digging!

@nicolas-grekas nicolas-grekas force-pushed the feature/phpunit-8-runner-compatibility branch from 3bf78a0 to a0c66a3 Compare April 8, 2019 07:56
@nicolas-grekas
Copy link
Member

Thank you @alexander-schranz.

@nicolas-grekas nicolas-grekas merged commit a0c66a3 into symfony:3.4 Apr 8, 2019
nicolas-grekas added a commit that referenced this pull request Apr 8, 2019
This PR was squashed before being merged into the 3.4 branch (closes #30085).

Discussion
----------

Fix TestRunner compatibility to PhpUnit 8

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | related to: #30055
| License       | MIT
| Doc PR        | -

Modify the installed phpunit version to be compatibility with the symfony custom TestRunner. This is sure not the best way but maybe currently the fastest way to support PhpUnit 8. The hack should be removed as soon as there is another way to implement a custom Runner.

Commits
-------

a0c66a3 Fix TestRunner compatibility to PhpUnit 8
@alexander-schranz alexander-schranz deleted the feature/phpunit-8-runner-compatibility branch April 8, 2019 10:29
This was referenced Apr 16, 2019
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.

None yet

10 participants