|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TraderInteractive\NetAcuity\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\ClientInterface; |
|
6
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
|
|
10
|
|
|
abstract class NetAcuityTestSuite extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
protected function getMockGuzzleClient() : ClientInterface |
|
13
|
|
|
{ |
|
14
|
|
|
return $this->getMockBuilder( |
|
15
|
|
|
'\GuzzleHttp\Client' |
|
16
|
|
|
)->disableOriginalConstructor()->setMethods(['send'])->getMock(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
protected function getMockClientException(int $code, string $errorMessage) : ClientException |
|
20
|
|
|
{ |
|
21
|
|
|
$mockStream =$this->getMockBuilder( |
|
22
|
|
|
'\GuzzleHttp\Psr7\Stream' |
|
23
|
|
|
)->disableOriginalConstructor()->setMethods(['getContents'])->getMock(); |
|
24
|
|
|
$mockStream->method( |
|
25
|
|
|
'getContents' |
|
26
|
|
|
)->willReturn(json_encode(['error' => ['message' => $errorMessage]])); |
|
27
|
|
|
|
|
28
|
|
|
$mockResponse = $this->getMockBuilder( |
|
29
|
|
|
'\GuzzleHttp\Psr7\Response' |
|
30
|
|
|
)->disableOriginalConstructor()->setMethods(['getStatusCode', 'getBody'])->getMock(); |
|
31
|
|
|
$mockResponse->method('getStatusCode')->willReturn($code); |
|
32
|
|
|
$mockResponse->method('getBody')->willReturn($mockStream); |
|
33
|
|
|
|
|
34
|
|
|
$mockException = $this->getMockBuilder( |
|
35
|
|
|
'\GuzzleHttp\Exception\ClientException' |
|
36
|
|
|
)->disableOriginalConstructor()->setMethods(['getResponse'])->getMock(); |
|
37
|
|
|
$mockException->method('getResponse')->willReturn($mockResponse); |
|
38
|
|
|
|
|
39
|
|
|
return $mockException; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function getMockResponse(array $response) : ResponseInterface |
|
43
|
|
|
{ |
|
44
|
|
|
$mockStream = $this->getMockBuilder( |
|
45
|
|
|
'\GuzzleHttp\Psr7\Stream' |
|
46
|
|
|
)->disableOriginalConstructor()->setMethods(['getContents'])->getMock(); |
|
47
|
|
|
$mockStream->method('getContents')->willReturn(json_encode(['response' => $response], true)); |
|
48
|
|
|
|
|
49
|
|
|
$mockResponse = $this->getMockBuilder( |
|
50
|
|
|
'\GuzzleHttp\Psr7\Response' |
|
51
|
|
|
)->disableOriginalConstructor()->setMethods(['getBody'])->getMock(); |
|
52
|
|
|
$mockResponse->method('getBody')->willReturn($mockStream); |
|
53
|
|
|
|
|
54
|
|
|
return $mockResponse; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|