/** * @test */ public function an_invokable_plugin_is_loaded_by_plugin_manager_and_attached_to_event_store_by_configuration() { $pluginManager = new ServiceManager(new Config(["invokables" => ["eventlogger" => EventLoggerPlugin::class]])); $eventStore = new EventStore(new InMemoryAdapter(), new ProophActionEventEmitter()); $logger = $pluginManager->get('eventlogger'); $logger->setUp($eventStore); $repository = new AggregateRepository($eventStore, AggregateType::fromAggregateRootClass('Prooph\\EventStoreTest\\Mock\\User'), new ConfigurableAggregateTranslator(), new AggregateStreamStrategy($eventStore)); $eventStore->beginTransaction(); $user = User::create("Alex", "*****@*****.**"); $repository->addAggregateRoot($user); $eventStore->commit(); $loggedStreamEvents = $pluginManager->get("eventlogger")->getLoggedStreamEvents(); $this->assertEquals(1, count($loggedStreamEvents)); }
/** * @test */ public function it_tracks_changes_of_aggregate() { $this->eventStore->beginTransaction(); $user = User::create('John Doe', '*****@*****.**'); $this->repository->addAggregateRoot($user); $this->eventStore->commit(); $this->eventStore->beginTransaction(); $fetchedUser = $this->repository->getAggregateRoot($user->getId()->toString()); $this->assertSame($user, $fetchedUser); $fetchedUser->changeName('Max Mustermann'); $this->eventStore->commit(); $this->clearRepositoryIdentityMap(); $fetchedUser2 = $this->repository->getAggregateRoot($user->getId()->toString()); $this->assertNotSame($fetchedUser, $fetchedUser2); $this->assertEquals('Max Mustermann', $fetchedUser2->name()); }
/** * @test * @expectedException \InvalidArgumentException */ public function it_does_not_allow_to_add_stream_events_with_wrong_repository_aggregate_type() { $this->eventStore->beginTransaction(); $user = User::create("John Doe", "*****@*****.**"); $aggregateType = AggregateType::fromAggregateRoot($user); $aggregateId = Uuid::uuid4()->toString(); $streamEvents = [UserCreated::with(['user_id' => $aggregateId], 1)]; $this->strategy->addEventsForNewAggregateRoot($aggregateType, $aggregateId, $streamEvents, $user); $this->eventStore->commit(); $this->eventStore->beginTransaction(); $streamEvents = [UsernameChanged::with(['name' => 'John Doe'], 2)]; $this->strategy->appendEvents(AggregateType::fromString("Product"), $aggregateId, $streamEvents, $user); }
/** * @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()); }