Add a method to create callable mock
In some case, it can be useful to mock a callable. So far, no method exists to provide it, but the following workaround is possible :
$mock = $this->createPartialMock(\stdClass::class, ['__invoke']);
$mock
->expects(self::once())
->method('__invoke')
->with(1, 2)
->willReturn(3);
The mock of method that do not actually exists in original class is deprecated in version 8 and will no longer be supported for version >= 9.
The previous workaround can be replaced by the following one :
$mock = $this->getMockBuilder(\stdClass::class)
->addMethods(['__invoke'])
->getMock();
$mock
->expects(self::once())
->method('__invoke')
->with(1, 2)
->willReturn(3);
This PR add a 'createCallableMock' method to provide the expected mock. If the PR is accepted, it would be possible to replace previous workaround by :
$mock = $this->createCallableMock();
$mock
->expects(self::once())
->method('__invoke')
->with(1, 2)
->willReturn(3);
Codecov Report
Merging #3908 into master will increase coverage by
<.01%. The diff coverage is100%.
@@ Coverage Diff @@
## master #3908 +/- ##
============================================
+ Coverage 83.67% 83.68% +<.01%
- Complexity 3855 3856 +1
============================================
Files 151 151
Lines 10199 10203 +4
============================================
+ Hits 8534 8538 +4
Misses 1665 1665
| Impacted Files | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| src/Framework/TestCase.php | 80.9% <100%> (+0.08%) |
339 <1> (+1) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 69ac974...b097a7b. Read the comment docs.
Thank you for your contribution. I appreciate the time you invested in preparing this pull request. However, I have decided not to merge it.