|
12 | 12 | use Laminas\Http\Response;
|
13 | 13 | use Magento\Framework\HTTP\LaminasClient;
|
14 | 14 | use Magento\Framework\HTTP\LaminasClientFactory;
|
| 15 | +use Magento\Framework\Serialize\SerializerInterface; |
15 | 16 | use Magento\NewRelicReporting\Model\Apm\Deployments;
|
16 | 17 | use Magento\NewRelicReporting\Model\Config;
|
17 | 18 | use PHPUnit\Framework\MockObject\MockObject;
|
@@ -45,31 +46,24 @@ class DeploymentsTest extends TestCase
|
45 | 46 | */
|
46 | 47 | protected $loggerMock;
|
47 | 48 |
|
| 49 | + /** |
| 50 | + * @var SerializerInterface|MockObject |
| 51 | + */ |
| 52 | + private $serializerMock; |
| 53 | + |
48 | 54 | protected function setUp(): void
|
49 | 55 | {
|
50 |
| - $this->httpClientFactoryMock = $this->getMockBuilder(LaminasClientFactory::class) |
51 |
| - ->setMethods(['create']) |
52 |
| - ->disableOriginalConstructor() |
53 |
| - ->getMock(); |
54 |
| - |
55 |
| - $this->httpClientMock = $this->getMockBuilder(LaminasClient::class) |
56 |
| - ->setMethods(['send', 'setUri', 'setMethod', 'setHeaders', 'setParameterPost']) |
57 |
| - ->disableOriginalConstructor() |
58 |
| - ->getMock(); |
59 |
| - |
60 |
| - $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) |
61 |
| - ->disableOriginalConstructor() |
62 |
| - ->getMockForAbstractClass(); |
63 |
| - |
64 |
| - $this->configMock = $this->getMockBuilder(Config::class) |
65 |
| - ->setMethods(['getNewRelicApiUrl', 'getNewRelicApiKey', 'getNewRelicAppId']) |
66 |
| - ->disableOriginalConstructor() |
67 |
| - ->getMock(); |
| 56 | + $this->httpClientFactoryMock = $this->createMock(LaminasClientFactory::class); |
| 57 | + $this->httpClientMock = $this->createMock(LaminasClient::class); |
| 58 | + $this->loggerMock = $this->createMock(LoggerInterface::class); |
| 59 | + $this->configMock = $this->createMock(Config::class); |
| 60 | + $this->serializerMock = $this->createMock(SerializerInterface::class); |
68 | 61 |
|
69 | 62 | $this->model = new Deployments(
|
70 | 63 | $this->configMock,
|
71 | 64 | $this->loggerMock,
|
72 |
| - $this->httpClientFactoryMock |
| 65 | + $this->httpClientFactoryMock, |
| 66 | + $this->serializerMock |
73 | 67 | );
|
74 | 68 | }
|
75 | 69 |
|
@@ -97,9 +91,13 @@ public function testSetDeploymentRequestOk()
|
97 | 91 | ->with($data['headers'])
|
98 | 92 | ->willReturnSelf();
|
99 | 93 |
|
100 |
| - $this->httpClientMock->expects($this->once()) |
101 |
| - ->method('setParameterPost') |
| 94 | + $this->serializerMock->expects($this->once()) |
| 95 | + ->method('serialize') |
102 | 96 | ->with($data['params'])
|
| 97 | + ->willReturn(json_encode($data['params'])); |
| 98 | + $this->httpClientMock->expects($this->once()) |
| 99 | + ->method('setRawBody') |
| 100 | + ->with(json_encode($data['params'])) |
103 | 101 | ->willReturnSelf();
|
104 | 102 |
|
105 | 103 | $this->configMock->expects($this->once())
|
@@ -163,9 +161,13 @@ public function testSetDeploymentBadStatus()
|
163 | 161 | ->with($data['headers'])
|
164 | 162 | ->willReturnSelf();
|
165 | 163 |
|
166 |
| - $this->httpClientMock->expects($this->once()) |
167 |
| - ->method('setParameterPost') |
| 164 | + $this->serializerMock->expects($this->once()) |
| 165 | + ->method('serialize') |
168 | 166 | ->with($data['params'])
|
| 167 | + ->willReturn(json_encode($data['params'])); |
| 168 | + $this->httpClientMock->expects($this->once()) |
| 169 | + ->method('setRawBody') |
| 170 | + ->with(json_encode($data['params'])) |
169 | 171 | ->willReturnSelf();
|
170 | 172 |
|
171 | 173 | $this->configMock->expects($this->once())
|
@@ -225,9 +227,13 @@ public function testSetDeploymentRequestFail()
|
225 | 227 | ->with($data['headers'])
|
226 | 228 | ->willReturnSelf();
|
227 | 229 |
|
228 |
| - $this->httpClientMock->expects($this->once()) |
229 |
| - ->method('setParameterPost') |
| 230 | + $this->serializerMock->expects($this->once()) |
| 231 | + ->method('serialize') |
230 | 232 | ->with($data['params'])
|
| 233 | + ->willReturn(json_encode($data['params'])); |
| 234 | + $this->httpClientMock->expects($this->once()) |
| 235 | + ->method('setRawBody') |
| 236 | + ->with(json_encode($data['params'])) |
231 | 237 | ->willReturnSelf();
|
232 | 238 |
|
233 | 239 | $this->configMock->expects($this->once())
|
|
0 commit comments