public function testGetUserByEmailAddressIfNotFoundReturnsNull() { $storage = $this->getMockBuilder(Storage::class)->getMockForAbstractClass(); $service = new UserService($storage); $actual = $service->getUserByUserName('foo'); self::assertNull($actual); }
public function testGetByUserNameActionThrowsNotFoundExceptionIfNotFound() { self::setExpectedException(NotFoundHttpException::class); $id = Uuid::createNew(); $user = new User($id, 'user', 'email', 'name', 0); $this->service->expects(self::once())->method('getUserByUserName')->with('user')->will(self::returnValue(null)); $fetcher = $this->getMockBuilder(ParamFetcherInterface::class)->getMockForAbstractClass(); $fetcher->expects(self::once())->method('get')->with('user_name')->will(self::returnValue('user')); $controller = new UsersController($this->viewBuilder, $this->service, $this->commandBus); $view = $controller->getByUserNameAction($fetcher); }
/** * @param Uuid $id * @return UserReadModel * @throws NotFoundHttpException */ private function getUser(Uuid $id) { try { return $this->userService->getUser($id); } catch (ObjectNotFoundException $e) { throw new NotFoundHttpException($e->getMessage(), $e); } }
/** * @Rest\Put("", * condition="request.headers.get('content-type') matches '/domain-model=create-user/i'" * ) * @Rest\View() * * @ParamConverter("userResource", * class="AppBundle\Controller\Resource\User", * converter="fos_rest.request_body" * ) * * @param UserResource $userResource * @return View * @throws HttpException */ public function createAction(UserResource $userResource) { $user = $this->userService->getUserByUserName($userResource->getUserName()); if ($user != null) { return $this->viewBuilder->setStatus(204)->setVersion($user)->setLocation(static::BASE_ROUTE . $user->getId())->build(); } $id = Uuid::createNew(); $command = new CreateUser($id, $userResource->getUserName(), $userResource->getEmailAddress(), $userResource->getFullName()); $this->commandBus->send($command); $user = $this->userService->getUser($id); return $this->viewBuilder->setDocument($user)->setVersion()->setLocation(static::BASE_ROUTE . $user->getId())->setStatus(201)->build(); }
public function testApplyConverterOnUserCreatesUser() { $id = Uuid::createNew(); $user = new UserReadModel($id, 'user', 'email', 'name', 1); $request = Request::createFromGlobals(); $request->attributes->set('id', $id); $this->userService->expects(self::once())->method('getUser')->with($id)->will(self::returnValue($user)); $this->configuration->expects(self::once())->method('getOptions')->will(self::returnValue(['id' => 'id'])); $this->configuration->expects(self::atLeastOnce())->method('getClass')->will(self::returnValue(UserResource::class)); $this->configuration->expects(self::atLeastOnce())->method('getName')->will(self::returnValue('user')); $converter = new ParamConverter($this->bookService, $this->userService); $converter->apply($request, $this->configuration); self::assertEquals($user->getId()->getValue(), $request->attributes->get('user')->getId()->getValue()); }