Skip to content

[WIP][PHPUnitBridge] Cross compatibility between PHPUnit 5 and 6 #21158

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 11 commits into from

Conversation

Jean85
Copy link
Contributor

@Jean85 Jean85 commented Jan 4, 2017

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21125
License MIT

Still WIP... I have doubt on how to solve (preserving BC) the case where the target class that I want to replace is a public method's argument typehint, like in SymfonyTestsListener::addSkippedTest:

public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)

@Jean85
Copy link
Contributor Author

Jean85 commented Jan 4, 2017

Status: needs work


namespace Symfony\Bridge\PhpUnit\Compat\Framework;

if (class_exists(PHPUnit\Framework\BaseTestListener::class)) {
Copy link
Member

Choose a reason for hiding this comment

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

this is a no-go. the bridge must stay compatible with PHP 5.3 to be usable in the Symfony LTS CI setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Already fixed, the Travis build reported this.

@@ -103,6 +103,7 @@
"psr-4": {
"Symfony\\Bridge\\Doctrine\\": "src/Symfony/Bridge/Doctrine/",
"Symfony\\Bridge\\Monolog\\": "src/Symfony/Bridge/Monolog/",
"Symfony\\Bridge\\PhpUnit\\Compat\\": "src/Symfony/Bridge/PhpUnit/Compat/",
Copy link
Member

Choose a reason for hiding this comment

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

-1 for this. The PHPUnit bridge is not meant to be autoloaded from the main Symfony repo

Copy link
Contributor Author

@Jean85 Jean85 Jan 4, 2017

Choose a reason for hiding this comment

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

I'm not autoloading the whole bridge but just the Compat classes, otherwise this will not work. Do you have any suggestions for an alternate approach?

[EDIT] I've done this here since the normal autoload was failing during the SecurityBundle tests in the build. Maybe it's just a build issue?

Copy link
Member

Choose a reason for hiding this comment

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

These classes must be autoloaded by the bridge only. Anything else is wrong.

A failure may be related to cases mixing a downloaded version of the bridge and your patched version here. But I have not seen the failure you are talking about. The only build failures on Travis on the commit before this one are about broken signatures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, we have to load that just in the bridge. I've reverted that but the build is failing: https://travis-ci.org/Jean85/symfony/jobs/188845916#L1983

Copy link
Member

Choose a reason for hiding this comment

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

but ths has nothing to do with SecurityBundle. It is a failure when testing the bridge itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you're right. In fact, the PR build is green, great! https://travis-ci.org/symfony/symfony/builds/188846004


namespace Symfony\Bridge\PhpUnit\Compat\Framework;

if (class_exists(PHPUnit\Framework\BaseTestListener::class)) {
Copy link
Member

Choose a reason for hiding this comment

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

and if it was kept, there is a missing \ here, meaning you check for Symfony\Bridge\PhpUnit\Compat\Framework\PHPUnit\Framework\BaseTestListener

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Already fixed, the Travis build reported this too.

class Blacklist extends \PHPUnit\Util\Blacklist
{}
} else {
class Blacklist extends \PHPUnit_Util_Blacklist
Copy link
Member

Choose a reason for hiding this comment

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

there is no reason to create this class. We need compat classes only when extending them. Otherwise, we can do the class_exists check around the usage of the class, which is much more readable

@@ -119,7 +128,7 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
} elseif (2 === $this->state) {
$skipped = array();
foreach ($suite->tests() as $test) {
if (!$test instanceof \PHPUnit_Framework_TestCase
if (!$this->isInstanceOfPHPUnitTestSuite($test)
Copy link
Member

Choose a reason for hiding this comment

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

method name is weird, as the check was for TestCase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Thanks, fixing it

namespace Symfony\Bridge\PhpUnit\Compat\Framework;

if (class_exists(PHPUnit\Framework\BaseTestListener::class)) {
abstract class BaseTestListener extends \PHPUnit\Framework\BaseTestListener
Copy link
Member

Choose a reason for hiding this comment

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

this class (and all other classes here) must be tagged as @internal so that there are not covered by BC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! Doing it RN

@Jean85
Copy link
Contributor Author

Jean85 commented Jan 4, 2017

Ok, the build is green, but still I don't know how to proceed for the class in typehints...
I've suggested an approach here: #21125 (comment)

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Jan 6, 2017
@Jean85
Copy link
Contributor Author

Jean85 commented Jan 9, 2017

Closing in favor of #21221

@Jean85 Jean85 closed this Jan 9, 2017
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 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.

4 participants