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); }