Skip to content

Hotfix/improve notification test #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Notification/AppNotificationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


use App\Notification\Client\HTTPClientAdapterInterface;
use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HTTPResponseInterface;

interface AppNotificationInterface
{
public function __construct(HTTPClientAdapterInterface $client, string $message, string $messageType);

public function notify(): ResponseAdapterInterface;
public function notify(): HTTPResponseInterface;
}
9 changes: 4 additions & 5 deletions app/Notification/Client/Guzzle/GuzzleHTTPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@


use App\Notification\Client\HTTPClientAdapterInterface;
use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HTTPResponseInterface;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

class GuzzleHTTPClient implements HTTPClientAdapterInterface
{
Expand All @@ -18,15 +17,15 @@ public function __construct()
$this->client = new Client();
}

public function post(string $url, array $params): ResponseAdapterInterface
public function post(string $url, array $params): HTTPResponseInterface
{
$clientResponse = $this->client->post(
$guzzleResponse = $this->client->post(
$url,
[
'json' => $params
]
);

return new GuzzleResponse($clientResponse);
return new HTTPResponse($guzzleResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
namespace App\Notification\Client\Guzzle;


use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HTTPResponseInterface;
use Psr\Http\Message\ResponseInterface;

class GuzzleResponse implements ResponseAdapterInterface
class HTTPResponse implements HTTPResponseInterface
{
private ResponseInterface $clientResponse;

Expand Down
2 changes: 1 addition & 1 deletion app/Notification/Client/HTTPClientAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

interface HTTPClientAdapterInterface
{
public function post(string $url, array $params): ResponseAdapterInterface;
public function post(string $url, array $params): HTTPResponseInterface;
}
14 changes: 14 additions & 0 deletions app/Notification/Client/HTTPResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php


namespace App\Notification\Client;


use Psr\Http\Message\ResponseInterface;

interface HTTPResponseInterface
{
public function __construct(ResponseInterface $clientResponse);

public function getResponse(): array;
}
10 changes: 0 additions & 10 deletions app/Notification/Client/ResponseAdapterInterface.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Notification/Slack/SlackNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Notification\AppNotificationInterface;
use App\Notification\Client\HTTPClientAdapterInterface;
use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HTTPResponseInterface;

final class SlackNotification implements AppNotificationInterface
{
Expand All @@ -19,7 +19,7 @@ public function __construct(HTTPClientAdapterInterface $client, string $message,
$this->client = $client;
}

public function notify(): ResponseAdapterInterface
public function notify(): HTTPResponseInterface
{
return $this->client->post(
getenv('SLACK_API_WEBHOOK'),
Expand Down
24 changes: 24 additions & 0 deletions tests/Notification/Slack/FakeSlackNotificationResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php


namespace App\Test\Notification\Slack;


use App\Notification\Client\Guzzle\HTTPResponse;
use App\Notification\Client\HTTPResponseInterface;
use Psr\Http\Message\ResponseInterface;

class FakeSlackNotificationResponse implements HTTPResponseInterface
{
private ResponseInterface $response;

public function __construct(ResponseInterface $response)
{
$this->response = $response;
}

public function getResponse(): array
{
return (new HTTPResponse($this->response))->getResponse();
}
}
34 changes: 34 additions & 0 deletions tests/Notification/Slack/FakeSlackNotificationResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Test\Notification\Slack;

use App\Notification\Client\HTTPResponseInterface;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

require_once 'app/DotEnvLoader/index.php';

class FakeSlackNotificationResponseTest extends TestCase
{
public static function test_FakeSlackNotificationResponse_ShouldAssertHTTPResponse(): void
{
$notificationResponse = new Response(
$statusCode = 200,
$responseHeader = [],
$responseBody = null,
$protocolVersion = '1.1',
$responseReason = 'OK'
);

$fakerResponse = new FakeSlackNotificationResponse($notificationResponse);

$expectedResponse = [
'status_code' => 200,
'message' => 'OK',
];

Assert::assertInstanceOf(HTTPResponseInterface::class, $fakerResponse);
Assert::assertEquals($expectedResponse, $fakerResponse->getResponse());
}
}
36 changes: 0 additions & 36 deletions tests/Notification/Slack/SlackNotificationTest.php

This file was deleted.