/** * @param Uuid $id * @return User * @throws AggregateNotFoundException */ public function findById(Uuid $id) { $events = $this->storage->getEventsForAggregate($id); $user = new User($id); $user->loadFromHistory($events); return $user; }
/** * @param UserCreated $event */ protected function applyUserCreated(UserCreated $event) { parent::applyUserCreated($event); $this->userName = $event->getUserName(); $this->emailAddress = $event->getEmailAddress(); $this->fullName = $event->getFullName(); }
public function testCreateUserHandlerWillCallStoreOnRepository() { $id = Uuid::createNew(); $userName = '******'; $emailAddress = 'bar'; $fullName = 'baz boo'; $command = new CreateUser($id, $userName, $emailAddress, $fullName); $user = User::create($command->getId(), $command->getUserName(), $command->getEmailAddress(), $command->getFullName()); $repository = $this->getMockBuilder(Repository::class)->disableOriginalConstructor()->getMock(); $repository->expects(self::once())->method('store')->with($user); $handler = new CreateUserHandler($repository); $handler->handle($command); }
public function testFindUserByIdLoadsUserFromHistory() { $userId = Uuid::createNew(); $userName = '******'; $emailAddress = 'bar'; $fullName = 'baz boo'; $expectedUser = User::create($userId, $userName, $emailAddress, $fullName); $events = new Events([new UserCreated($userId, $userName, $emailAddress, $fullName)]); $storage = $this->getMockBuilder(EventStore::class)->disableOriginalConstructor()->getMock(); $storage->expects(self::once())->method('getEventsForAggregate')->with($userId)->will(self::returnValue($events)); $repository = new Users($storage); $actualUser = $repository->findById($userId); self::assertEquals($expectedUser->getId(), $actualUser->getId()); }
/** * @param CreateUser $command */ public function handleCreateUser(CreateUser $command) { $user = User::create($command->getId(), $command->getUserName(), $command->getEmailAddress(), $command->getFullName()); $this->repository->store($user); }