10up / wp_mock

WordPress API Mocking Framework
https://wp-mock.gitbook.io
Other
676 stars 70 forks source link

Update return type for mockPost() #226

Closed wvega-godaddy closed 1 year ago

wvega-godaddy commented 1 year ago

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 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.

Contributor checklist

Reviewer checklist

- [ ] Code changes review - [ ] Documentation changes review - [ ] Unit tests pass - [ ] Static analysis passes
coveralls commented 1 year ago

Coverage Status

coverage: 65.646%. remained the same when pulling 56918850dd2fb3e59e41ef0a8352830c2f67d6b1 on chore/update-returned-type-for-mock-post into db23b60a136162a5dc78a2f05068a3a56edb1ab7 on trunk.