-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PhpUnitBridge] Add type hints #26994
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
Conversation
2403702
to
74f4773
Compare
When trying to run simple-phpunit, I now get autoloading issues that I also get with phpunit 6:
Not quite sure why this happens but I think I might have fixed the bug :P |
Other, bigger issue: "The PHPUnit\Framework\BaseTestListener class has been removed (deprecated in PHPUnit 6.4)" |
Ah nevermind that has been handled already it seems. |
@juliendufresne @geoff-maddock can you please test this patch on whatever project you were having this issue, and review this PR? |
I did exactly what you did before posting the issue and ran with another more complex issue. I'll try again to get the right output. |
EDIT: this is the output of one call meaning that I have two times the same error. EDIT2: ok I'm guessing it's not getting the right phpunit project because this one is located in |
Looks like you have phpunit installed on your project: |
Here is the commit that introduces this method: sebastianbergmann/phpunit@41c7584 |
Just saw this at the same time :) |
Yeah that's why we should stop using phpstan as a vendor like this :P |
Argh, as you said it's |
Removing the dependency that introduced phpunit works. Using phpstan standalone (outside of the project) is another debate :) |
Ah nevermind, it's totally doable: https://hub.docker.com/r/phpstan/phpstan/ |
It's so sick I've not found that it uses the wrong phpunit earlier because I could have done the exact same PR months ago ^^ |
I still don't understand why it loaded the class It should use its own autoloading located in What I found so far is that if I force the autoloading from the $reflector = new ReflectionClass('PHPUnit\TextUI\TestRunner'); It works. (you need to put this code in the simple-phunit file on line 123 so it will regenerate the phpunit file.) |
I figured it out. That's why we can not have both phpunit-bridge and phpunit as a dependency in the project. |
Actually, the bridge should still be compatible with PHP 5.3, so we might have to use the same approach as we have for SymfonyTestsListener.php... |
Ah right, I didn't check the right composer.json, and assumed the constraints would be the same symfony/src/Symfony/Bridge/PhpUnit/composer.json Lines 19 to 21 in 833909b
|
@@ -26,7 +27,7 @@ class Command extends BaseCommand | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
protected function createRunner() | |||
protected function createRunner(): BaseRunner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas wait, aren't we already guaranteed to have php 7.0 here? We are inside a conditional block where phpunit is version 6 or above, ergo php itself must be 7 or above, correct? Or does the class_exists('PHPUnit_Runner_Version')
condition part have other implications?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP 5.3 will still raise a parse error...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah but 5.3 needs to be able to parse this I think.
31adcfb
to
855c112
Compare
@@ -11,45 +11,14 @@ | |||
|
|||
namespace Symfony\Bridge\PhpUnit\TextUI; | |||
|
|||
use PHPUnit\TextUI\TestRunner as BaseRunner; | |||
use Symfony\Bridge\PhpUnit\SymfonyTestsListener; | |||
|
|||
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { | |||
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunner', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we rename this one TestRunnerForV5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe yeah, @nicolas-grekas please advise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's rename to ForV4 yes
if (!$registeredLocally) { | ||
$arguments['listeners'][] = $listener; | ||
} | ||
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV6', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have create a TestRunnerForV7 as well.
The TestRunnerForV6 should be the same as the previous defined class (i.e without return typehint) and the TestRunnerForV7 with the return typehint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have fewer files since adding the type hints even if they are not required is possible, but maybe the naming could be improved *ForV6AndAbove
, *ForV5AndBelow
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the Symfony standards regarding naming. I'll let others answer :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the suffix: let use the lowest number
@@ -0,0 +1,59 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to define this class? It is already defined in the Symfony\Bridge\PhpUnit
namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, didn't mean to do this, I copied too many files from my sandbox directory.
* @internal | ||
*/ | ||
class Command extends BaseCommand | ||
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV6', 'Symfony\Bridge\PhpUnit\TextUI\Command'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have create CommandForV7 as well
855c112
to
3206bdb
Compare
Why is it for 4.0 and not 2.7? |
The bug was reported for 4.0, let's see if it applies to lower versions. |
The 2.7 code looks a lot different: there is no I can make a separate PR just for this method signature:
|
The |
3206bdb
to
3db0323
Compare
Apparently, support for phpunit 7 is a feature and was therefore added on 3.4 |
The Appveyor and Travis build failures seem unrelated. |
The adopted naming convention is to use the lowest supported version for naming. Since we are not 100% sure about phpunit 4 support, we use V5, and if it works for phpunit 4, that's great but we don't really care. |
This makes classes inheriting from phpunit classes compatible with phpunit 7. Fixes symfony#26931
182e4b8
to
6fbcc51
Compare
Thank you @greg0ire. |
This PR was merged into the 3.4 branch. Discussion ---------- [PhpUnitBridge] Add type hints | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no (only changed classes marked as internal) | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26931 | License | MIT | Doc PR | n/a This makes classes inheriting from phpunit classes compatible with phpunit 7. Commits ------- 6fbcc51 Add type hints
* 3.4: (22 commits) [appveyor] use PHP 7.1 to run composer [HttpKernel] Don't clean legacy containers that are still loaded [VarDumper] Fix HtmlDumper classes match Make the simple auth provider the same as in Symfony 2.7. [PhpUnitBridge] silence wget fix merge [Security] guardAuthenticationProvider::authenticate cannot return null according to interface specification [PhpUnitBridge] Fix #26994 [VarDumper] Remove decoration from actual output in tests [PropertyInfo] Minor cleanup and perf improvement [Bridge/Doctrine] fix count() notice on PHP 7.2 [Security] Skip user checks if not implementing UserInterface [DI] Add check of internal type to ContainerBuilder::getReflectionClass [HttpFoundation] Add HTTP_EARLY_HINTS const [DoctrineBridge] Improve exception message at `IdReader::getIdValue()` Add type hints fixed CS Use new PHP7.2 functions in hasColorSupport [VarDumper] Fix dumping of SplObjectStorage [HttpFoundation] Add functional tests for Response::sendHeaders() ...
* 4.0: (22 commits) [appveyor] use PHP 7.1 to run composer [HttpKernel] Don't clean legacy containers that are still loaded [VarDumper] Fix HtmlDumper classes match Make the simple auth provider the same as in Symfony 2.7. [PhpUnitBridge] silence wget fix merge [Security] guardAuthenticationProvider::authenticate cannot return null according to interface specification [PhpUnitBridge] Fix #26994 [VarDumper] Remove decoration from actual output in tests [PropertyInfo] Minor cleanup and perf improvement [Bridge/Doctrine] fix count() notice on PHP 7.2 [Security] Skip user checks if not implementing UserInterface [DI] Add check of internal type to ContainerBuilder::getReflectionClass [HttpFoundation] Add HTTP_EARLY_HINTS const [DoctrineBridge] Improve exception message at `IdReader::getIdValue()` Add type hints fixed CS Use new PHP7.2 functions in hasColorSupport [VarDumper] Fix dumping of SplObjectStorage [HttpFoundation] Add functional tests for Response::sendHeaders() ...
This makes classes inheriting from phpunit classes compatible with phpunit 7.