Skip to content

Do not generate a return statement in the constructor of a test double#6800

Closed
lazerg wants to merge 1 commit into
sebastianbergmann:12.5from
lazerg:issue-6797
Closed

Do not generate a return statement in the constructor of a test double#6800
lazerg wants to merge 1 commit into
sebastianbergmann:12.5from
lazerg:issue-6797

Conversation

@lazerg

@lazerg lazerg commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

When an interface (or class) that declares a __construct() method is doubled, the generated constructor ends with return $__phpunit_result;. A constructor cannot declare a return type, so ReflectionMapper resolves it to UnknownType (neither void nor never) and DoubledMethod::generateCode() emits the return statement. On PHP 8.6 this triggers the Returning a value from a constructor is deprecated deprecation.

This suppresses the return statement when the generated method is a constructor. The existing generator test for #4139 (which doubles an interface declaring a constructor) is updated to the corrected output; it fails before this change and passes after.

Closes #6797

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.00%. Comparing base (7c4ce79) to head (4c4dc4c).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               12.5    #6800   +/-   ##
=========================================
  Coverage     96.00%   96.00%           
- Complexity     7568     7569    +1     
=========================================
  Files           798      798           
  Lines         23180    23180           
=========================================
  Hits          22253    22253           
  Misses          927      927           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@sebastianbergmann

Copy link
Copy Markdown
Owner

Thank you for your contribution and for taking the time to prepare this pull request. I appreciate the effort.

However, I've decided not to merge it as-is, since this issue needs to be addressed across the 8.5, 9.6, 10.5, 11.5, 12.5, 13.2, and main branches. I'll take care of this myself next week, in one pass; starting with a fix for the oldest supported branch and then merging/adapting it forward through the newer branches.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants