/** * @test * @dataProvider providePersistence * @param Persistence $persistence */ public function it_should_disallow_tracking_AggregateRoots_twice(Persistence $persistence) { $unitOfWork = $this->buildUnitOfWork($persistence); $unitOfWork->track(Contract::with(Order::class), $this->orderId, $this->order); $this->setExpectedException(AggregateRootIsAlreadyBeingTracked::class); $unitOfWork->track(Contract::with(Order::class), $this->orderId, $this->order); }
/** * @param Contract $streamContract * @param Identifier $streamId * @return EventEnvelope[] */ public function fetch(Contract $streamContract, Identifier $streamId) { $records = $this->connection->fetchAll(Query\Select::from(self::TABLE_NAME), ['streamContract' => $streamContract, 'streamId' => $streamId]); $eventEnvelopes = array_map(function (array $record) { return EventEnvelope::reconstitute(EventId::fromString($record['eventId']), Contract::with($record['eventContract']), $record['eventPayload']); }, $records); return $eventEnvelopes; }
/** * @test * @depends it_should_commit_and_fetch_events * @dataProvider providePersistence * @param Persistence $persistence */ public function it_should_throw_when_events_have_been_committed_elsewhere(Persistence $persistence) { $commitId = CommitId::generate(); $streamContract = Contract::with('My.Contract'); $streamId = OrderId::generate(); $eventEnvelope = EventEnvelope::wrap(EventId::generate(), Contract::with("My.SomethingHasHappened"), "My payload2"); $this->setExpectedException(OptimisticConcurrencyFailed::class); $persistence->commit($commitId, $streamContract, $streamId, $expectedStreamVersion = 1, [$eventEnvelope]); }
/** * Make a contract from an fully qualified class name, of the form My.Namespace.Class * @param object|string $object * @return Contract */ public static function canonicalFrom($object) { return Contract::with(ClassFunctions::canonical($object)); }