diff --git a/app/Notification/AppNotificationInterface.php b/app/Notification/AppNotificationInterface.php index 3d7acc9..d221d90 100644 --- a/app/Notification/AppNotificationInterface.php +++ b/app/Notification/AppNotificationInterface.php @@ -4,12 +4,12 @@ namespace App\Notification; -use App\Notification\Client\HTTPClientAdapterInterface; -use App\Notification\Client\ResponseAdapterInterface; +use App\Notification\Client\HttpClientAdapterInterface; +use Psr\Http\Message\ResponseInterface; interface AppNotificationInterface { - public function __construct(HTTPClientAdapterInterface $client, string $message, string $messageType); + public function __construct(HttpClientAdapterInterface $client, string $message, string $messageType); - public function notify(): ResponseAdapterInterface; + public function notify(): ResponseInterface; } diff --git a/app/Notification/Client/Guzzle/GuzzleHTTPClient.php b/app/Notification/Client/Guzzle/GuzzleHTTPClient.php deleted file mode 100644 index 4be067c..0000000 --- a/app/Notification/Client/Guzzle/GuzzleHTTPClient.php +++ /dev/null @@ -1,32 +0,0 @@ -client = new Client(); - } - - public function post(string $url, array $params): ResponseAdapterInterface - { - $clientResponse = $this->client->post( - $url, - [ - 'json' => $params - ] - ); - - return new GuzzleResponse($clientResponse); - } -} diff --git a/app/Notification/Client/Guzzle/GuzzleHttpClient.php b/app/Notification/Client/Guzzle/GuzzleHttpClient.php new file mode 100644 index 0000000..1f8b189 --- /dev/null +++ b/app/Notification/Client/Guzzle/GuzzleHttpClient.php @@ -0,0 +1,29 @@ +client = new Client(); + } + + public function post(string $url, array $params): ResponseInterface + { + return $this->client->post( + $url, + [ + 'json' => $params + ] + ); + } +} diff --git a/app/Notification/Client/Guzzle/GuzzleResponse.php b/app/Notification/Client/Guzzle/GuzzleResponse.php deleted file mode 100644 index a641b21..0000000 --- a/app/Notification/Client/Guzzle/GuzzleResponse.php +++ /dev/null @@ -1,31 +0,0 @@ -clientResponse = $clientResponse; - } - - public function getResponse(): array - { - return self::sanitizeResponse($this->clientResponse); - } - - private static function sanitizeResponse(ResponseInterface $guzzleResponse): array - { - return [ - 'status_code' => $guzzleResponse->getStatusCode(), - 'message' => $guzzleResponse->getReasonPhrase() - ]; - } -} diff --git a/app/Notification/Client/HTTPClientAdapterInterface.php b/app/Notification/Client/HTTPClientAdapterInterface.php deleted file mode 100644 index 25c7c16..0000000 --- a/app/Notification/Client/HTTPClientAdapterInterface.php +++ /dev/null @@ -1,10 +0,0 @@ -message = new SlackStylizedMessageCreator($message, $messageType); $this->client = $client; } - public function notify(): ResponseAdapterInterface + public function notify(): ResponseInterface { return $this->client->post( getenv('SLACK_API_WEBHOOK'), diff --git a/app/Route/Router.php b/app/Route/Router.php index cf432f8..c7ae75e 100644 --- a/app/Route/Router.php +++ b/app/Route/Router.php @@ -4,7 +4,7 @@ namespace App\Route; -use App\Notification\Client\Guzzle\GuzzleHTTPClient; +use App\Notification\Client\Guzzle\GuzzleHttpClient; use App\Notification\NotificationTypeEnum; use App\Notification\StatusCodeEnum; use App\Notification\Slack\SlackNotification; @@ -41,7 +41,7 @@ private static function createReflectionMethod(array $uriContent): ReflectionMet return new ReflectionMethod($uriContent['namespace'], $uriContent['method']); } catch (ReflectionException $exception) { (new SlackNotification( - new GuzzleHTTPClient(), + new GuzzleHttpClient(), $exception->getMessage(), NotificationTypeEnum::ERROR() ))->notify(); diff --git a/composer.json b/composer.json index 8c78f37..840051c 100755 --- a/composer.json +++ b/composer.json @@ -41,6 +41,6 @@ "phpunit/phpunit": "8.5.*" }, "scripts": { - "tests": "./vendor/bin/phpunit tests --color=always --stop-on-failure", + "tests": "./vendor/bin/phpunit tests --color=always --stop-on-failure" } } diff --git a/tests/Notification/Fake/FakeHttpClient.php b/tests/Notification/Fake/FakeHttpClient.php new file mode 100644 index 0000000..2f20403 --- /dev/null +++ b/tests/Notification/Fake/FakeHttpClient.php @@ -0,0 +1,23 @@ +response = $response; + } + + public function post(string $url, array $params): ResponseInterface + { + return $this->response; + } +} diff --git a/tests/Notification/FakeNotificationResponseTest.php b/tests/Notification/FakeNotificationResponseTest.php new file mode 100644 index 0000000..5715d95 --- /dev/null +++ b/tests/Notification/FakeNotificationResponseTest.php @@ -0,0 +1,30 @@ +mockResponse($notificationResponse); + + $response = $fakeClient->post($fakeUrl = 'https://fake.com', $emptyParams = []); + + Assert::assertEquals($expectedStatusCodeResponse = 200, $response->getStatusCode()); + Assert::assertEquals($expectedPhraseResponse = 'OK', $response->getReasonPhrase()); + } +} diff --git a/tests/Notification/Slack/SlackNotificationTest.php b/tests/Notification/Slack/SlackNotificationTest.php deleted file mode 100644 index 8aa25aa..0000000 --- a/tests/Notification/Slack/SlackNotificationTest.php +++ /dev/null @@ -1,36 +0,0 @@ -notify(); - - $expectedResponse = [ - 'status_code' => 200, - 'message' => 'OK', - ]; - - Assert::assertInstanceOf(ResponseAdapterInterface::class, $notificationResponse); - Assert::assertEquals($expectedResponse, $notificationResponse->getResponse()); - } -}