Exemple #1
0
 public function it_should_throw_on_set_email_if_email_is_taken(HttpClient $client, UserRepositoryInterface $repository)
 {
     $newEmail = '*****@*****.**';
     $repository->hasUserEmail($newEmail)->shouldBeCalled()->willReturn(true);
     $this->shouldThrow('\\Pisa\\GizmoAPI\\Exceptions\\ValidationException')->duringSetEmail($repository, $newEmail);
     $this->Email->shouldNotBe($newEmail);
 }
Exemple #2
0
 /**
  * @return  void
  * @throws  Exception on error
  */
 public function setEmail(UserRepositoryInterface $repository, $newEmail)
 {
     if (!$this->exists()) {
         throw new RequirementException("User doesn't exist");
     } elseif ($repository->hasUserEmail($newEmail)) {
         throw new ValidationException("{$newEmail} is already registered");
     }
     $response = $this->client->post('Users/SetUserEmail', ['userId' => $this->getPrimaryKeyValue(), 'newEmail' => $newEmail]);
     if ($response === null) {
         throw new InternalException("Response failed");
     }
     $response->assertEmpty();
     $response->assertStatusCodes(204);
     $this->Email = $newEmail;
 }