Brain-WP/BrainMonkey

A never-returning function must not return in ...

michaelw85 opened this issue ยท 10 comments

Hi,

I'm using PHP 8.1 with:

  • phpunit/phpunit 10.1.0
  • brain/monkey 2.6.1
  • pestphp/pest v2.5.0

When I write a simple test mocking WP's get_option all tests stop working. error code 255
when('get_option')->justReturn(...)

This results in a Fatal error:
PHP Fatal error: A never-returning function must not return in /Users/..../vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php on line 91
When I change the typing from never to void what it used to be in PHPUnit 10.0.0 it works again.

I'm guessing there is a mismatch when the function is mocked but I haven't found the root cause yet.

Same issue when downgrading phpunit and using expect in a test

Functions\expect('update_option')->once()->with('opt', 'value')->andReturn(true)

After more debugging I think this might be an issue caused by PEST but I'm still not sure. The source code in PEST seems fine to me.
Pest source code with never typing
When changing this line to void it works just fine.

I've created a PR for PEST: pestphp/pest#786

Hi @michaelw85 I don't think this is an issue with Brain Monkey, this is a PHP 5.6 codebase, and we don't use return types at all.

Maybe you could also look at Mockery, but I don't think there's anything we can do here to solve the issue.

Feel free to re-open if I'm wrong.

@gmazzap I think you are right, I haven't looked at Mockery or Patchwork yet. I think for some reason somewhere something is emitted in the mocked functions causing the never typing to fatal.

This does mean the latest PHPUnit version + Brain Monkey is an issue unless you apply the patch I've provided.

jrfnl commented

This does mean the latest PHPUnit version + Brain Monkey is an issue unless you apply the patch I've provided.

You mean PHPUnit 10 ? I know that Mockery definitely does not support PHPUnit 10 yet. Also see the open PRs in the repo, in particular this one: mockery/mockery#1219

I'm not sure Patchwork would be problematic with PHPUnit 10 as it is a stand-alone tool which works independently of PHPUnit.

You might be jumping the gun a bit here.

Yep, before using BM with PHPUnit 10 we need Mockery to be compatible.

This does mean the latest PHPUnit version + Brain Monkey is an issue unless you apply the patch I've provided.

You mean PHPUnit 10 ? I know that Mockery definitely does not support PHPUnit 10 yet. Also see the open PRs in the repo, in particular this one: mockery/mockery#1219

I'm not sure Patchwork would be problematic with PHPUnit 10 as it is a stand-alone tool which works independently of PHPUnit.

You might be jumping the gun a bit here.

Yes, I'm running PHPUnit 10.1.1 which comes with the new Pest v2.
The issue you linked also mentions the never typing so without further investigation I'm going to assume Mockery is the issue. In my project, I just patched all never typings to void and it works fine so far.

Hey folks,

Mockery supports never return type for PHP 8.1 via mockery/mockery#1184 & tagged 1.5.1

Updating Brain-WP/BrainMonkey composer to ^1.3.5 || ^1.4.4 || ^1.5.1 should resolve this.

Have a great day. โœŒ๐Ÿพ

jrfnl commented

Thanks for pitching in @ghostwriter !

@jrfnl I'm starting to think this might be a Pest related issue. If you are interested here's a repo with more details https://github.com/michaelw85/never-issue#readme

Updating Brain-WP/BrainMonkey composer to ^1.3.5 || ^1.4.4 || ^1.5.1 should resolve this.

Is there anything blocking this? If it's just a matter of available time to handle the upgrade, I might have some time to pitch in and open a pull request.

Updating Brain-WP/BrainMonkey composer to ^1.3.5 || ^1.4.4 || ^1.5.1 should resolve this.

Is there anything blocking this? If it's just a matter of available time to handle the upgrade, I might have some time to pitch in and open a pull request.

For me the root cause still remains unresolved and to date I still don't know the exact origin of the issue. I dirty resolved it by locally patching all the return types. The issues were closed in the different repos because "blame" was given to another library or deemed a local issue in my codebase :(