-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Test Failures with PHP 8 #3526
Comments
Travis-CI has php 8.0 runtime (for
|
PHPUnit is not yet supported on PHP 8. |
If you use |
i will not remove btw, travis have pre-installed phpunit 8.0.2 on their php 8.0 image. |
I believe travis now has 8.0.2 pre-installed for their php 7.2 image as well (it was 7.5.1 a few days ago) |
I suggest to use |
Notes dump: The main problem appears to be changes to how is_callable behaves:phpunit/src/Framework/TestCase.php Lines 1780 to 1784 in aed4efc
In PHP 8, is_callable(class::method, ...) can only work on static methods, something like: diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php
index 54e9866a3..62d661e77 100644
--- a/src/Framework/TestCase.php
+++ b/src/Framework/TestCase.php
@@ -1775,9 +1775,21 @@ private function handleDependencies(): bool
if (\strpos($dependency, '::') === false) {
$dependency = $className . '::' . $dependency;
}
-
+
+ if (!preg_match('~([^:]+)::(.*)~', $dependency, $parts)) {
+ /* error */
+ }
+
+ /*
+ if ($parts[1] != get_class(this)) {
+ you will need a reference to an object of type parts[1]
+ or to enforce the rule that you may not depend on a test in another
+ class/suite/whatever
+ }
+ */
+
if (!isset($passedKeys[$dependency])) {
- if (!\is_callable($dependency, false, $callableName) || $dependency !== $callableName) {
+ if (!\is_callable([$this, $parts[2]], false, $callableName) || $dependency !== $callableName) {
$this->markWarningForUncallableDependency($dependency);
} else {
$this->markSkippedForMissingDependecy($dependency); Get's it down to one failure ... method_exists may be faster there, because you know you are testing for the existence of a public method, and you know you're not checking for static callability (because it 's not allowed if the function wasn't declared static) ... just a thought ... While you're refactoring that function, I'd probably use a regex, maybe something like: <?php
$input = [
"clone class::method",
"!clone class::method",
"shallowClone class::method",
"!shallowClone class::method",
"function",
"clone function",
"!clone function",
"shallowClone function",
"!shallowClone function"
];
foreach ($input as $next) {
preg_match('~(?<negate>\!?)'.
'(?<type>clone|shallowClone)?\s?'.
'((?<class>[a-zA-Z0-9_]+)::)?'. /* this should probably be a better pattern */
'(?<function>([a-zA-Z0-9\_]+))~si', /* this should probably be a better pattern */
$next, $matches); /* no match is malformed */
var_dump([
"negate" => $matches['negate'] === '!',
"type" => $matches['type'],
"class" => $matches['class'],
"function" => $matches['function']
]);
} If I understood it properly ... That should get you somewhere ... |
After c557764 we are down to one failure:
|
Worked around #3559 by manually generating the - public function a(int $i = PHP_INT_MAX, int $j = Is\Namespaced\A_CONSTANT, string $v = PHP_VERSION, string $z = '#'): string
+ public function a(int $i = Is\Namespaced\PHP_INT_MAX, int $j = Is\Namespaced\A_CONSTANT, string $v = PHP_VERSION, string $z = '#'): string |
true in PHP 7.3.4 (and in PHP 7.4-dev) but false in PHP 8.0-dev.
|
Fixed by @nikic in php/php-src@e311f2a. |
So, how do we install PHPUnit on PHP 8? Looks like it still doesn't allow PHP 8. |
If we do that, then half of the benefit of using Composer is gone. I'm sure the people who want to build on PHP 8 still want Composer to report when things aren't compatible with PHP. |
You can use the code using the "--ignore-platform-reqs" parameter. I tested it and it worked perfectly! composer global require phpunit/phpunit --ignore-platform-reqs I hope it helps 👍 |
疑似關聯 issue: - sebastianbergmann/phpunit#3526 跑 php 8 的測試時,告訴 composer 無視平台版本限制。
疑似關聯 issue: - sebastianbergmann/phpunit#3526 跑 php 8 的測試時,告訴 composer 無視平台版本限制。 這個 commit 還不正常,會導致 phpunit 的相依套件裝錯版本 整包壞了了。
I get the following test failures with PHP 8.0.0-dev (
cb95175d6c9f36637818142989648ea74af4cf3d
):Now PHPUnit does not have to be compatible with PHP 8 just yet, but these failures could potentially reveal code mistakes that have no effect in PHP 7. I will investigate this, either I find something interesting in PHPUnit or in PHP 8.
The text was updated successfully, but these errors were encountered: