phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

Add expectThrowable methods

Open alamirault opened this issue 4 years ago • 1 comments

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 ?

alamirault avatar Nov 21 '21 11:11 alamirault

I am sorry, but I do not see any value in this.

sebastianbergmann avatar Nov 21 '21 15:11 sebastianbergmann