diff --git a/src/PHPUnit/ApiCheckUserResponse.json b/src/PHPUnit/ApiCheckUserResponse.json new file mode 100644 index 0000000..81a50fe --- /dev/null +++ b/src/PHPUnit/ApiCheckUserResponse.json @@ -0,0 +1,5 @@ +{ + "error_msg": "error_Username already exists", + "data": "", + "error_code": 10003 +} \ No newline at end of file diff --git a/src/Response/ApiCheckUserResponse.php b/src/Response/ApiCheckUserResponse.php new file mode 100644 index 0000000..27b211b --- /dev/null +++ b/src/Response/ApiCheckUserResponse.php @@ -0,0 +1,44 @@ +userExists = $userExists; + } + + public function userExists(): bool + { + return $this->userExists; + } + + public static function generate(ResponseInterface $httpResponse): ApiCheckUserResponse|false + { + $primitiveApiResponse = parent::generate($httpResponse); + if (!$primitiveApiResponse) { + return false; + } + + $responseJson = $primitiveApiResponse->getResponseJson(); + $errorMessage = $primitiveApiResponse->getErrorMessage(); + $errorCode = $primitiveApiResponse->getErrorCode(); + + $userExists = 10003 === $errorCode ? true : false; + + return new ApiCheckUserResponse( + $httpResponse, + $errorMessage, + $errorCode, + $responseJson, + $userExists + ); + } +} diff --git a/src/Route/ApiCheckUserRoute.php b/src/Route/ApiCheckUserRoute.php new file mode 100644 index 0000000..39973dd --- /dev/null +++ b/src/Route/ApiCheckUserRoute.php @@ -0,0 +1,50 @@ +userName = $userName; + } + + public function getUserName(): string + { + return $this->userName; + } + + public static function getDescription(): string + { + return 'Check if the User Name already exists'; + } + + public static function getRequestRoute(): string + { + return 'user/check_user'; + } + + public static function getRequestMethod(): string + { + return 'POST'; + } + + /** + * @return class-string + */ + public static function getApiResponse(): string + { + return ApiCheckUserResponse::class; + } + + public function getAllParams(): array + { + return [ + 'user_name' => $this->getUserName(), + ]; + } +} diff --git a/tests/Response/ApiCheckUserResponse.php b/tests/Response/ApiCheckUserResponse.php new file mode 100644 index 0000000..55e7ac9 --- /dev/null +++ b/tests/Response/ApiCheckUserResponse.php @@ -0,0 +1,25 @@ +assertNotFalse($response = $this->makeApiClientRequest($route)); + $this->assertSame('', $response->getErrorMessage()); + $this->assertSame(0, $response->getErrorCode()); + $this->assertFalse($response->hasErrors()); + + $this->assertFalse($response->userExists()); + } +}