Cache for generated Test Double code was not updated for Test Stub and Mock Object distinction #5534
Labels
feature/test-doubles
Test Stubs and Mock Objects
type/bug
Something is broken
version/10
Something affects PHPUnit 10
Summary
In PHPUnit 10.4.0 I occassionally get a TestStub class returned instead of a MockObject class as before.
Current behavior
How to reproduce
The chaining above fails if in some other test for one of the return objects a TestStub is created. The chained method will then return a TestStub for that class instead of a MockObject, which is not compatible with the method return type and crashes with a type error.
I don't quite understand why, where and how a TestStub is created, but I found the problem where the mix up happens. The problem is because there's a TestStub / MockObject cache, but the generated cache key doesn't differentiate between TestStub and MockObject. See:
Class:
PHPUnit\Framework\MockObject\Generator\Generator
Method:
generate
Code:
My temp fix that seems to work. Add the $mockObject status into the cache key:
The text was updated successfully, but these errors were encountered: