Skip to content

Commit 209f893

Browse files
committed
fix depending unit test
1 parent 4915272 commit 209f893

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

tests/Libraries/ClientExternalTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tests\Libraries;
66

7+
use GuzzleHttp\Exception\ConnectException;
78
use GuzzleHttp\Exception\GuzzleException;
89
use GuzzleHttp\HandlerStack;
910
use GuzzleHttp\Psr7\MultipartStream;
@@ -31,7 +32,11 @@ public function testCallEksternal1(): void
3132
['content-type' => 'application/json'],
3233
json_encode(['message' => 'hello world'])
3334
);
34-
$client = new ClientExternal();
35+
$mock = new MockHandler([
36+
new Response(200, ['Content-Type' => 'application/json'], json_encode(['status' => 'ok', 'message' => 'hello world'])),
37+
]);
38+
$handlerStack = new HandlerStack($mock);
39+
$client = new ClientExternal(['handler' => $handlerStack]);
3540
$response = $client->call($request);
3641
$contents = $response->getBody()->getContents();
3742
$contents_arr = json_decode($contents, true, 512);
@@ -50,6 +55,11 @@ public function testCallExternalMultipartSuccess(): void
5055
$f = fopen('public/docs/hello.txt', 'w');
5156
fwrite($f, 'hello world');
5257
fclose($f);
58+
$mock = new MockHandler([
59+
new Response(200, ['Content-Type' => 'application/json'], json_encode(['id' => '101', 'status' => 'ok', 'message' => 'well done'])),
60+
]);
61+
$handlerStack = new HandlerStack($mock);
62+
$client = new ClientExternal(['handler' => $handlerStack]);
5363
$request = new Request(
5464
'POST',
5565
'https://jsonplaceholder.typicode.com/posts',
@@ -61,7 +71,6 @@ public function testCallExternalMultipartSuccess(): void
6171
]
6272
])
6373
);
64-
$client = new ClientExternal();
6574
$resp = $client
6675
->injectRequestHeader(['X-Unit-Test' => ['clover']])
6776
->injectResponseHeader(['X-Unit-Test-Response' => ['clover-response']])
@@ -88,7 +97,11 @@ public function testCallExternalMultipartError(): void
8897
]
8998
])
9099
);
91-
$client = new ClientExternal();
100+
$mock = new MockHandler([
101+
new ConnectException('simulated error', $request)
102+
]);
103+
$handlerStack = new HandlerStack($mock);
104+
$client = new ClientExternal(['handler' => $handlerStack]);
92105
$client->call($request);
93106
}
94107

0 commit comments

Comments
 (0)