8
8
use Magento \Analytics \Model \Connector \Http \ConverterInterface ;
9
9
use Magento \Analytics \Model \Connector \Http \JsonConverter ;
10
10
use Magento \Framework \HTTP \Adapter \CurlFactory ;
11
+ use Magento \Framework \HTTP \ResponseFactory ;
11
12
12
13
/**
13
14
* A unit test for testing of the CURL HTTP client.
@@ -17,25 +18,20 @@ class CurlTest extends \PHPUnit\Framework\TestCase
17
18
/**
18
19
* @var \Magento\Analytics\Model\Connector\Http\Client\Curl
19
20
*/
20
- private $ subject ;
21
+ private $ curl ;
21
22
22
23
/**
23
24
* @var \Magento\Framework\HTTP\Adapter\Curl|\PHPUnit_Framework_MockObject_MockObject
24
25
*/
25
- private $ curlMock ;
26
+ private $ curlAdapterMock ;
26
27
27
28
/**
28
29
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
29
30
*/
30
31
private $ loggerMock ;
31
32
32
33
/**
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
39
35
*/
40
36
private $ responseFactoryMock ;
41
37
@@ -44,17 +40,12 @@ class CurlTest extends \PHPUnit\Framework\TestCase
44
40
*/
45
41
private $ converterMock ;
46
42
47
- /**
48
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
49
- */
50
- private $ objectManagerHelper ;
51
-
52
43
/**
53
44
* @return void
54
45
*/
55
46
protected function setUp ()
56
47
{
57
- $ this ->curlMock = $ this ->getMockBuilder (
48
+ $ this ->curlAdapterMock = $ this ->getMockBuilder (
58
49
\Magento \Framework \HTTP \Adapter \Curl::class
59
50
)
60
51
->disableOriginalConstructor ()
@@ -65,28 +56,27 @@ protected function setUp()
65
56
)
66
57
->disableOriginalConstructor ()
67
58
->getMock ();
68
- $ this -> curlFactoryMock = $ this ->getMockBuilder (CurlFactory::class)
59
+ $ curlFactoryMock = $ this ->getMockBuilder (CurlFactory::class)
69
60
->setMethods (['create ' ])
70
61
->disableOriginalConstructor ()
71
62
->getMock ();
72
- $ this -> curlFactoryMock ->expects ($ this ->any ())
63
+ $ curlFactoryMock ->expects ($ this ->any ())
73
64
->method ('create ' )
74
- ->willReturn ($ this ->curlMock );
65
+ ->willReturn ($ this ->curlAdapterMock );
75
66
76
67
$ this ->responseFactoryMock = $ this ->getMockBuilder (
77
- \ Magento \ Framework \ HTTP \ ResponseFactory::class
68
+ ResponseFactory::class
78
69
)
79
70
->disableOriginalConstructor ()
80
71
->getMock ();
81
72
$ this ->converterMock = $ this ->createJsonConverter ();
82
73
83
- $ this ->objectManagerHelper =
84
- new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
74
+ $ objectManagerHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
85
75
86
- $ this ->subject = $ this -> objectManagerHelper ->getObject (
76
+ $ this ->curl = $ objectManagerHelper ->getObject (
87
77
\Magento \Analytics \Model \Connector \Http \Client \Curl::class,
88
78
[
89
- 'curlFactory ' => $ this -> curlFactoryMock ,
79
+ 'curlFactory ' => $ curlFactoryMock ,
90
80
'responseFactory ' => $ this ->responseFactoryMock ,
91
81
'converter ' => $ this ->converterMock ,
92
82
'logger ' => $ this ->loggerMock ,
@@ -122,7 +112,7 @@ public function testRequestSuccess(array $data)
122
112
{
123
113
$ responseString = 'This is response. ' ;
124
114
$ response = new \Zend_Http_Response (201 , [], $ responseString );
125
- $ this ->curlMock ->expects ($ this ->once ())
115
+ $ this ->curlAdapterMock ->expects ($ this ->once ())
126
116
->method ('write ' )
127
117
->with (
128
118
$ data ['method ' ],
@@ -131,10 +121,10 @@ public function testRequestSuccess(array $data)
131
121
$ data ['headers ' ],
132
122
json_encode ($ data ['body ' ])
133
123
);
134
- $ this ->curlMock ->expects ($ this ->once ())
124
+ $ this ->curlAdapterMock ->expects ($ this ->once ())
135
125
->method ('read ' )
136
126
->willReturn ($ responseString );
137
- $ this ->curlMock ->expects ($ this ->any ())
127
+ $ this ->curlAdapterMock ->expects ($ this ->any ())
138
128
->method ('getErrno ' )
139
129
->willReturn (0 );
140
130
@@ -145,7 +135,7 @@ public function testRequestSuccess(array $data)
145
135
146
136
$ this ->assertEquals (
147
137
$ response ,
148
- $ this ->subject ->request (
138
+ $ this ->curl ->request (
149
139
$ data ['method ' ],
150
140
$ data ['url ' ],
151
141
$ data ['body ' ],
@@ -162,7 +152,7 @@ public function testRequestSuccess(array $data)
162
152
public function testRequestError (array $ data )
163
153
{
164
154
$ response = new \Zend_Http_Response (0 , []);
165
- $ this ->curlMock ->expects ($ this ->once ())
155
+ $ this ->curlAdapterMock ->expects ($ this ->once ())
166
156
->method ('write ' )
167
157
->with (
168
158
$ data ['method ' ],
@@ -171,12 +161,12 @@ public function testRequestError(array $data)
171
161
$ data ['headers ' ],
172
162
json_encode ($ data ['body ' ])
173
163
);
174
- $ this ->curlMock ->expects ($ this ->once ())
164
+ $ this ->curlAdapterMock ->expects ($ this ->once ())
175
165
->method ('read ' );
176
- $ this ->curlMock ->expects ($ this ->atLeastOnce ())
166
+ $ this ->curlAdapterMock ->expects ($ this ->atLeastOnce ())
177
167
->method ('getErrno ' )
178
168
->willReturn (1 );
179
- $ this ->curlMock ->expects ($ this ->atLeastOnce ())
169
+ $ this ->curlAdapterMock ->expects ($ this ->atLeastOnce ())
180
170
->method ('getError ' )
181
171
->willReturn ('CURL error. ' );
182
172
@@ -190,7 +180,7 @@ public function testRequestError(array $data)
190
180
191
181
$ this ->assertEquals (
192
182
$ response ,
193
- $ this ->subject ->request (
183
+ $ this ->curl ->request (
194
184
$ data ['method ' ],
195
185
$ data ['url ' ],
196
186
$ data ['body ' ],
0 commit comments