Repository navigation
Fix sealed test double unions and MockBuilder::getTestDouble() return type - #377
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two of the three problems reported in #375.
@phpstan-sealed MockObject|StubInternalis turned into an intersectionMockObjectTypeNodeResolverExtensionno longer converts unions in PHPDocs whose namespace is underPHPUnit\\,PHPStan\\, orSebastianBergmann\\. The conversion is meant forFoo|MockObjectin users' code. In PHPUnit itself, a union of test double interfaces such as the sealing ofStubis meant as a union.Every method of
MockBuilderexceptgetMock*()is assumed to return the builderMockBuilderDynamicReturnTypeExtensionnow 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 declaredMockObject|Stubreturn type.The
MockBuilderstub problem is not addressed here.Tested with PHPUnit 9.6 and 12.5.