| 
6 | 6 | use Mockery;  | 
7 | 7 | use Mockery\Adapter\Phpunit\MockeryTestCase;  | 
8 | 8 | use ReturnTypeWillChange;  | 
 | 9 | +use RuntimeException;  | 
9 | 10 | use Serializable;  | 
 | 11 | +use function pcntl_fork;  | 
 | 12 | +use function pcntl_waitpid;  | 
 | 13 | +use function pcntl_wexitstatus;  | 
10 | 14 | 
 
  | 
11 | 15 | /**  | 
12 | 16 |  * @requires PHP 8.1.0-dev  | 
@@ -82,6 +86,39 @@ public function it_can_mock_a_class_with_an_intersection_argument_type_hint()  | 
82 | 86 | 
 
  | 
83 | 87 |         $mock->foo($object);  | 
84 | 88 |     }  | 
 | 89 | + | 
 | 90 | +    /** @test */  | 
 | 91 | +    public function it_can_mock_a_class_with_a_never_returning_type_hint()  | 
 | 92 | +    {  | 
 | 93 | +        $mock = Mockery::mock(NeverReturningTypehintClass::class)->makePartial();  | 
 | 94 | + | 
 | 95 | +        $this->expectException(RuntimeException::class);  | 
 | 96 | +        $mock->throws();  | 
 | 97 | +    }  | 
 | 98 | + | 
 | 99 | +    /**  | 
 | 100 | +     * @requires extension pcntl  | 
 | 101 | +     * @test  | 
 | 102 | +     */  | 
 | 103 | +    public function it_can_mock_a_class_with_a_never_returning_type_hint_with_exit()  | 
 | 104 | +    {  | 
 | 105 | +        $mock = Mockery::mock(NeverReturningTypehintClass::class)->makePartial();  | 
 | 106 | + | 
 | 107 | +        $pid = pcntl_fork();  | 
 | 108 | + | 
 | 109 | +        if (-1 === $pid) {  | 
 | 110 | +            $this->markTestSkipped("Couldn't fork for exit test");  | 
 | 111 | + | 
 | 112 | +            return;  | 
 | 113 | +        } elseif ($pid) {  | 
 | 114 | +            pcntl_waitpid($pid, $status);  | 
 | 115 | +            $this->assertEquals(123, pcntl_wexitstatus($status));  | 
 | 116 | + | 
 | 117 | +            return;  | 
 | 118 | +        }  | 
 | 119 | + | 
 | 120 | +        $mock->exits();  | 
 | 121 | +    }  | 
85 | 122 | }  | 
86 | 123 | 
 
  | 
87 | 124 | interface LoggerInterface  | 
@@ -135,6 +172,18 @@ public function getTimestamp(): float  | 
135 | 172 |     }  | 
136 | 173 | }  | 
137 | 174 | 
 
  | 
 | 175 | +class NeverReturningTypehintClass  | 
 | 176 | +{  | 
 | 177 | +    public function throws(): never  | 
 | 178 | +    {  | 
 | 179 | +        throw new RuntimeException('Never!');  | 
 | 180 | +    }  | 
 | 181 | + | 
 | 182 | +    public function exits(): never  | 
 | 183 | +    {  | 
 | 184 | +        exit(123);  | 
 | 185 | +    }  | 
 | 186 | +}  | 
138 | 187 | class IntersectionTypeHelperClass  | 
139 | 188 | {  | 
140 | 189 | }  | 
 | 
0 commit comments