public function testAddNumberToUserValidationPassesWillProceedToSaveUser()
 {
     $user = $this->createExampleUser();
     $number = $this->createExamplePhoneNumber();
     $this->userRepositoryMock->expects($this->once())->method('findById')->with(100)->will($this->returnValue($user));
     $this->validatorMock->expects($this->once())->method('validate')->with($number)->will($this->returnValue(new ConstraintViolationList()));
     $this->numberRepositoryMock->expects($this->once())->method('save')->with($number);
     $this->useCase->addNumberToUser($number, $user);
     $this->assertSame($number, $user->getPhoneNumbers()->get(0));
     $this->assertSame($user, $number->getOwner());
 }
 /**
  * @param PhoneNumber $number
  * @param User $user
  * @param Request $request
  * @return View
  */
 private function processForm(PhoneNumber $number, User $user, Request $request)
 {
     $number->setOwner($user);
     $form = $this->formFactory->createNamed('phoneNumber', 'phone_number_add', $number);
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return new View($form, 400);
     }
     $this->useCase->addNumberToUser($number, $user, false);
     return new View($number, 201, ['Location' => $this->router->generate('arkon_phonebook_get_user_number', ['id' => $user->getId(), 'numberId' => $number->getId()], true)]);
 }
 public function testCreateUserFormDataValidWillReturn201Response()
 {
     $request = $this->createExampleRequest();
     $user = $this->createExampleUser();
     $this->formMock->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->useCaseMock->expects($this->once())->method('addNumberToUser');
     $this->routerMock->expects($this->once())->method('generate')->will($this->returnValue('http://example.com'));
     $view = $this->controller->addNumberAction($user, $request);
     $this->assertInstanceOf(PhoneNumber::class, $view->getData());
     $this->assertSame(201, $view->getStatusCode());
     $this->assertSame(['http://example.com'], $view->getHeaders()['location']);
 }