public function it_should_throw_on_rename_if_username_is_taken(HttpClient $client, UserRepositoryInterface $repository) { $newUserName = '******'; $repository->hasUserName($newUserName)->shouldBeCalled()->willReturn(true); $this->shouldThrow('\\Pisa\\GizmoAPI\\Exceptions\\ValidationException')->duringRename($repository, $newUserName); $this->UserName->shouldNotBe($newUserName); }
/** * @return void * @throws Exception on error */ public function rename(UserRepositoryInterface $repository, $newUserName) { if (!$this->exists()) { throw new RequirementException("User doesn't exist"); } elseif ($repository->hasUserName($newUserName)) { throw new ValidationException("{$newUserName} already exists"); } $response = $this->client->post('Users/Rename', ['userId' => $this->getPrimaryKeyValue(), 'newUserName' => $newUserName]); if ($response === null) { throw new InternalException("Response failed"); } $response->assertEmpty(); $response->assertStatusCodes(204); $this->UserName = $newUserName; }