public function testDeserializesMetadata() { $metadata = new Metadata(); $contract = Contract::createFromClassName('stdClass'); $this->serializer->expects($this->once())->method('deserialize')->with('{}', $contract)->willReturn($metadata); $this->assertSame($metadata, $this->eventSerializer->deserializeMetadata('{}', $contract)); }
public function testRetrieveAllEventsForAnAggregateRoot() { $aggregateRootType = Contract::createFromClassName('stdClass'); $aggregateRootIdentifier = new AggregateRootIdentifierStub(); $this->statement->method('fetchAll')->willReturn([]); $this->assertInstanceOf('RayRutjes\\DomainFoundation\\Domain\\Event\\Stream\\EventStream', $this->eventStore->read($aggregateRootType, $aggregateRootIdentifier)); }
public function setUp() { $this->unitOfWork = $this->getMock('RayRutjes\\DomainFoundation\\UnitOfWork\\UnitOfWork'); $this->aggregateRootType = Contract::createFromClassName('RayRutjes\\DomainFoundation\\Test\\Unit\\Domain\\AggregateRoot\\EventSourcedAggregateRootStub'); $this->eventStore = $this->getMock('RayRutjes\\DomainFoundation\\EventStore\\EventStore'); $this->eventBus = $this->getMock('RayRutjes\\DomainFoundation\\EventBus\\EventBus'); $this->repository = new AggregateRootRepository($this->unitOfWork, $this->aggregateRootType, $this->eventStore, $this->eventBus); }
/** * @param array $record * * @return Event */ private function translateRecordIntoEventMessage(array $record) { $identifier = new MessageIdentifier($record['event_id']); $payload = $this->eventSerializer->deserializePayload($record['event_payload'], Contract::createFromClassName($record['event_payload_type'])); $metadata = $this->eventSerializer->deserializeMetadata($record['event_metadata'], Contract::createFromClassName($record['event_metadata_type'])); $sequenceNumber = (int) $record['aggregate_version']; $eventMessage = new GenericEvent($this->aggregateRootIdentifier, $sequenceNumber, $identifier, $payload, $metadata); return $eventMessage; }
/** * @expectedException \RayRutjes\DomainFoundation\Repository\ConcurrencyException */ public function testDetectsConcurrencyAndThrowsTheAccordingException() { $aggregateRootIdentifier = new AggregateRootIdentifierStub(Uuid::NIL); $aggregateRootType = Contract::createFromClassName('Product'); $messageIdentifier = new MessageIdentifier(UUID::NIL); $payload = new PayloadStub(); $event = new GenericEvent($aggregateRootIdentifier, 1, $messageIdentifier, $payload); $eventStream = new GenericEventStream([$event]); $this->eventStore->append($aggregateRootType, $eventStream); }
/** * @param UnitOfWork $unitOfWork * @param Connection $connection */ public function __construct(UnitOfWork $unitOfWork, Connection $connection, EventBus $eventBus) { $eventStore = new DoctrineEventStore($connection); $aggregateRootType = Contract::createFromClassName(User::class); $this->repository = new AggregateRootRepository($unitOfWork, $aggregateRootType, $eventStore, $eventBus); }
/** * @depends testCanBeCreatedFromAClassName */ public function testCanDetermineIfItIsEqualToAnotherContract(Contract $contract) { $this->assertTrue($contract->equals($contract)); $this->assertFalse($contract->equals(Contract::createFromClassName('AnotherClassName'))); }
/** * @param UnitOfWork $unitOfWork * @param \PDO $pdo * @param EventBus $eventBus */ public function __construct(UnitOfWork $unitOfWork, \PDO $pdo, EventBus $eventBus) { $eventStore = new PdoEventStore($pdo); $aggregateRootType = Contract::createFromClassName(User::class); $this->repository = new AggregateRootRepository($unitOfWork, $aggregateRootType, $eventStore, $eventBus); }