Skip to content

Fix sealed test double unions and MockBuilder::getTestDouble() return type - #377

Merged
ondrejmirtes merged 2 commits into
2.1.xfrom
fix-375
Dec 3, 2026
Merged

ondrejmirtes merged 2 commits into
2.1.xfrom
fix-375

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Fixes two of the three problems reported in #375.

@phpstan-sealed MockObject|StubInternal is turned into an intersection

MockObjectTypeNodeResolverExtension no longer converts unions in PHPDocs whose namespace is under PHPUnit\\, PHPStan\\, or SebastianBergmann\\. The conversion is meant for Foo|MockObject in users' code. In PHPUnit itself, a union of test double interfaces such as the sealing of Stub is meant as a union.

Every method of MockBuilder except getMock*() is assumed to return the builder

MockBuilderDynamicReturnTypeExtension now only handles methods whose declared return type is the builder (self, static, or $this), instead of every method except a list of names. getTestDouble(), which PHPUnit 12.5.1+ inherits, keeps its declared MockObject|Stub return type.

The MockBuilder stub problem is not addressed here.

Tested with PHPUnit 9.6 and 12.5.

…ergmann namespaces

A union such as @phpstan-sealed MockObject|StubInternal on PHPUnit's Stub
interface is meant as a union, not as Foo|MockObject.

Refs #375

Amp-Thread-ID: https://ampcode.com/threads/T-01a23bbc-5704-74d2-8eb6-4ad62c97a4b6
…e builder

Since PHPUnit 12.5.1, MockBuilder inherits getTestDouble(), which returns
MockObject|Stub. It was inferred to return the builder because every method
except getMock*() was assumed to. Methods that return the builder declare
self, static, or $this, so check the declared return type instead of
listing method names.

Refs #375

Amp-Thread-ID: https://ampcode.com/threads/T-01a23bbc-5704-74d2-8eb6-4ad62c97a4b6
@ondrejmirtes
ondrejmirtes merged commit 23501e3 into 2.1.x Dec 3, 2026
110 of 113 checks passed
@ondrejmirtes
ondrejmirtes deleted the fix-375 branch December 3, 2026 11:58
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.

1 participant