/** * @test */ public function it_loads_events_by_matching_metadata() { $stream = $this->getTestStream(); $this->eventStore->beginTransaction(); $this->eventStore->create($stream); $this->eventStore->commit(); $streamEventWithMetadata = TestDomainEvent::with(['name' => 'Alex', 'email' => '*****@*****.**'], 2); $streamEventWithMetadata = $streamEventWithMetadata->withAddedMetadata('snapshot', true); $this->eventStore->beginTransaction(); $this->eventStore->appendTo($stream->streamName(), [$streamEventWithMetadata]); $this->eventStore->commit(); $loadedEvents = $this->eventStore->loadEventsByMetadataFrom($stream->streamName(), ['snapshot' => true]); $this->assertEquals(1, count($loadedEvents)); $this->assertTrue($loadedEvents[0]->metadata()['snapshot']); }
/** * @test */ public function it_reads_stream_events_for_aggregate() { $this->eventStore->beginTransaction(); $user = User::create("John Doe", "*****@*****.**"); $aggregateType = AggregateType::fromString('Object'); $aggregateId1 = Uuid::uuid4()->toString(); $streamEvents1 = [UserCreated::with(['user_id' => $aggregateId1], 1)]; $this->strategy->addEventsForNewAggregateRoot($aggregateType, $aggregateId1, $streamEvents1, $user); $product = new Product(); $aggregateId2 = Uuid::uuid4()->toString(); $streamEvents2 = [TestDomainEvent::with(['product_id' => $aggregateId2], 1)]; $this->strategy->addEventsForNewAggregateRoot($aggregateType, $aggregateId2, $streamEvents2, $product); $this->eventStore->commit(); $streamEvents = $this->strategy->read($aggregateType, $aggregateId2); $this->assertEquals(1, count($streamEvents)); $this->assertInstanceOf(DomainEvent::class, $streamEvents[0]); $this->assertEquals($aggregateId2, $streamEvents[0]->payload()['product_id']); $arType = $this->strategy->getAggregateRootType($aggregateType, $streamEvents); $this->assertEquals('Prooph\\EventStoreTest\\Mock\\Product', $arType->toString()); }