v0.2.0 (1/N): public API surface — interfaces + BridgeOp enum
Establishes the contract layer the rest of v0.2.0 builds on. Pre-1.0
SemVer break: ModelPublisher::publishEntityChange() now takes BridgeOp
instead of a raw string.
Interfaces (Symfony idiom: same namespace as concrete, like HubInterface
next to Hub):
- PublisherInterface — publish(string, array, bool)
- ModelPublisherInterface — publishEntityChange(object, BridgeOp)
- CorrelationContextInterface — set/get/clear
App code should typehint these instead of the concretes so swappable
implementations (offline-buffer publisher, multi-hub fan-out, request-
stamp correlation) remain non-breaking. Concrete classes implement them
unchanged; autowire continues to inject the implementations transparently.
BridgeOp: PHP 8.1 string-backed enum with cases Upsert / Delete /
Replace / Event matching PLAN.md §4's envelope `op` wire format.
Internal call sites updated; tests use the cases directly.
Switched typehints:
- ModelPublisher ctor: PublisherInterface + CorrelationContextInterface
- DoctrineBridgeListener ctor: ModelPublisherInterface
- HealthController ctor: PublisherInterface (still emits `Publisher`
as bundle canary value — `::class` resolves to the concrete class
name regardless of typehint, so bundled-supervisor.sh's grep stays
green)
- skeleton PingController ctor: PublisherInterface (canonical app
pattern — example/todo has no Publisher consumer to update)
Drive-by: removed deprecated setAccessible(true) call in
ModelPublisher::extractId — PHP 8.1+ allows reflection without it.
PHPStan + cs-fixer + PHPUnit (17/17) + maker snapshot all pass; dev
container compiles in the example app.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace PhpQml\Bridge\Tests;
|
||||
|
||||
use PhpQml\Bridge\Attribute\BridgeResource;
|
||||
use PhpQml\Bridge\BridgeOp;
|
||||
use PhpQml\Bridge\CorrelationContext;
|
||||
use PhpQml\Bridge\ModelPublisher;
|
||||
use PhpQml\Bridge\Publisher;
|
||||
@@ -71,7 +72,7 @@ final class ModelPublisherTest extends TestCase
|
||||
{
|
||||
$todo = new FakeTodo(id: '019de596-be1c-7642-985c-edcadeef9b5d', title: 'milk', done: false);
|
||||
|
||||
$this->publisher->publishEntityChange($todo, 'upsert');
|
||||
$this->publisher->publishEntityChange($todo, BridgeOp::Upsert);
|
||||
|
||||
// The HubSpy only retains the LAST update. To validate both topics,
|
||||
// re-publish and check the second envelope, but for the assertion of
|
||||
@@ -98,7 +99,7 @@ final class ModelPublisherTest extends TestCase
|
||||
$this->context->set('idem-1234');
|
||||
$this->publisher->publishEntityChange(
|
||||
new FakeTodo(id: '1', title: 'x'),
|
||||
'upsert',
|
||||
BridgeOp::Upsert,
|
||||
);
|
||||
|
||||
$envelope = json_decode($this->hub->captured->getData(), true);
|
||||
@@ -109,7 +110,7 @@ final class ModelPublisherTest extends TestCase
|
||||
{
|
||||
$this->publisher->publishEntityChange(
|
||||
new FakeTodo(id: '7', title: 'gone'),
|
||||
'delete',
|
||||
BridgeOp::Delete,
|
||||
);
|
||||
|
||||
$envelope = json_decode($this->hub->captured->getData(), true);
|
||||
@@ -119,17 +120,17 @@ final class ModelPublisherTest extends TestCase
|
||||
|
||||
public function testEntitiesWithoutBridgeResourceAreIgnored(): void
|
||||
{
|
||||
$this->publisher->publishEntityChange(new FakeNotMarked(1, 'x'), 'upsert');
|
||||
$this->publisher->publishEntityChange(new FakeNotMarked(1, 'x'), BridgeOp::Upsert);
|
||||
|
||||
self::assertNull($this->hub->captured);
|
||||
}
|
||||
|
||||
public function testVersionIncreasesOnEachPublish(): void
|
||||
{
|
||||
$this->publisher->publishEntityChange(new FakeTodo(id: '1', title: 'a'), 'upsert');
|
||||
$this->publisher->publishEntityChange(new FakeTodo(id: '1', title: 'a'), BridgeOp::Upsert);
|
||||
$first = json_decode($this->hub->captured->getData(), true)['version'];
|
||||
|
||||
$this->publisher->publishEntityChange(new FakeTodo(id: '1', title: 'b'), 'upsert');
|
||||
$this->publisher->publishEntityChange(new FakeTodo(id: '1', title: 'b'), BridgeOp::Upsert);
|
||||
$second = json_decode($this->hub->captured->getData(), true)['version'];
|
||||
|
||||
self::assertGreaterThan($first, $second);
|
||||
|
||||
Reference in New Issue
Block a user