36 lines
1.0 KiB
PHP
36 lines
1.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Blax\ReactPhpKernel\Tests;
|
||
|
|
|
||
|
|
use Blax\ReactPhpKernel\Server\SocketServerFactory;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
use React\EventLoop\StreamSelectLoop;
|
||
|
|
use React\Socket\SocketServer;
|
||
|
|
|
||
|
|
final class SocketServerFactoryTest extends TestCase
|
||
|
|
{
|
||
|
|
public function test_creates_a_plain_tcp_listener(): void
|
||
|
|
{
|
||
|
|
$server = SocketServerFactory::create('127.0.0.1:0', new StreamSelectLoop);
|
||
|
|
|
||
|
|
$this->assertInstanceOf(SocketServer::class, $server);
|
||
|
|
$this->assertStringStartsWith('tcp://127.0.0.1:', (string) $server->getAddress());
|
||
|
|
|
||
|
|
$server->close();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_binds_an_ephemeral_port_that_can_be_read_back(): void
|
||
|
|
{
|
||
|
|
$server = SocketServerFactory::create('127.0.0.1:0', new StreamSelectLoop);
|
||
|
|
|
||
|
|
$address = (string) $server->getAddress();
|
||
|
|
$port = (int) parse_url($address, PHP_URL_PORT);
|
||
|
|
|
||
|
|
$this->assertGreaterThan(0, $port, 'an ephemeral port should have been assigned');
|
||
|
|
|
||
|
|
$server->close();
|
||
|
|
}
|
||
|
|
}
|