Skip to content

The PHPUnit\Framework\TestCase::prophesize method not polyfilled #62

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
aik099 opened this issue Oct 31, 2021 · 16 comments
Closed

The PHPUnit\Framework\TestCase::prophesize method not polyfilled #62

aik099 opened this issue Oct 31, 2021 · 16 comments

Comments

@aik099
Copy link

aik099 commented Oct 31, 2021

Since PHP 7.3 I'm seeing this warning:

PHPUnit\Framework\TestCase::prophesize() is deprecated and will be removed in PHPUnit 10. Please use the trait provided by phpspec/prophecy-phpunit.

I can't just require phpspec/prophecy-phpunit in the composer.json and use the trait it provides, because package itself won't even connect in PHP 7.2 and smaller versions.

@jrfnl
Copy link
Collaborator

jrfnl commented Oct 31, 2021

@aik099 Thanks for opening an issue about this.

Unfortunately, I don't see a straight forward way to solve this from within the PHPUnit Polyfills library as the same Composer restrictions apply.

As far as I know, Composer does not have an option to conditionally install a package based on the PHP version, so the PHPUnit Polyfills library can't (conditionally) require it either.

The only thing I can currently think of - and this is quite hacky - is to have a conditional composer require --dev for phpspec/prophecy-phpunit as part of a post-install-cmd/post-update-cmd script, but as scripts are only executed for the "root" project, this is still not something which could be handled by the PHPUnit Polyfills.

The only thing the Polyfills could do is provide a trait which would either load the trait provided by phpspec/prophecy-phpunit or call the PHPUnit\Framework\TestCase::prophesize() method depending on the availability of either, but that would still require that the "root" project would add the post-install-cmd/post-update-cmd to require the phpspec/prophecy-phpunit package depending on the PHP version detected, so it wouldn't work out of the box.

The only other thing I can think of, would be for the phpspec/prophecy-phpunit library to widen the requirements and add the "fall-through to PHPUnit" trait for PHP < 7.2 there....

Ideas/suggestions/PRs for solutions welcome....

@Seldaek @sebastianbergmann Would you happen to have any bright ideas on this subject ?

@aik099
Copy link
Author

aik099 commented Nov 1, 2021

@stof, any way to make https://github.com/phpspec/prophecy-phpunit work on other PHP versions?

@jrfnl
Copy link
Collaborator

jrfnl commented Nov 1, 2021

The only other thing I can think of, would be for the phpspec/prophecy-phpunit library to widen the requirements and add the "fall-through to PHPUnit" trait for PHP < 7.2 there....

@stof FYI and if it helps, we did something similar to what I propose above for the rdohms/phpunit-arraysubset-asserts package, where the real functionality in the repo is used in combination with the supported PHP and PHPUnit versions, but where the package is still allowed to be installed in combination with older PHP/PHPUnit versions, in which case it falls through to the PHPUnit native functionality as included in the older PHPUnit versions.

For reference:
rdohms/phpunit-arraysubset-asserts#11
rdohms/phpunit-arraysubset-asserts#48

If you think a similar solution would be acceptable for phpspec/prophecy-phpunit, I'd be willing to help get that set up.

@Seldaek
Copy link

Seldaek commented Nov 1, 2021

Sorry i don't see a better way than what you suggested above.

@jrfnl
Copy link
Collaborator

jrfnl commented Nov 1, 2021

@Seldaek Thanks Jordi for giving this a look-over!

@stof
Copy link

stof commented Nov 2, 2021

@jrfnl @aik099 I would welcome a PR extending the supported PHPUnit versions, with a condition definition of the trait being either empty or the current one.

@jrfnl
Copy link
Collaborator

jrfnl commented Nov 4, 2021

FYI: I've prepared all the necessary changes. I can start pulling them once I get a response to phpspec/prophecy-phpunit#34

@aik099
Copy link
Author

aik099 commented Nov 9, 2021

@jrfnl , the phpspec/prophecy-phpunit#34 is merged now. You can send PR with autoloader now. Thank you.

@jrfnl
Copy link
Collaborator

jrfnl commented Nov 9, 2021

@aik I'm waiting for the follow-up PRs to be merged (step by step) - also see: phpspec/prophecy-phpunit#35 (comment)

@jrfnl
Copy link
Collaborator

jrfnl commented Nov 9, 2021

Alternatively, I could put those back in draft and pull them after the PR addressing this issue, but that's up to @stof. The currently open PRs are very minor small changes, so should be easy merges.

@stof
Copy link

stof commented Nov 9, 2021

The currently opened PRs are not at all a blocker for that change anyway (bumping the min prophecy version does not impact the definition of the trait at all for instance). So you should be able to create the PR.

@jrfnl
Copy link
Collaborator

jrfnl commented Nov 9, 2021

I'll do some rebasing tomorrow, as, as I said before, the PRs make changes in the same files, so will be creating conflicts when pulled at the same time. Guess I'll just keep recreating commits and rebasing :-/

@aik
Copy link

aik commented Nov 10, 2021

@aik I'm waiting for the follow-up PRs to be merged (step by step) - also see: phpspec/prophecy-phpunit#35 (comment)

do not wait, I am the wrong "aik" :) @aik099 probably is.

@jrfnl
Copy link
Collaborator

jrfnl commented Nov 10, 2021

@aik Apologies and thanks for letting me know ❤️

@jrfnl
Copy link
Collaborator

jrfnl commented Nov 10, 2021

@stof @aik099 FYI: the PR has now been pulled - see phpspec/prophecy-phpunit#38

@jrfnl
Copy link
Collaborator

jrfnl commented Aug 24, 2022

I'm going to close this issue as this is not something which I intend to solve in the polyfills (forward compatibility vs backward compatibility). The PR to https://github.com/phpspec/prophecy-phpunit is (still) open and if it would be merged, I'll happily link to it from the readme of this package, but other than that, there is nothing to be done here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants