phpunit
phpunit copied to clipboard
Add expectThrowable methods
Hello,
Throwable interface was introduce in PHP 7.0 as base interface for any object that can be thrown.
Currently phpunit has only expectException* methods but they can work with Throwable (except expectExceptionObject).
/**
* @psalm-param class-string<\Throwable> $exception
*/
public function expectException(string $exception): void;
public function expectExceptionCode(int|string $code): void;
public function expectExceptionMessage(string $message): void;
public function expectExceptionMessageMatches(string $regularExpression): void;
public function expectExceptionObject(\Exception $exception): void;
I think we can add new methods expectThrowable, expectThrowableCode, expectThrowableMessage, expectThrowableMessageMatches, expectThrowableObject. So we can use them for Errors and Exceptions (not implicitly) and be closest of language.
It would be great if we can deprecate expectException* in future but I know it could be difficult.
What do think about adding these methods ?
I am sorry, but I do not see any value in this.