Skip to content

ReflectionType::__toString() is deprecated #45

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
spacedmonkey opened this issue Jul 9, 2021 · 6 comments
Closed

ReflectionType::__toString() is deprecated #45

spacedmonkey opened this issue Jul 9, 2021 · 6 comments

Comments

@spacedmonkey
Copy link

Running PHPUnit 6.5.14 in PHP 7.4, generate the following error when using createMock

Function ReflectionType::__toString() is deprecated

I wonder if this library could patch this issue.

PHPUnit issue sebastianbergmann/phpunit#3728

@spacedmonkey
Copy link
Author

For more context, here is the PR where I found the issue GoogleForCreators/web-stories-wp#8264

It seems to be an issue, with methods having return type hints + reflection.

@jrfnl
Copy link
Collaborator

jrfnl commented Jul 9, 2021

@spacedmonkey This is not an issue which this library will or should fix, as it is an issue caused by a wrong test setup configuration.

The whole point of the polyfills is that you can use the modern, PHPUnit 9.x assertions and expectations (and fix the void issue), but can still run your tests on the most appropriate (and supported) PHPUnit version for the PHP version on which you are running the tests.

In short: you should not be running PHPUnit 6.x on PHP 7.4. You should be using PHPUnit 8.x or 9.x, which are both supported for PHP 7.4. You could even use PHPUnit 7.x, which will (hopefully) also fix this, even though not officially supported on PHP 7.4.

image
Source: https://phpunit.de/supported-versions.html

Looking at the repo you linked to, there are two things I can see:

  1. You have a committed composer.lock file via which you are managing your dependencies, including your dev dependencies like PHPUnit.
  2. You are running tests in the context of WordPress, which limits the test running to PHPUnit 5.x - 7.x.

To fix this with that context in mind:

  • Either "lock" PHPUnit at PHPUnit 7.x and downgrade the PHPUnit version in your CI script for the test run against PHP 7.0.
  • Or keep the lock at PHPUnit 6.x and upgrade the PHPUnit version in your CI script for any test runs on PHP >= 7.4.

To limit the update to just PHPUnit (and its dependencies), you can use a pattern like so (for the second option listed above):

composer require --dev phpunit/phpunit:"^7.5" --update-with-dependencies --ignore-platform-reqs

You're basically now trying to fit a square block into a round hole.

@jrfnl
Copy link
Collaborator

jrfnl commented Jul 14, 2021

@spacedmonkey Just checking: did my answer clarify things enough for you ? Can this issue be closed ?

@jrfnl
Copy link
Collaborator

jrfnl commented Jul 28, 2021

Closing for lack of reply.

@jrfnl jrfnl closed this as completed Jul 28, 2021
@spacedmonkey
Copy link
Author

We worked around this issues, but patching PHPUnit 6.x to run in PHP 7.4. It makes everything a lot simpler, as means we can run PHP 6.x everywhere and it just works.

@jrfnl
Copy link
Collaborator

jrfnl commented Jul 28, 2021

I presume you mean PHPUnit 6.x ? PHP 6.x was never released.

Either way, glad you got it working, but I still think you are trying to fit a square block into a round hole and that's not what this package will help you do.

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

2 participants