-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using willReturnOnConsecutiveCalls()
together with throwException()
#5469
Comments
willReturnOnConsecutiveCalls()
together with throwException()
Please note that the functionality in question is currently "only" soft-deprecated. Your tests continue to work in exactly the same way as before and no deprecation is displayed by PHPUnit. This is also the reason why the deprecation is not mentioned in the ChangeLog. The actual deprecation for the functionality in question is tracked in #5423 and #5425. Thank you for bringing this to my attention, I was not aware that this works: <?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
interface I
{
public function m(): bool;
}
final class Test extends TestCase
{
public function testOne(): void
{
$i = $this->createStub(I::class);
$i->method('m')
->willReturnOnConsecutiveCalls(
false,
true,
$this->throwException(new Exception('message'))
);
$this->assertFalse($i->m());
$this->assertTrue($i->m());
$this->expectException(Exception::class);
$this->assertTrue($i->m());
}
} In the example shown above, the test stub
As of right now, I have no alternative to suggest to achieve the same result once #5424 and #5426 are implemented. I will need to investigate this further. |
No, you're right about that. It's our PHPStan configuration that warns about calling deprecated methods. Thanks for the information. I will ignore the PHPStan message for now and will keep an eye out for future changes! |
The soft-deprecation of |
Summary
PHPUnit 10.3 deprecated
willReturnOnConsecutiveCalls
andthrowException
methods. I am unsure how to convert this piece of code:I can replace
willReturnOnConsecutiveCalls
withwillReturn
, but how can I declare that it should throw an exception the first time, and true the second time?The text was updated successfully, but these errors were encountered: