Phase 1 sub-commit 7: CI quality job
Some checks failed
CI / Quality (push) Has been cancelled

PHPStan (level 6 + symfony extension) and PHP CS Fixer (Symfony +
PHP83Migration ruleset) configs at framework/php/. composer.json
exposes phpstan / cs:check / cs:fix / phpunit / quality scripts.
PHPStan-clean across the bundle; cs:check is happy after auto-fix
applied @Symfony idioms (yoda, leading-backslash JSON_*, blank-line
before return). Test mocks consolidated into a HubSpy helper to keep
PHPStan happy about by-ref captures.

Skeleton's Makefile target `quality` chains `composer quality` (in
framework/php/) with cmake's all_qmllint target. Local run is green —
11 tests / 32 assertions, no PHPStan errors, cs-fixer clean, qmllint
emits advisory warnings only.

Layout fix in skeleton's Main.qml: status-dot Rectangles inside
RowLayout now use Layout.preferredWidth/Height instead of width/height
to satisfy Quick.layout-positioning checks.

.gitea/workflows/ci.yml replaces the placeholder with a real `quality`
job: setup-php, composer install (cached), the four PHP checks, Qt 6
via install-qt-action (cached), QML module build, qmllint via the
all_qmllint CMake target. Workflow exists from this commit onward
even if a runner isn't provisioned yet.

bridge:doctor lost the Publisher dependency since it was only used as
a "service is wired" marker — the command being injectable already
proves that.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-02 02:15:06 +02:00
parent d671b26cac
commit 7323b9affe
14 changed files with 198 additions and 108 deletions

View File

@@ -5,12 +5,9 @@ declare(strict_types=1);
namespace PhpQml\Bridge\Tests\Command;
use PhpQml\Bridge\Command\BridgeDoctorCommand;
use PhpQml\Bridge\Publisher;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
#[CoversClass(BridgeDoctorCommand::class)]
final class BridgeDoctorCommandTest extends TestCase
@@ -18,11 +15,10 @@ final class BridgeDoctorCommandTest extends TestCase
public function testAllPassesWhenEnvIsFullyConfigured(): void
{
$command = new BridgeDoctorCommand(
publisher: $this->makePublisher(),
bridgeToken: 'devtoken',
mercureUrl: 'http://127.0.0.1:8765/.well-known/mercure',
mercurePublisherKey: 'devkey',
mercureSubscriberKey: 'devkey',
bridgeToken: 'devtoken',
mercureUrl: 'http://127.0.0.1:8765/.well-known/mercure',
mercurePublisherKey: 'devkey',
mercureSubscriberKey: 'devkey',
);
$tester = new CommandTester($command);
@@ -37,11 +33,10 @@ final class BridgeDoctorCommandTest extends TestCase
public function testFailsAndShowsHintsWhenEnvIsMissing(): void
{
$command = new BridgeDoctorCommand(
publisher: $this->makePublisher(),
bridgeToken: '',
mercureUrl: '',
mercurePublisherKey: '',
mercureSubscriberKey: '',
bridgeToken: '',
mercureUrl: '',
mercurePublisherKey: '',
mercureSubscriberKey: '',
);
$tester = new CommandTester($command);
@@ -58,11 +53,10 @@ final class BridgeDoctorCommandTest extends TestCase
public function testConnectOptionFailsClosedAgainstAnUnreachableUrl(): void
{
$command = new BridgeDoctorCommand(
publisher: $this->makePublisher(),
bridgeToken: 'devtoken',
mercureUrl: 'http://127.0.0.1:8765/.well-known/mercure',
mercurePublisherKey: 'devkey',
mercureSubscriberKey: 'devkey',
bridgeToken: 'devtoken',
mercureUrl: 'http://127.0.0.1:8765/.well-known/mercure',
mercurePublisherKey: 'devkey',
mercureSubscriberKey: 'devkey',
);
$tester = new CommandTester($command);
@@ -72,17 +66,4 @@ final class BridgeDoctorCommandTest extends TestCase
self::assertSame(1, $exit);
self::assertStringContainsString('Backend probe failed', $tester->getDisplay());
}
private function makePublisher(): Publisher
{
return new Publisher(new class implements HubInterface {
public function getUrl(): string { return ''; }
public function getPublicUrl(): string { return ''; }
public function getProvider(): \Symfony\Component\Mercure\Jwt\TokenProviderInterface
{ throw new \LogicException(); }
public function getFactory(): ?\Symfony\Component\Mercure\Jwt\TokenFactoryInterface
{ return null; }
public function publish(Update $update): string { return ''; }
});
}
}

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace PhpQml\Bridge\Tests\Helper;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Jwt\TokenFactoryInterface;
use Symfony\Component\Mercure\Jwt\TokenProviderInterface;
use Symfony\Component\Mercure\Update;
/**
* Minimal HubInterface fake that records the last published Update.
* Used by Publisher / BridgeDoctorCommand tests.
*/
final class HubSpy implements HubInterface
{
public ?Update $captured = null;
public function __construct(private readonly string $stubReturnId = '')
{
}
public function getUrl(): string
{
return 'http://localhost/.well-known/mercure';
}
public function getPublicUrl(): string
{
return $this->getUrl();
}
public function getProvider(): TokenProviderInterface
{
throw new \LogicException('HubSpy::getProvider not used in tests.');
}
public function getFactory(): ?TokenFactoryInterface
{
return null;
}
public function publish(Update $update): string
{
$this->captured = $update;
return $this->stubReturnId;
}
}

View File

@@ -5,9 +5,9 @@ declare(strict_types=1);
namespace PhpQml\Bridge\Tests;
use PhpQml\Bridge\Publisher;
use PhpQml\Bridge\Tests\Helper\HubSpy;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
#[CoversClass(Publisher::class)]
@@ -15,58 +15,30 @@ final class PublisherTest extends TestCase
{
public function testPublishWritesEnvelopeAsJsonOnTheGivenTopic(): void
{
$captured = null;
$hub = new class($captured) implements HubInterface {
public function __construct(private mixed &$captured) {}
public function getUrl(): string { return 'http://localhost/.well-known/mercure'; }
public function getPublicUrl(): string { return $this->getUrl(); }
public function getProvider(): \Symfony\Component\Mercure\Jwt\TokenProviderInterface
{
throw new \LogicException('not used in test');
}
public function getFactory(): ?\Symfony\Component\Mercure\Jwt\TokenFactoryInterface
{
return null;
}
public function publish(Update $update): string
{
$this->captured = $update;
return 'urn:uuid:test';
}
};
$hub = new HubSpy('urn:uuid:test');
$publisher = new Publisher($hub);
$id = $publisher->publish('app://model/todo', ['op' => 'upsert', 'id' => '1', 'data' => ['done' => true], 'version' => 7]);
$id = $publisher->publish(
'app://model/todo',
['op' => 'upsert', 'id' => '1', 'data' => ['done' => true], 'version' => 7],
);
self::assertSame('urn:uuid:test', $id);
self::assertInstanceOf(Update::class, $captured);
self::assertSame(['app://model/todo'], $captured->getTopics());
self::assertInstanceOf(Update::class, $hub->captured);
self::assertSame(['app://model/todo'], $hub->captured->getTopics());
self::assertJsonStringEqualsJsonString(
'{"op":"upsert","id":"1","data":{"done":true},"version":7}',
$captured->getData(),
$hub->captured->getData(),
);
self::assertFalse($captured->isPrivate());
self::assertFalse($hub->captured->isPrivate());
}
public function testPrivateFlagIsForwarded(): void
{
$captured = null;
$hub = new class($captured) implements HubInterface {
public function __construct(private mixed &$captured) {}
public function getUrl(): string { return ''; }
public function getPublicUrl(): string { return ''; }
public function getProvider(): \Symfony\Component\Mercure\Jwt\TokenProviderInterface { throw new \LogicException(); }
public function getFactory(): ?\Symfony\Component\Mercure\Jwt\TokenFactoryInterface { return null; }
public function publish(Update $update): string { $this->captured = $update; return ''; }
};
$hub = new HubSpy();
(new Publisher($hub))->publish('app://event/internal', ['data' => 'x'], private: true);
self::assertTrue($captured->isPrivate());
self::assertNotNull($hub->captured);
self::assertTrue($hub->captured->isPrivate());
}
}

View File

@@ -28,7 +28,7 @@ final class SessionAuthenticatorTest extends TestCase
public function testAuthenticateAcceptsMatchingBearerToken(): void
{
$auth = new SessionAuthenticator('s3cret');
$auth = new SessionAuthenticator('s3cret');
$request = new Request();
$request->headers->set('Authorization', 'Bearer s3cret');
@@ -40,7 +40,7 @@ final class SessionAuthenticatorTest extends TestCase
public function testAuthenticateRejectsMissingBearerScheme(): void
{
$auth = new SessionAuthenticator('s3cret');
$auth = new SessionAuthenticator('s3cret');
$request = new Request();
$request->headers->set('Authorization', 'Basic deadbeef');
@@ -51,7 +51,7 @@ final class SessionAuthenticatorTest extends TestCase
public function testAuthenticateRejectsWrongToken(): void
{
$auth = new SessionAuthenticator('s3cret');
$auth = new SessionAuthenticator('s3cret');
$request = new Request();
$request->headers->set('Authorization', 'Bearer wrong');
@@ -63,7 +63,7 @@ final class SessionAuthenticatorTest extends TestCase
public function testAuthenticateRejectsEmptyExpectedToken(): void
{
// Avoids passing a misconfigured (empty) deployment.
$auth = new SessionAuthenticator('');
$auth = new SessionAuthenticator('');
$request = new Request();
$request->headers->set('Authorization', 'Bearer ');
@@ -73,10 +73,9 @@ final class SessionAuthenticatorTest extends TestCase
public function testAuthenticationFailureProducesProblemJson(): void
{
$auth = new SessionAuthenticator('s3cret');
$auth = new SessionAuthenticator('s3cret');
$response = $auth->onAuthenticationFailure(new Request(), new AuthenticationException('Bearer token invalid.'));
self::assertNotNull($response);
self::assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
self::assertSame('application/problem+json', $response->headers->get('Content-Type'));
$body = json_decode((string) $response->getContent(), true);