2026-05-02 01:08:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace PhpQml\Bridge\Tests\Command;
|
|
|
|
|
|
|
|
|
|
use PhpQml\Bridge\Command\BridgeDoctorCommand;
|
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
|
|
|
|
|
|
#[CoversClass(BridgeDoctorCommand::class)]
|
|
|
|
|
final class BridgeDoctorCommandTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
public function testAllPassesWhenEnvIsFullyConfigured(): void
|
|
|
|
|
{
|
|
|
|
|
$command = new BridgeDoctorCommand(
|
2026-05-02 02:15:06 +02:00
|
|
|
bridgeToken: 'devtoken',
|
|
|
|
|
mercureUrl: 'http://127.0.0.1:8765/.well-known/mercure',
|
|
|
|
|
mercurePublisherKey: 'devkey',
|
|
|
|
|
mercureSubscriberKey: 'devkey',
|
2026-05-02 01:08:09 +02:00
|
|
|
);
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
|
|
|
|
|
$exit = $tester->execute([]);
|
|
|
|
|
|
|
|
|
|
self::assertSame(0, $exit);
|
|
|
|
|
$display = $tester->getDisplay();
|
|
|
|
|
self::assertStringContainsString('All checks passed', $display);
|
|
|
|
|
self::assertStringNotContainsString('FAIL', $display);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFailsAndShowsHintsWhenEnvIsMissing(): void
|
|
|
|
|
{
|
|
|
|
|
$command = new BridgeDoctorCommand(
|
2026-05-02 02:15:06 +02:00
|
|
|
bridgeToken: '',
|
|
|
|
|
mercureUrl: '',
|
|
|
|
|
mercurePublisherKey: '',
|
|
|
|
|
mercureSubscriberKey: '',
|
2026-05-02 01:08:09 +02:00
|
|
|
);
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
|
|
|
|
|
$exit = $tester->execute([]);
|
|
|
|
|
|
|
|
|
|
self::assertSame(1, $exit);
|
|
|
|
|
$display = $tester->getDisplay();
|
|
|
|
|
self::assertStringContainsString('BRIDGE_TOKEN env set', $display);
|
|
|
|
|
self::assertStringContainsString('MERCURE_URL env set', $display);
|
|
|
|
|
self::assertStringContainsString('Set BRIDGE_TOKEN in .env.local', $display);
|
|
|
|
|
self::assertStringContainsString('Some checks failed', $display);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConnectOptionFailsClosedAgainstAnUnreachableUrl(): void
|
|
|
|
|
{
|
|
|
|
|
$command = new BridgeDoctorCommand(
|
2026-05-02 02:15:06 +02:00
|
|
|
bridgeToken: 'devtoken',
|
|
|
|
|
mercureUrl: 'http://127.0.0.1:8765/.well-known/mercure',
|
|
|
|
|
mercurePublisherKey: 'devkey',
|
|
|
|
|
mercureSubscriberKey: 'devkey',
|
2026-05-02 01:08:09 +02:00
|
|
|
);
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
|
|
|
|
|
// Port 1 is reserved and refuses connections — the probe must fail.
|
|
|
|
|
$exit = $tester->execute(['--connect' => true, '--url' => 'http://127.0.0.1:1/healthz']);
|
|
|
|
|
|
|
|
|
|
self::assertSame(1, $exit);
|
|
|
|
|
self::assertStringContainsString('Backend probe failed', $tester->getDisplay());
|
|
|
|
|
}
|
|
|
|
|
}
|