reactphp-kernel/tests/ChildReaperTest.php

48 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Blax\ReactPhpKernel\Tests;
use Blax\ReactPhpKernel\Process\ChildReaper;
use PHPUnit\Framework\TestCase;
use React\EventLoop\StreamSelectLoop;
final class ChildReaperTest extends TestCase
{
public function test_reap_all_returns_zero_when_there_are_no_children(): void
{
if (! function_exists('pcntl_waitpid')) {
$this->markTestSkipped('ext-pcntl not available');
}
$reaper = new ChildReaper(new StreamSelectLoop);
$this->assertSame(0, $reaper->reapAll());
}
public function test_install_and_uninstall_do_not_throw(): void
{
$loop = new StreamSelectLoop;
$reaper = new ChildReaper($loop);
$reaper->install(0.1);
$reaper->uninstall();
// Reaching here without an exception is the assertion.
$this->assertTrue(true);
}
public function test_reap_all_is_safe_to_call_repeatedly(): void
{
if (! function_exists('pcntl_waitpid')) {
$this->markTestSkipped('ext-pcntl not available');
}
$reaper = new ChildReaper(new StreamSelectLoop);
$this->assertSame(0, $reaper->reapAll());
$this->assertSame(0, $reaper->reapAll());
}
}