|
11 | 11 |
|
12 | 12 | namespace TransactPro\Gateway; |
13 | 13 |
|
14 | | -use PHPUnit\Framework\MockObject\MockObject; |
15 | 14 | use PHPUnit\Framework\TestCase; |
16 | 15 | use TransactPro\Gateway\DataSets\Auth; |
17 | 16 | use TransactPro\Gateway\Exceptions\GatewayException; |
@@ -46,63 +45,21 @@ class GatewayTest extends TestCase |
46 | 45 | public function testGateway(): void |
47 | 46 | { |
48 | 47 | $gw = new Gateway(); |
49 | | - $csvResponseMock = $this->createMock(CsvResponse::class); |
50 | | - |
51 | | - /** @var HttpClientInterface|MockObject $httpClientStub */ |
52 | | - $httpClientStub = $this->createMock(HttpClientInterface::class); |
53 | | - $httpClientStub->method('request')->willReturn(new class($csvResponseMock) implements ResponseInterface { |
54 | | - private $csvResponseMock; |
55 | | - |
56 | | - public function __construct($csvResponseMock) |
57 | | - { |
58 | | - $this->csvResponseMock = $csvResponseMock; |
59 | | - } |
60 | | - |
61 | | - public function getStatusCode(): int |
62 | | - { |
63 | | - return 200; |
64 | | - } |
65 | | - |
66 | | - public function setHeader(string $header, string $value): ResponseInterface |
67 | | - { |
68 | | - return $this; |
69 | | - } |
70 | | - |
71 | | - public function getHeaders(): array |
72 | | - { |
73 | | - return []; |
74 | | - } |
75 | | - |
76 | | - public function getHeader(string $header): string |
77 | | - { |
78 | | - return 'aaa'; |
79 | | - } |
80 | | - |
81 | | - public function getBody(): string |
82 | | - { |
83 | | - return 'holy moly'; |
84 | | - } |
85 | | - |
86 | | - public function isSuccessful(): bool |
87 | | - { |
88 | | - return true; |
89 | | - } |
90 | | - |
91 | | - public function getDigest() |
92 | | - { |
93 | | - return null; |
94 | | - } |
95 | | - |
96 | | - public function parseJSON(string $targetClass) |
97 | | - { |
98 | | - return null; |
99 | | - } |
100 | | - |
101 | | - public function parseCsv(): CsvResponse |
102 | | - { |
103 | | - return $this->csvResponseMock; |
104 | | - } |
105 | | - }); |
| 48 | + $csvResponseStub = $this->createStub(CsvResponse::class); |
| 49 | + |
| 50 | + $responseStub = $this->createStub(ResponseInterface::class); |
| 51 | + $responseStub->method('getStatusCode')->willReturn(200); |
| 52 | + $responseStub->method('setHeader')->willReturnSelf(); |
| 53 | + $responseStub->method('getHeaders')->willReturn([]); |
| 54 | + $responseStub->method('getHeader')->willReturn('aaa'); |
| 55 | + $responseStub->method('getBody')->willReturn('holy moly'); |
| 56 | + $responseStub->method('isSuccessful')->willReturn(true); |
| 57 | + $responseStub->method('getDigest')->willReturn(null); |
| 58 | + $responseStub->method('parseJSON')->willReturn(null); |
| 59 | + $responseStub->method('parseCsv')->willReturn($csvResponseStub); |
| 60 | + |
| 61 | + $httpClientStub = $this->createStub(HttpClientInterface::class); |
| 62 | + $httpClientStub->method('request')->willReturn($responseStub); |
106 | 63 |
|
107 | 64 | $gw->setHttpClient($httpClientStub); |
108 | 65 |
|
|
0 commit comments