Skip to content

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

Closed as not planned

Description

@aik099

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.

Activity

  1. jrfnl commented on Oct 31, 2021

    @jrfnl
    Collaborator

    @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 ?

  2. aik099 commented on Nov 1, 2021

    @aik099
    Author

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

  3. jrfnl commented on Nov 1, 2021

    @jrfnl
    Collaborator

    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.

  4. Seldaek commented on Nov 1, 2021

    @Seldaek

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

  5. jrfnl commented on Nov 1, 2021

    @jrfnl
    Collaborator

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

  6. stof commented on Nov 2, 2021

    @stof

    @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.

  7. jrfnl commented on Nov 4, 2021

    @jrfnl
    Collaborator

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

  8. aik099 commented on Nov 9, 2021

    @aik099
    Author

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

  9. jrfnl commented on Nov 9, 2021

    @jrfnl
    Collaborator

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

  10. jrfnl commented on Nov 9, 2021

    @jrfnl
    Collaborator

    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.

  11. stof commented on Nov 9, 2021

    @stof

    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.

  12. jrfnl commented on Nov 9, 2021

    @jrfnl
    Collaborator

    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 :-/

  13. aik commented on Nov 10, 2021

    @aik

    @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.

  14. jrfnl commented on Nov 10, 2021

    @jrfnl
    Collaborator

    @aik Apologies and thanks for letting me know ❤️

  15. jrfnl commented on Nov 10, 2021

    @jrfnl
    Collaborator

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

  16. jrfnl commented on Aug 24, 2022

    @jrfnl
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions