Skip to content

Commit 2b83edd

Browse files
author
Joan He
committed
MAGETWO-85060: Move code from 2.2.2 to develop
- fix static test failure
1 parent 7bee28f commit 2b83edd

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/Client/CurlTest.php

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Analytics\Model\Connector\Http\ConverterInterface;
99
use Magento\Analytics\Model\Connector\Http\JsonConverter;
1010
use Magento\Framework\HTTP\Adapter\CurlFactory;
11+
use Magento\Framework\HTTP\ResponseFactory;
1112

1213
/**
1314
* A unit test for testing of the CURL HTTP client.
@@ -17,25 +18,20 @@ class CurlTest extends \PHPUnit\Framework\TestCase
1718
/**
1819
* @var \Magento\Analytics\Model\Connector\Http\Client\Curl
1920
*/
20-
private $subject;
21+
private $curl;
2122

2223
/**
2324
* @var \Magento\Framework\HTTP\Adapter\Curl|\PHPUnit_Framework_MockObject_MockObject
2425
*/
25-
private $curlMock;
26+
private $curlAdapterMock;
2627

2728
/**
2829
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
2930
*/
3031
private $loggerMock;
3132

3233
/**
33-
* @var CurlFactory|\PHPUnit_Framework_MockObject_MockObject
34-
*/
35-
private $curlFactoryMock;
36-
37-
/**
38-
* @var \Magento\Analytics\Model\Connector\Http\ResponseFactory|\PHPUnit_Framework_MockObject_MockObject
34+
* @var ResponseFactory|\PHPUnit_Framework_MockObject_MockObject
3935
*/
4036
private $responseFactoryMock;
4137

@@ -44,17 +40,12 @@ class CurlTest extends \PHPUnit\Framework\TestCase
4440
*/
4541
private $converterMock;
4642

47-
/**
48-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
49-
*/
50-
private $objectManagerHelper;
51-
5243
/**
5344
* @return void
5445
*/
5546
protected function setUp()
5647
{
57-
$this->curlMock = $this->getMockBuilder(
48+
$this->curlAdapterMock = $this->getMockBuilder(
5849
\Magento\Framework\HTTP\Adapter\Curl::class
5950
)
6051
->disableOriginalConstructor()
@@ -65,28 +56,27 @@ protected function setUp()
6556
)
6657
->disableOriginalConstructor()
6758
->getMock();
68-
$this->curlFactoryMock = $this->getMockBuilder(CurlFactory::class)
59+
$curlFactoryMock = $this->getMockBuilder(CurlFactory::class)
6960
->setMethods(['create'])
7061
->disableOriginalConstructor()
7162
->getMock();
72-
$this->curlFactoryMock->expects($this->any())
63+
$curlFactoryMock->expects($this->any())
7364
->method('create')
74-
->willReturn($this->curlMock);
65+
->willReturn($this->curlAdapterMock);
7566

7667
$this->responseFactoryMock = $this->getMockBuilder(
77-
\Magento\Framework\HTTP\ResponseFactory::class
68+
ResponseFactory::class
7869
)
7970
->disableOriginalConstructor()
8071
->getMock();
8172
$this->converterMock = $this->createJsonConverter();
8273

83-
$this->objectManagerHelper =
84-
new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
74+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
8575

86-
$this->subject = $this->objectManagerHelper->getObject(
76+
$this->curl = $objectManagerHelper->getObject(
8777
\Magento\Analytics\Model\Connector\Http\Client\Curl::class,
8878
[
89-
'curlFactory' => $this->curlFactoryMock,
79+
'curlFactory' => $curlFactoryMock,
9080
'responseFactory' => $this->responseFactoryMock,
9181
'converter' => $this->converterMock,
9282
'logger' => $this->loggerMock,
@@ -122,7 +112,7 @@ public function testRequestSuccess(array $data)
122112
{
123113
$responseString = 'This is response.';
124114
$response = new \Zend_Http_Response(201, [], $responseString);
125-
$this->curlMock->expects($this->once())
115+
$this->curlAdapterMock->expects($this->once())
126116
->method('write')
127117
->with(
128118
$data['method'],
@@ -131,10 +121,10 @@ public function testRequestSuccess(array $data)
131121
$data['headers'],
132122
json_encode($data['body'])
133123
);
134-
$this->curlMock->expects($this->once())
124+
$this->curlAdapterMock->expects($this->once())
135125
->method('read')
136126
->willReturn($responseString);
137-
$this->curlMock->expects($this->any())
127+
$this->curlAdapterMock->expects($this->any())
138128
->method('getErrno')
139129
->willReturn(0);
140130

@@ -145,7 +135,7 @@ public function testRequestSuccess(array $data)
145135

146136
$this->assertEquals(
147137
$response,
148-
$this->subject->request(
138+
$this->curl->request(
149139
$data['method'],
150140
$data['url'],
151141
$data['body'],
@@ -162,7 +152,7 @@ public function testRequestSuccess(array $data)
162152
public function testRequestError(array $data)
163153
{
164154
$response = new \Zend_Http_Response(0, []);
165-
$this->curlMock->expects($this->once())
155+
$this->curlAdapterMock->expects($this->once())
166156
->method('write')
167157
->with(
168158
$data['method'],
@@ -171,12 +161,12 @@ public function testRequestError(array $data)
171161
$data['headers'],
172162
json_encode($data['body'])
173163
);
174-
$this->curlMock->expects($this->once())
164+
$this->curlAdapterMock->expects($this->once())
175165
->method('read');
176-
$this->curlMock->expects($this->atLeastOnce())
166+
$this->curlAdapterMock->expects($this->atLeastOnce())
177167
->method('getErrno')
178168
->willReturn(1);
179-
$this->curlMock->expects($this->atLeastOnce())
169+
$this->curlAdapterMock->expects($this->atLeastOnce())
180170
->method('getError')
181171
->willReturn('CURL error.');
182172

@@ -190,7 +180,7 @@ public function testRequestError(array $data)
190180

191181
$this->assertEquals(
192182
$response,
193-
$this->subject->request(
183+
$this->curl->request(
194184
$data['method'],
195185
$data['url'],
196186
$data['body'],

app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/JsonConverterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function convertBodyDataProvider()
6565

6666
public function testConvertData()
6767
{
68-
$data = ["token" => "secret-token"];
6968
$this->serializerMock->expects($this->once())
7069
->method('serialize')
7170
->willReturn('serializedResult');

0 commit comments

Comments
 (0)