Skip to content

Commit 2e2b88e

Browse files
committed
ACP2E-2030: Error while handling header for new relic module
1 parent adc4105 commit 2e2b88e

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

app/code/Magento/NewRelicReporting/Model/Apm/Deployments.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Laminas\Http\Request;
1010
use Magento\Framework\HTTP\LaminasClient;
1111
use Magento\Framework\HTTP\LaminasClientFactory;
12+
use Magento\Framework\Serialize\SerializerInterface;
1213
use Magento\NewRelicReporting\Model\Config;
1314
use Psr\Log\LoggerInterface;
1415

@@ -37,21 +38,29 @@ class Deployments
3738
*/
3839
protected $clientFactory;
3940

41+
/**
42+
* @var SerializerInterface
43+
*/
44+
private $serializer;
45+
4046
/**
4147
* Constructor
4248
*
4349
* @param Config $config
4450
* @param LoggerInterface $logger
4551
* @param LaminasClientFactory $clientFactory
52+
* @param SerializerInterface $serializer
4653
*/
4754
public function __construct(
4855
Config $config,
4956
LoggerInterface $logger,
50-
LaminasClientFactory $clientFactory
57+
LaminasClientFactory $clientFactory,
58+
SerializerInterface $serializer
5159
) {
5260
$this->config = $config;
5361
$this->logger = $logger;
5462
$this->clientFactory = $clientFactory;
63+
$this->serializer = $serializer;
5564
}
5665

5766
/**
@@ -97,8 +106,7 @@ public function setDeployment($description, $change = false, $user = false, $rev
97106
'revision' => $revision
98107
]
99108
];
100-
101-
$client->setParameterPost($params);
109+
$client->setRawBody($this->serializer->serialize($params));
102110

103111
try {
104112
$response = $client->send();

app/code/Magento/NewRelicReporting/Test/Unit/Model/Apm/DeploymentsTest.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Laminas\Http\Response;
1313
use Magento\Framework\HTTP\LaminasClient;
1414
use Magento\Framework\HTTP\LaminasClientFactory;
15+
use Magento\Framework\Serialize\SerializerInterface;
1516
use Magento\NewRelicReporting\Model\Apm\Deployments;
1617
use Magento\NewRelicReporting\Model\Config;
1718
use PHPUnit\Framework\MockObject\MockObject;
@@ -45,31 +46,24 @@ class DeploymentsTest extends TestCase
4546
*/
4647
protected $loggerMock;
4748

49+
/**
50+
* @var SerializerInterface|MockObject
51+
*/
52+
private $serializerMock;
53+
4854
protected function setUp(): void
4955
{
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);
6861

6962
$this->model = new Deployments(
7063
$this->configMock,
7164
$this->loggerMock,
72-
$this->httpClientFactoryMock
65+
$this->httpClientFactoryMock,
66+
$this->serializerMock
7367
);
7468
}
7569

@@ -97,9 +91,13 @@ public function testSetDeploymentRequestOk()
9791
->with($data['headers'])
9892
->willReturnSelf();
9993

100-
$this->httpClientMock->expects($this->once())
101-
->method('setParameterPost')
94+
$this->serializerMock->expects($this->once())
95+
->method('serialize')
10296
->with($data['params'])
97+
->willReturn(json_encode($data['params']));
98+
$this->httpClientMock->expects($this->once())
99+
->method('setRawBody')
100+
->with(json_encode($data['params']))
103101
->willReturnSelf();
104102

105103
$this->configMock->expects($this->once())
@@ -163,9 +161,13 @@ public function testSetDeploymentBadStatus()
163161
->with($data['headers'])
164162
->willReturnSelf();
165163

166-
$this->httpClientMock->expects($this->once())
167-
->method('setParameterPost')
164+
$this->serializerMock->expects($this->once())
165+
->method('serialize')
168166
->with($data['params'])
167+
->willReturn(json_encode($data['params']));
168+
$this->httpClientMock->expects($this->once())
169+
->method('setRawBody')
170+
->with(json_encode($data['params']))
169171
->willReturnSelf();
170172

171173
$this->configMock->expects($this->once())
@@ -225,9 +227,13 @@ public function testSetDeploymentRequestFail()
225227
->with($data['headers'])
226228
->willReturnSelf();
227229

228-
$this->httpClientMock->expects($this->once())
229-
->method('setParameterPost')
230+
$this->serializerMock->expects($this->once())
231+
->method('serialize')
230232
->with($data['params'])
233+
->willReturn(json_encode($data['params']));
234+
$this->httpClientMock->expects($this->once())
235+
->method('setRawBody')
236+
->with(json_encode($data['params']))
231237
->willReturnSelf();
232238

233239
$this->configMock->expects($this->once())

app/code/Magento/NewRelicReporting/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,9 @@
5353
</argument>
5454
</arguments>
5555
</type>
56+
<type name="Magento\NewRelicReporting\Model\Apm\Deployments">
57+
<arguments>
58+
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Json</argument>
59+
</arguments>
60+
</type>
5661
</config>

0 commit comments

Comments
 (0)