reactphp-kernel/tests/SocketPairIpcTest.php

50 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Blax\ReactPhpKernel\Tests;
use Blax\ReactPhpKernel\Ipc\SocketPairIpc;
use PHPUnit\Framework\TestCase;
use React\EventLoop\StreamSelectLoop;
final class SocketPairIpcTest extends TestCase
{
protected function setUp(): void
{
if (! SocketPairIpc::isSupported()) {
$this->markTestSkipped('ext-sockets (socket_create_pair / socket_export_stream) not available');
}
}
public function test_reports_support_on_this_platform(): void
{
$this->assertTrue(SocketPairIpc::isSupported());
}
public function test_create_returns_an_unconfigured_instance(): void
{
$ipc = SocketPairIpc::create(new StreamSelectLoop);
$this->assertInstanceOf(SocketPairIpc::class, $ipc);
}
public function test_double_configuration_is_rejected(): void
{
$ipc = SocketPairIpc::create(new StreamSelectLoop);
$ipc->setupChild();
$this->expectException(\LogicException::class);
$ipc->setupChild();
}
public function test_send_from_a_non_child_is_rejected(): void
{
$ipc = SocketPairIpc::create(new StreamSelectLoop);
// Not configured as child -> sendToParent must refuse.
$this->expectException(\LogicException::class);
$ipc->sendToParent('nope');
}
}