From 705f675adbd15f4a68dbec4805eb57ca16b7e86a Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Tue, 7 Jun 2022 20:22:51 -0400 Subject: [PATCH] Test never-returning function/method that throws an exception Signed-off-by: Nathanael Esayeas --- tests/PHP81/Php81LanguageFeaturesTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/PHP81/Php81LanguageFeaturesTest.php b/tests/PHP81/Php81LanguageFeaturesTest.php index 26af5885f..52b9933ab 100644 --- a/tests/PHP81/Php81LanguageFeaturesTest.php +++ b/tests/PHP81/Php81LanguageFeaturesTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\Adapter\Phpunit\MockeryTestCase; use ReturnTypeWillChange; +use RuntimeException; use Serializable; /** @@ -82,6 +83,15 @@ public function it_can_mock_a_class_with_an_intersection_argument_type_hint() $mock->foo($object); } + + /** @test */ + public function it_can_mock_a_class_with_a_never_returning_type_hint() + { + $mock = Mockery::mock(NeverReturningTypehintClass::class)->makePartial(); + + $this->expectException(RuntimeException::class); + $mock->throws(); + } } interface LoggerInterface @@ -135,6 +145,18 @@ public function getTimestamp(): float } } +class NeverReturningTypehintClass +{ + public function throws(): never + { + throw new RuntimeException('Never!'); + } + + public function exits(): never + { + exit; + } +} class IntersectionTypeHelperClass { }