コード例 #1
0
ファイル: Users.php プロジェクト: EightArmCode/librarian
 /**
  * @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;
 }
コード例 #2
0
ファイル: User.php プロジェクト: EightArmCode/librarian
 /**
  * @param UserCreated $event
  */
 protected function applyUserCreated(UserCreated $event)
 {
     parent::applyUserCreated($event);
     $this->userName = $event->getUserName();
     $this->emailAddress = $event->getEmailAddress();
     $this->fullName = $event->getFullName();
 }
コード例 #3
0
 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);
 }
コード例 #4
0
ファイル: UsersTest.php プロジェクト: EightArmCode/librarian
 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());
 }
コード例 #5
0
 /**
  * @param CreateUser $command
  */
 public function handleCreateUser(CreateUser $command)
 {
     $user = User::create($command->getId(), $command->getUserName(), $command->getEmailAddress(), $command->getFullName());
     $this->repository->store($user);
 }