1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEcoTest\Zed\FirstData\Business; |
9
|
|
|
|
10
|
|
|
use Codeception\Test\Unit; |
|
|
|
|
11
|
|
|
use SprykerEco\Zed\FirstData\Business\FirstDataBusinessFactory; |
12
|
|
|
use SprykerEco\Zed\FirstData\Dependency\External\Guzzle\FirstDataGuzzleHttpClientAdapter; |
13
|
|
|
use SprykerEco\Zed\FirstData\Dependency\External\Guzzle\FirstDataGuzzleHttpClientAdapterInterface; |
14
|
|
|
use SprykerEco\Zed\FirstData\Dependency\External\Guzzle\Response\FirstDataGuzzleResponse; |
15
|
|
|
use SprykerEco\Zed\FirstData\Dependency\External\Guzzle\Response\FirstDataGuzzleResponseInterface; |
16
|
|
|
use SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceBridge; |
17
|
|
|
use SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceInterface; |
18
|
|
|
use SprykerEco\Zed\FirstData\FirstDataConfig; |
19
|
|
|
use SprykerEco\Zed\FirstData\Persistence\FirstDataEntityManager; |
20
|
|
|
use SprykerEco\Zed\FirstData\Persistence\FirstDataPersistenceFactory; |
21
|
|
|
use SprykerEco\Zed\FirstData\Persistence\FirstDataRepository; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Auto-generated group annotations |
25
|
|
|
* |
26
|
|
|
* @group SprykerEcoTest |
27
|
|
|
* @group Zed |
28
|
|
|
* @group FirstData |
29
|
|
|
* @group Business |
30
|
|
|
* @group Facade |
31
|
|
|
* @group AbstractFirstDataFacadeTest |
32
|
|
|
*/ |
33
|
|
|
abstract class AbstractFirstDataFacadeTest extends Unit |
34
|
|
|
{ |
35
|
|
|
protected const CLIENT_TOKEN_HEADER_KEY = 'Client-Token'; |
36
|
|
|
protected const TEST_CLIENT_TOKEN = 'clientToken'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param array $clientResponse |
40
|
|
|
* @param array $clientHeaders |
41
|
|
|
* |
42
|
|
|
* @return \SprykerEco\Zed\FirstData\Business\FirstDataBusinessFactory |
43
|
|
|
*/ |
44
|
|
|
protected function getFirstDataBusinessFactoryMock(array $clientResponse = [], array $clientHeaders = []): FirstDataBusinessFactory |
45
|
|
|
{ |
46
|
|
|
$mockFirstDataBusinessFactory = $this->createPartialMock( |
47
|
|
|
FirstDataBusinessFactory::class, |
48
|
|
|
[ |
49
|
|
|
'createFirstDataGuzzleHttpClientAdapter', |
50
|
|
|
'getUtilEncodingService', |
51
|
|
|
] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$mockFirstDataBusinessFactory->setConfig(new FirstDataConfig()); |
55
|
|
|
$mockFirstDataBusinessFactory->setEntityManager((new FirstDataEntityManager())->setFactory(new FirstDataPersistenceFactory())); |
56
|
|
|
$mockFirstDataBusinessFactory->setRepository((new FirstDataRepository())->setFactory(new FirstDataPersistenceFactory())); |
57
|
|
|
|
58
|
|
|
$mockFirstDataBusinessFactory |
59
|
|
|
->method('createFirstDataGuzzleHttpClientAdapter') |
60
|
|
|
->willReturn($this->getFirstDataGuzzleHttpClientAdapterMock($clientResponse, $clientHeaders)); |
61
|
|
|
$mockFirstDataBusinessFactory |
62
|
|
|
->method('getUtilEncodingService') |
63
|
|
|
->willReturn($this->getUtilEncodingServiceMock($clientResponse)); |
64
|
|
|
|
65
|
|
|
return $mockFirstDataBusinessFactory; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param array $clientResponse |
70
|
|
|
* @param array $clientHeaders |
71
|
|
|
* |
72
|
|
|
* @return \SprykerEco\Zed\FirstData\Dependency\External\Guzzle\FirstDataGuzzleHttpClientAdapterInterface |
73
|
|
|
*/ |
74
|
|
|
protected function getFirstDataGuzzleHttpClientAdapterMock(array $clientResponse, array $clientHeaders): FirstDataGuzzleHttpClientAdapterInterface |
75
|
|
|
{ |
76
|
|
|
$createFirstDataGuzzleHttpClientAdapterMock = $this->createPartialMock( |
77
|
|
|
FirstDataGuzzleHttpClientAdapter::class, |
78
|
|
|
[ |
79
|
|
|
'post', |
80
|
|
|
] |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$createFirstDataGuzzleHttpClientAdapterMock |
84
|
|
|
->method('post') |
85
|
|
|
->willReturn($this->getFirstDataGuzzleResponseMock($clientResponse, $clientHeaders)); |
86
|
|
|
|
87
|
|
|
return $createFirstDataGuzzleHttpClientAdapterMock; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param array $clientResponse |
92
|
|
|
* |
93
|
|
|
* @return \SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceInterface |
94
|
|
|
*/ |
95
|
|
|
protected function getUtilEncodingServiceMock(array $clientResponse): FirstDataToUtilEncodingServiceInterface |
96
|
|
|
{ |
97
|
|
|
$mockUtilEncodingService = $this->createPartialMock( |
98
|
|
|
FirstDataToUtilEncodingServiceBridge::class, |
99
|
|
|
[ |
100
|
|
|
'decodeJson', |
101
|
|
|
'encodeJson', |
102
|
|
|
] |
103
|
|
|
); |
104
|
|
|
$mockUtilEncodingService |
105
|
|
|
->method('decodeJson') |
106
|
|
|
->willReturn($clientResponse); |
107
|
|
|
$mockUtilEncodingService |
108
|
|
|
->method('encodeJson') |
109
|
|
|
->willReturn(json_encode($clientResponse)); |
110
|
|
|
|
111
|
|
|
return $mockUtilEncodingService; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param array $clientResponse |
116
|
|
|
* @param array $clientHeaders |
117
|
|
|
* |
118
|
|
|
* @return \SprykerEco\Zed\FirstData\Dependency\External\Guzzle\Response\FirstDataGuzzleResponseInterface |
119
|
|
|
*/ |
120
|
|
|
protected function getFirstDataGuzzleResponseMock(array $clientResponse, array $clientHeaders): FirstDataGuzzleResponseInterface |
121
|
|
|
{ |
122
|
|
|
$mockFirstDataGuzzleResponse = $this->createPartialMock( |
123
|
|
|
FirstDataGuzzleResponse::class, |
124
|
|
|
[ |
125
|
|
|
'getResponseBody', |
126
|
|
|
'getHeaders', |
127
|
|
|
'getHeader', |
128
|
|
|
] |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$mockFirstDataGuzzleResponse |
132
|
|
|
->method('getResponseBody') |
133
|
|
|
->willReturn(json_encode($clientResponse)); |
134
|
|
|
|
135
|
|
|
$mockFirstDataGuzzleResponse |
136
|
|
|
->method('getHeaders') |
137
|
|
|
->willReturn($clientHeaders); |
138
|
|
|
|
139
|
|
|
$mockFirstDataGuzzleResponse |
140
|
|
|
->method('getHeader') |
141
|
|
|
->willReturnCallback(function (string $header) { |
142
|
|
|
if ($header === static::CLIENT_TOKEN_HEADER_KEY) { |
143
|
|
|
return static::TEST_CLIENT_TOKEN; |
144
|
|
|
} |
145
|
|
|
}); |
146
|
|
|
|
147
|
|
|
return $mockFirstDataGuzzleResponse; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths