Skip to content

Commit

Permalink
Test never-returning function/method that terminates
Browse files Browse the repository at this point in the history
Co-Authored-By: Dave Marshall <dave@atstsolutions.co.uk>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter and davedevelopment committed Jun 8, 2022
1 parent 705f675 commit ec2443a
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/PHP81/Php81LanguageFeaturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use ReturnTypeWillChange;
use RuntimeException;
use Serializable;
use function pcntl_fork;
use function pcntl_waitpid;
use function pcntl_wexitstatus;

/**
* @requires PHP 8.1.0-dev
Expand Down Expand Up @@ -92,6 +95,30 @@ public function it_can_mock_a_class_with_a_never_returning_type_hint()
$this->expectException(RuntimeException::class);
$mock->throws();
}

/**
* @requires extension pcntl
* @test
*/
public function it_can_mock_a_class_with_a_never_returning_type_hint_with_exit()
{
$mock = Mockery::mock(NeverReturningTypehintClass::class)->makePartial();

$pid = pcntl_fork();

if (-1 === $pid) {
$this->markTestSkipped("Couldn't fork for exit test");

return;
} elseif ($pid) {
pcntl_waitpid($pid, $status);
$this->assertEquals(123, pcntl_wexitstatus($status));

return;
}

$mock->exits();
}
}

interface LoggerInterface
Expand Down Expand Up @@ -154,7 +181,7 @@ public function throws(): never

public function exits(): never
{
exit;
exit(123);
}
}
class IntersectionTypeHelperClass
Expand Down

0 comments on commit ec2443a

Please sign in to comment.