-
Notifications
You must be signed in to change notification settings - Fork 242
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
Add PHP 8.1 support #533
Add PHP 8.1 support #533
Conversation
Thanks @javer for working on this. I've been testing this PR using Drupal's tests and it works great. Deprecation messages that were incorrectly triggered when mocking a class that implements \Iterator are no longer triggered. Nice one. 👍 |
There's one issue that's come up from testing on Drupal. If you have a interface that extends \Traversable then on PHP 8.1 creating a double will trigger deprecation notices. If you add ->willImplement(\IteratorAggregator::class) then the deprecation notices go away. I think this is because \Traversable needs the object to implement either \IteratorAggregator or \Iterator - so it's a bit of an odd one. |
composer.json
Outdated
@@ -18,15 +18,15 @@ | |||
], | |||
|
|||
"require": { | |||
"php": "^7.2 || ~8.0, <8.1", | |||
"php": "^7.2 || ^8.0", |
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 we didn't do this. It can be ~8.0, <8.2
once we've had a chance to test
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.
Changed to ^7.2 || ~8.0, <8.2
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.
Is there a reason why 8.2 is not supported? 🤔
@@ -113,8 +113,8 @@ function it_accepts_any_key_token_type_to_score_object_that_is_both_traversable_ | |||
return 'value'; | |||
}); | |||
$object->key()->willReturn('key'); | |||
$object->rewind()->willReturn(null); | |||
$object->next()->willReturn(null); | |||
(\PHP_VERSION_ID < 80100) ? $object->rewind()->willReturn(null) : $object->rewind()->shouldBeCalled(); |
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.
Can you explain what's causing this change from a stub to a mock?
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.
Since PHP 8.1 many internal classes have got correct return types: https://wiki.php.net/rfc/internal_method_return_types
Now ArrayIterator::rewind()
has return type void
: https://github.com/php/php-src/blob/master/ext/spl/spl_array.stub.php#L201
That's why it cannot return null
, and tests fail: https://github.com/javer/prophecy/runs/3215333259?check_suite_focus=true#step:6:27
Prophecy/Argument/Token/ArrayEntryToken
104 - it accepts any key token type to score object that is both traversable and array accessible
the method "rewind" has a void return type, and so cannot return anything
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.
shouldBeCalled()
will make things break if the iterator is never used. I think we need something like canBeCalled()
instead
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 we didn't tag a version as working with 8.1 when there isn't yet an RC (and therefore more changes could occur).
Many of the other changes look ok, although I'm concerned in some places the tests have been changed rather than the implementation
@ciaranmcnulty Feature freeze for PHP 8.1 was done on Jul 20 2021, so no changes in the language specs are expected since that moment. Many changes in the tests related to the fact that they are checking implementation of the internal PHP classes which have been changed significantly in PHP 8.1, see:
So since PHP 8.1 many such tests became incorrect, because behavior of the tested methods was changed inside PHP. I suggest not to wait for RC, because this library is special in the sense that 99% PHP packages indirectly depend on it, because all of them use In other words, missing support for PHP 8.1 in this library blocks almost all packages even to test whether they support PHP 8.1 or not, because all of them at least need to put this hack to CI flow https://github.com/php-amqplib/php-amqplib/pull/929/files#diff-ea12f60188cdd90bc99e5d0af2eb91647bbe4a9199176aa1ec5240f65efed510R79 and then they see many failed tests just because of incompatibility of this library with PHP 8.1, but not because of their failures. |
@alexpott Please check whether doubling |
|
@javer sorry I was wrong - cause of general awkwardness testing a PR with composer I missed the changes to src/Prophecy/Doubler/ClassPatch/TraversablePatch.php - your recent changes work great. Thanks! |
Added spec for testing new (and old) behavior of |
@@ -29,6 +34,10 @@ jobs: | |||
php-version: "${{ matrix.php }}" | |||
coverage: none | |||
|
|||
- name: Configure for PHP 8.1 | |||
run: composer config platform.php 8.0.99 |
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 think the point of this PR is that we don't need this step. It should work without this. Or is there any dependency not compatible with 8.1?
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.
When other libraries depend on this one - yes, you are right. But this library itself has dev-dependency on phpspec/phpspec
, which requires php: ^7.3 || 8.0.*
.
Lines 28 to 31 in be1996e
"require-dev": { | |
"phpspec/phpspec": "^6.0", | |
"phpunit/phpunit": "^8.0 || ^9.0" | |
}, |
There is some kind of circular dependency phpspec -> prophecy -> phpspec
, so one of these libraries should be fixed first, and because prophecy
is runtime dependency for phpspec
- it should be prophecy
. After merging this PR and tagging the release we will be able to test phpspec
and fix it to support PHP 8.1, release a new version and only after this specified above lines can be removed.
# composer install
Problem 1
- phpspec/phpspec 6.0.0 requires php ^7.2, <7.4 -> your php version (8.1.0beta1) does not satisfy that requirement.
- phpspec/phpspec[6.1.0, ..., 6.2.2] require php ^7.2, <7.5 -> your php version (8.1.0beta1) does not satisfy that requirement.
- phpspec/phpspec[6.3.0, ..., 6.3.1] require php ^7.2 || 8.0.* -> your php version (8.1.0beta1) does not satisfy that requirement.
- phpspec/phpspec[7.0.0, ..., 7.1.0] require php ^7.3 || 8.0.* -> your php version (8.1.0beta1) does not satisfy that requirement.
- Root composer.json requires phpspec/phpspec ^6.0 || ^7.0 -> satisfiable by phpspec/phpspec[6.0.0, ..., 6.3.1, 7.0.0, 7.0.1, 7.1.0].
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.
Ok, cross-ref: phpspec/phpspec#1387
I really don't want to tag a release of Prophecy that says it supports 8.1 before we've tested against a release candidate. If it's screwing up PHPUnit then I could maybe be persuaded (cc @sebastianbergmann) Is there a reason libraries wanting to test can't use composer's |
PHPUnit 8.5 and PHPUnit 9.5 still depend on Prophecy. This leads to
and
respectively. PHPUnit 10, which is still in development, no longer depends on Prophecy. |
@sebastianbergmann I'm happy to do whatever makes your life easier, but is there a reason |
I think having to use In other words: are you planning to support PHP 8.1 in Prophecy and if so, when? |
With all respect. The number of changes in this PR shows clearly to me that |
PHPUnit depends on Prophecy to provide the protected function prophesize($classOrInterface = null): ObjectProphecy
{
if (is_string($classOrInterface)) {
$this->recordDoubledType($classOrInterface);
}
return $this->getProphet()->prophesize($classOrInterface);
} And in the if ($this->prophet !== null) {
try {
$this->prophet->checkPredictions();
} finally {
foreach ($this->prophet->getProphecies() as $objectProphecy) {
foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) {
foreach ($methodProphecies as $methodProphecy) {
assert($methodProphecy instanceof MethodProphecy);
$this->numAssertions += count($methodProphecy->getCheckedPredictions());
}
}
}
}
} Many years ago, I thought that it would be a good idea to 1) have PHPUnit depend on Prophecy to make the latter always available when PHPUnit is availabe and 2) provide a convenient integration of Prophecy with PHPUnit. This was deprecated in PHPUnit 9.1 and has been removed for PHPUnit 10. |
You can merge this into a dev branch instead of master then. That way the whole downstream deps chain isn't blocked from upgrading/trying out their code with PHP 8.1. |
I've added some issues for things we'll need to check on PHP 8.1 https://github.com/phpspec/prophecy/issues?q=is%3Aopen+is%3Aissue+label%3APHP8.1 Any extra issues people can think of, please raise them |
If someone can depend on a dev branch instead, they can use the |
I'm happy to start testing against it and would aim to tag a release around the RC stage |
PHPUnit 8.5 and PHPUnit 9.5 are supported on PHP 8.1 and depend on Prophecy. I am not sure what you mean by "are you planning to support PHP 8.1 in Prophecy", though. |
@sebastianbergmann Sorry that was meant to be quoting your question from upthread and then answering it |
Thanks, I'm going to merge this so dev-master is 'compatible', but won't tag a release until the outstanding issues are closed off |
|
Thanks for the work @javer |
It's demoralising to have so many on here emphasising how important it is for Prophecy to support 8.1, but no work has been done on any of the 8.1 issues in the month since, nor has anyone reviewed or commented on #538 It'll all eventually get done, of course, but at the moment it's bottlenecked on my time and availability |
Fixes #531