The return type must be a WP_Post and a mockery mock at the same time. I believe that the method needs to use an intersection type instead of an union one.
Details
Unfortunately, WP_Post cannot be used in an intersection type, because the class is declared as final (related discussions in PHPStan's repo). The current version of mockPost() was always returning Mockery\LegacyMockInterface so I think it still makes sense to update the return type.
I also updated the return type of mockWp() to return an intersection of WP and Mockery mock interfaces. Since WP is not final, we can use the intersection type directly.
coverage: 65.646%. remained the same when pulling 56918850dd2fb3e59e41ef0a8352830c2f67d6b1 on chore/update-returned-type-for-mock-post into db23b60a136162a5dc78a2f05068a3a56edb1ab7 on trunk.
Summary
The return type must be a
WP_Post
and a mockery mock at the same time. I believe that the method needs to use an intersection type instead of an union one.Details
Unfortunately,
WP_Post
cannot be used in an intersection type, because the class is declared as final (related discussions in PHPStan's repo). The current version ofmockPost()
was always returningMockery\LegacyMockInterface
so I think it still makes sense to update the return type.I also updated the return type of
mockWp()
to return an intersection ofWP
and Mockery mock interfaces. SinceWP
is not final, we can use the intersection type directly.Contributor checklist
Reviewer checklist
- [ ] Code changes review - [ ] Documentation changes review - [ ] Unit tests pass - [ ] Static analysis passes