-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
105 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
|
||
namespace App\Notification\Client\Guzzle; | ||
|
||
|
||
use App\Notification\Client\HttpClientAdapterInterface; | ||
use GuzzleHttp\Client; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
final class GuzzleHttpClient implements HttpClientAdapterInterface | ||
{ | ||
private Client $client; | ||
|
||
public function __construct() | ||
{ | ||
$this->client = new Client(); | ||
} | ||
|
||
public function post(string $url, array $params): ResponseInterface | ||
{ | ||
return $this->client->post( | ||
$url, | ||
[ | ||
'json' => $params | ||
] | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
|
||
namespace App\Notification\Client; | ||
|
||
|
||
use Psr\Http\Message\ResponseInterface; | ||
|
||
interface HttpClientAdapterInterface | ||
{ | ||
public function post(string $url, array $params): ResponseInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
|
||
namespace App\Test\Notification\Fake; | ||
|
||
|
||
use App\Notification\Client\HttpClientAdapterInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class FakeHttpClient implements HttpClientAdapterInterface | ||
{ | ||
private ResponseInterface $response; | ||
|
||
public function mockResponse(ResponseInterface $response): void | ||
{ | ||
$this->response = $response; | ||
} | ||
|
||
public function post(string $url, array $params): ResponseInterface | ||
{ | ||
return $this->response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Test\Notification\Slack; | ||
|
||
use App\Test\Notification\Fake\FakeHttpClient; | ||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class FakeNotificationResponseTest extends TestCase | ||
{ | ||
public static function test_FakeHttpClient_ShouldAssertHttpResponse(): void | ||
{ | ||
$notificationResponse = new Response( | ||
$statusCode = 200, | ||
$responseHeader = [], | ||
$responseBody = null, | ||
$protocolVersion = '1.1', | ||
$responseReason = 'OK' | ||
); | ||
|
||
$fakeClient = new FakeHttpClient(); | ||
$fakeClient->mockResponse($notificationResponse); | ||
|
||
$response = $fakeClient->post($fakeUrl = 'https://fake.com', $emptyParams = []); | ||
|
||
Assert::assertEquals($expectedStatusCodeResponse = 200, $response->getStatusCode()); | ||
Assert::assertEquals($expectedPhraseResponse = 'OK', $response->getReasonPhrase()); | ||
} | ||
} |