Skip to content

Commit

Permalink
Merge pull request #66 from reactphp-parallel/3.x-add-type-testing
Browse files Browse the repository at this point in the history
[3.x] Add type testing
  • Loading branch information
WyriHaximus authored Dec 26, 2024
2 parents 6e438eb + d15d1aa commit e970d8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions etc/qa/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
parameters:
level: max
ignoreErrors:
-
message: '#Result of method ReactParallel\\Runtime\\Runtime::run\(\) \(void\) is used.#'
path: ../../tests/Types.php
ergebnis:
noExtends:
classesAllowedToBeExtended:
Expand Down
4 changes: 2 additions & 2 deletions src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public function __construct(private EventLoopBridge $eventLoopBridge, string $au
}

/**
* @param (Closure():?T) $callable
* @param (Closure():T)|(Closure():void) $callable
* @param array<int, mixed> $args
*
* @return ?T
* @return ($callable is (Closure():T) ? T : null)
*
* @template T
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/Types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use ReactParallel\Runtime\Runtime;
use ReactParallel\EventLoop\EventLoopBridge;

use function PHPStan\Testing\assertType;

$pool = Runtime::create(new EventLoopBridge());

assertType('bool', $pool->run(static function (): bool {
return true;
}));

assertType('bool|int', $pool->run(static function (): bool|int {
return time() % 2 !== 0 ? true : time();
}));

assertType('null', $pool->run(static function () {
}));

0 comments on commit e970d8c

Please sign in to comment.