public function testGetUserNumberWillReturnFoundEntities() { $user = new User(); $numbers = [(new PhoneNumber())->setId(100), (new PhoneNumber())->setId(200)]; $this->repositoryMock->expects($this->once())->method('findUserNumbers')->with($user)->will($this->returnValue($numbers)); $this->assertSame($numbers, $this->useCase->getUserNumbers($user)); }
public function testRemoveExistingNumberWillRemoveItFromRepository() { $number = $this->createExampleNumber(); $this->repositoryMock->expects($this->once())->method('findById')->with(100)->will($this->returnValue($number)); $this->repositoryMock->expects($this->once())->method('remove')->with($number); $this->useCase->removeNumber($number); }
/** * @param PhoneNumber $number * @return void */ public function removeNumber(PhoneNumber $number) { if (!$this->repository->findById($number->getId())) { throw new NotExistingPhoneNumberException(sprintf('Phone number with [id = %d] does not exist', $number->getId())); } $this->repository->remove($number); $this->repository->synchronize(); }
public function testAddNumberToUserValidationPassesWillProceedToSaveUser() { $number = $this->createExamplePhoneNumber(); $this->repositoryMock->expects($this->once())->method('findById')->with(100)->will($this->returnValue($number)); $this->validatorMock->expects($this->once())->method('validate')->with($number)->will($this->returnValue(new ConstraintViolationList())); $this->repositoryMock->expects($this->once())->method('save')->with($number); $this->useCase->editPhoneNumber($number); }
/** * @param PhoneNumber $phoneNumber * @param User $user * @param bool $validate */ public function addNumberToUser(PhoneNumber $phoneNumber, User $user, $validate = true) { $user->addPhoneNumber($phoneNumber); $phoneNumber->setOwner($user); if ($validate) { $this->validateInput($phoneNumber, $user); } $this->numberRepository->save($phoneNumber); $this->numberRepository->synchronize(); }
/** * @param PhoneNumber $phoneNumber * @throws NotExistingPhoneNumberException * @throws EditPhoneNumberException */ private function validatePhoneNumber(PhoneNumber $phoneNumber) { if (!$this->repository->findById($phoneNumber->getId())) { throw new NotExistingPhoneNumberException(sprintf('Phone number with [id = %d] does not exist.', $phoneNumber->getId())); } $violations = $this->validator->validate($phoneNumber); if ($violations->count()) { throw new EditPhoneNumberException($violations); } }
/** * @param User $user * @param int $numberId * @return PhoneNumber */ public function getUserNumber(User $user, $numberId) { return $this->repository->findUserNumber($user, $numberId); }
/** * @param User $user * @return PhoneNumber[] */ public function getUserNumbers(User $user) { return $this->repository->findUserNumbers($user); }