reactphp-kernel/tests/Fixtures/RecordingServer.php

44 lines
946 B
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Blax\ReactPhpKernel\Tests\Fixtures;
use Blax\ReactPhpKernel\Contracts\Server;
use React\EventLoop\LoopInterface;
/**
* A test-double protocol server that records whether it was booted / shut down
* and lets a test hook onto the boot moment (e.g. to schedule the kernel stop).
*/
final class RecordingServer implements Server
{
public bool $booted = false;
public bool $wasShutDown = false;
/** @var callable|null function(LoopInterface): void */
public $onBoot = null;
public function __construct(private string $id = 'recording') {}
public function name(): string
{
return $this->id;
}
public function boot(LoopInterface $loop): void
{
$this->booted = true;
if ($this->onBoot !== null) {
($this->onBoot)($loop);
}
}
public function shutdown(): void
{
$this->wasShutDown = true;
}
}