-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 changed files
with
127 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
use Jenky\Atlas\Body\MultipartResource; | ||
use Jenky\Atlas\Exception\HttpException; | ||
use Jenky\Atlas\Mock\MockClient; | ||
use Jenky\Atlas\Mock\MockResponse; | ||
use Jenky\Atlas\Response; | ||
use Jenky\Atlas\Tests\Services\HTTPBin\Connector; | ||
use Jenky\Atlas\Tests\Services\HTTPBin\DTO\Uuid; | ||
|
@@ -45,20 +47,28 @@ public function test_sending_request_directly(): void | |
|
||
public function test_sending_request_from_connector(): void | ||
{ | ||
$response = $this->connector->send(new GetHeadersRequest()); | ||
$client = new MockClient(); | ||
$connector = $this->connector->withClient($client); | ||
|
||
$response = $connector->send(new GetHeadersRequest()); | ||
|
||
$this->assertTrue($response->ok()); | ||
} | ||
|
||
public function test_request_headers(): void | ||
{ | ||
$client = new MockClient( | ||
MockResponse::fixture(__DIR__.'/fixtures/headers.json') | ||
); | ||
$connector = $this->connector->withClient($client); | ||
|
||
$request = new GetHeadersRequest(); | ||
|
||
$request->headers() | ||
->with('Accept', 'application/json') | ||
->with('X-Foo', 'bar'); | ||
|
||
$response = $this->connector->send($request); | ||
$response = $connector->send($request); | ||
|
||
$this->assertTrue($response->ok()); | ||
$this->assertSame('bar', $response->data()['headers']['X-Foo'] ?? null); | ||
|
@@ -67,9 +77,14 @@ public function test_request_headers(): void | |
|
||
public function test_cast_response_to_dto(): void | ||
{ | ||
$client = new MockClient( | ||
MockResponse::create(['uuid' => '01b67779-4690-4094-8e83-624cc496e1ef']) | ||
); | ||
$connector = $this->connector->withClient($client); | ||
|
||
$request = new GetUuidRequest(); | ||
|
||
$response = $this->connector->send($request); | ||
$response = $connector->send($request); | ||
|
||
$this->assertTrue($response->ok()); | ||
$this->assertInstanceOf(Uuid::class, $dto = Uuid::fromResponse($response)); | ||
|
@@ -78,13 +93,18 @@ public function test_cast_response_to_dto(): void | |
|
||
public function test_request_body(): void | ||
{ | ||
$client = new MockClient( | ||
MockResponse::fixture(__DIR__.'/fixtures/anything.json') | ||
); | ||
$connector = $this->connector->withClient($client); | ||
|
||
$request = new PostAnythingRequest(); | ||
|
||
$request->body() | ||
->with('hello', 'world') | ||
->merge(['foo' => 'bar'], ['buzz' => 'quiz']); | ||
|
||
$response = $this->connector->send($request); | ||
$response = $connector->send($request); | ||
|
||
$this->assertTrue($response->ok()); | ||
$this->assertSame('bar', $response['json']['foo'] ?? null); | ||
|
@@ -94,11 +114,16 @@ public function test_request_body(): void | |
|
||
public function test_request_multipart(): void | ||
{ | ||
$client = new MockClient( | ||
MockResponse::fixture(__DIR__.'/fixtures/multipart.json') | ||
); | ||
$connector = $this->connector->withClient($client); | ||
|
||
$request = new PostRequest('John', '[email protected]'); | ||
$request->body() | ||
->with('img', MultipartResource::from(__DIR__.'/fixtures/1x1.png')); | ||
|
||
$response = $this->connector->send($request); | ||
$response = $connector->send($request); | ||
|
||
$this->assertFalse($response->failed()); | ||
|
||
|
@@ -111,9 +136,14 @@ public function test_request_multipart(): void | |
|
||
public function test_response_xml_decoder(): void | ||
{ | ||
$client = new MockClient( | ||
MockResponse::fixture(__DIR__.'/fixtures/slideshow.xml', 200, ['Content-Type' => 'text/xml']) | ||
); | ||
$connector = $this->connector->withClient($client); | ||
|
||
$request = new GetXmlRequest(); | ||
|
||
$response = $this->connector->send($request); | ||
$response = $connector->send($request); | ||
|
||
$this->assertTrue($response->ok()); | ||
|
||
|
@@ -123,14 +153,20 @@ public function test_response_xml_decoder(): void | |
|
||
public function test_response_exception(): void | ||
{ | ||
$client = new MockClient([ | ||
MockResponse::create('', 400), | ||
MockResponse::create(''), | ||
]); | ||
$connector = $this->connector->withClient($client); | ||
|
||
$request = new GetStatusRequest(400); | ||
|
||
$this->expectException(HttpException::class); | ||
|
||
$this->connector->send($request)->throwIf(function (Response $response) { | ||
$connector->send($request)->throwIf(function (Response $response) { | ||
return $response->failed(); | ||
}); | ||
|
||
$this->connector->send($request->withStatus(200))->throwIf(true); | ||
$connector->send($request->withStatus(200))->throwIf(true); | ||
} | ||
} |
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,26 @@ | ||
{ | ||
"args": {}, | ||
"data": { | ||
"hello": "world", | ||
"foo": "bar", | ||
"buzz": "quiz" | ||
}, | ||
"files": {}, | ||
"form": {}, | ||
"headers": { | ||
"Content-Length": "43", | ||
"Content-Type": "application/json", | ||
"Host": "httpbin.org", | ||
"User-Agent": "GuzzleHttp/7", | ||
"X-Amzn-Trace-Id": "Root=1-648be8e7-22eb348849e631df01a655d9", | ||
"X-From": "atlas" | ||
}, | ||
"json": { | ||
"buzz": "quiz", | ||
"foo": "bar", | ||
"hello": "world" | ||
}, | ||
"method": "POST", | ||
"origin": "222.252.14.21", | ||
"url": "https://httpbin.org/anything" | ||
} |
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,11 @@ | ||
{ | ||
"headers": { | ||
"Accept": "application/json", | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
"Host": "httpbin.org", | ||
"User-Agent": "GuzzleHttp/7", | ||
"X-Amzn-Trace-Id": "Root=1-648be83a-1a58dcdc0ee57cf561dd6de9", | ||
"X-Foo": "bar", | ||
"X-From": "atlas" | ||
} | ||
} |
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,22 @@ | ||
{ | ||
"args": {}, | ||
"data": "", | ||
"files": { | ||
"img": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=" | ||
}, | ||
"form": { | ||
"email": "[email protected]", | ||
"name": "John" | ||
}, | ||
"headers": { | ||
"Content-Length": "548", | ||
"Content-Type": "multipart/form-data; boundary=3a257f6bae64997ef39d9f6ce690da26f85c6fa8", | ||
"Host": "httpbin.org", | ||
"User-Agent": "GuzzleHttp/7", | ||
"X-Amzn-Trace-Id": "Root=1-648be978-61653b9e74646cd85f2fc9fc", | ||
"X-From": "atlas" | ||
}, | ||
"json": null, | ||
"origin": "222.252.14.21", | ||
"url": "https://httpbin.org/post" | ||
} |
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,24 @@ | ||
<?xml version='1.0' encoding='us-ascii'?> | ||
|
||
<!-- A SAMPLE set of slides --> | ||
|
||
<slideshow | ||
title="Sample Slide Show" | ||
date="Date of publication" | ||
author="Yours Truly" | ||
> | ||
|
||
<!-- TITLE SLIDE --> | ||
<slide type="all"> | ||
<title>Wake up to WonderWidgets!</title> | ||
</slide> | ||
|
||
<!-- OVERVIEW --> | ||
<slide type="all"> | ||
<title>Overview</title> | ||
<item>Why <em>WonderWidgets</em> are great</item> | ||
<item/> | ||
<item>Who <em>buys</em> WonderWidgets</item> | ||
</slide> | ||
|
||
</slideshow> |