Skip to content

Commit e970d8c

Browse files
authored
Merge pull request #66 from reactphp-parallel/3.x-add-type-testing
[3.x] Add type testing
2 parents 6e438eb + d15d1aa commit e970d8c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

etc/qa/phpstan.neon

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
parameters:
22
level: max
3+
ignoreErrors:
4+
-
5+
message: '#Result of method ReactParallel\\Runtime\\Runtime::run\(\) \(void\) is used.#'
6+
path: ../../tests/Types.php
37
ergebnis:
48
noExtends:
59
classesAllowedToBeExtended:

src/Runtime.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public function __construct(private EventLoopBridge $eventLoopBridge, string $au
2626
}
2727

2828
/**
29-
* @param (Closure():?T) $callable
29+
* @param (Closure():T)|(Closure():void) $callable
3030
* @param array<int, mixed> $args
3131
*
32-
* @return ?T
32+
* @return ($callable is (Closure():T) ? T : null)
3333
*
3434
* @template T
3535
*/

tests/Types.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use ReactParallel\Runtime\Runtime;
6+
use ReactParallel\EventLoop\EventLoopBridge;
7+
8+
use function PHPStan\Testing\assertType;
9+
10+
$pool = Runtime::create(new EventLoopBridge());
11+
12+
assertType('bool', $pool->run(static function (): bool {
13+
return true;
14+
}));
15+
16+
assertType('bool|int', $pool->run(static function (): bool|int {
17+
return time() % 2 !== 0 ? true : time();
18+
}));
19+
20+
assertType('null', $pool->run(static function () {
21+
}));

0 commit comments

Comments
 (0)