13
13
use Http \HttplugBundle \Collector \Formatter ;
14
14
use Http \HttplugBundle \Collector \ProfileClient ;
15
15
use Http \HttplugBundle \Collector \Stack ;
16
+ use Http \Message \Formatter as MessageFormatter ;
16
17
use Http \Promise \FulfilledPromise ;
17
18
use Http \Promise \Promise ;
18
19
use Http \Promise \RejectedPromise ;
@@ -47,7 +48,7 @@ class ProfileClientTest extends TestCase
47
48
private $ request ;
48
49
49
50
/**
50
- * @var Formatter|MockObject
51
+ * @var Formatter
51
52
*/
52
53
private $ formatter ;
53
54
@@ -93,22 +94,23 @@ class ProfileClientTest extends TestCase
93
94
94
95
public function setUp (): void
95
96
{
96
- $ this ->collector = $ this ->getMockBuilder (Collector::class)->disableOriginalConstructor ()->getMock ();
97
+ $ messageFormatter = $ this ->createMock (MessageFormatter::class);
98
+ $ this ->formatter = new Formatter ($ messageFormatter , $ this ->createMock (MessageFormatter::class));
99
+ $ this ->collector = new Collector ();
100
+ $ this ->stopwatch = $ this ->createMock (Stopwatch::class);
101
+
97
102
$ this ->activeStack = new Stack ('default ' , 'FormattedRequest ' );
98
103
$ this ->client = $ this ->getMockBuilder (ClientInterface::class)->getMock ();
99
104
$ this ->uri = new Uri ('https://example.com/target ' );
100
105
$ this ->request = new Request ('GET ' , $ this ->uri );
101
- $ this ->formatter = $ this ->getMockBuilder (Formatter::class)->disableOriginalConstructor ()->getMock ();
102
- $ this ->stopwatch = $ this ->getMockBuilder (Stopwatch::class)->disableOriginalConstructor ()->getMock ();
103
- $ this ->stopwatchEvent = $ this ->getMockBuilder (StopwatchEvent::class)->disableOriginalConstructor ()->getMock ();
106
+ $ this ->stopwatchEvent = $ this ->createMock (StopwatchEvent::class);
104
107
$ this ->subject = new ProfileClient ($ this ->client , $ this ->collector , $ this ->formatter , $ this ->stopwatch );
105
108
$ this ->response = new Response ();
106
109
$ this ->exception = new \Exception ();
107
110
$ this ->fulfilledPromise = new FulfilledPromise ($ this ->response );
108
111
$ this ->rejectedPromise = new RejectedPromise ($ this ->exception );
109
112
110
- $ this ->collector ->method ('getActiveStack ' )->willReturn ($ this ->activeStack );
111
- $ this ->formatter
113
+ $ messageFormatter
112
114
->method ('formatResponse ' )
113
115
->with ($ this ->response )
114
116
->willReturn ('FormattedResponse ' )
@@ -151,10 +153,6 @@ public function testSendRequestTypeError()
151
153
->willReturnCallback (function () {
152
154
throw new \Error ('You set string to int prop ' );
153
155
});
154
- $ this ->formatter
155
- ->expects ($ this ->once ())
156
- ->method ('formatException ' )
157
- ->with ($ this ->isInstanceOf (\Error::class));
158
156
159
157
$ this ->expectException (\Error::class);
160
158
$ this ->expectExceptionMessage ('You set string to int prop ' );
@@ -170,11 +168,6 @@ public function testSendAsyncRequest(): void
170
168
->willReturn ($ this ->fulfilledPromise )
171
169
;
172
170
173
- $ this ->collector
174
- ->expects ($ this ->once ())
175
- ->method ('deactivateStack ' )
176
- ;
177
-
178
171
$ promise = $ this ->subject ->sendAsyncRequest ($ this ->request );
179
172
180
173
$ this ->assertEquals ($ this ->fulfilledPromise , $ promise );
@@ -186,12 +179,6 @@ public function testSendAsyncRequest(): void
186
179
187
180
public function testOnFulfilled (): void
188
181
{
189
- $ this ->collector
190
- ->expects ($ this ->once ())
191
- ->method ('activateStack ' )
192
- ->with ($ this ->activeStack )
193
- ;
194
-
195
182
$ this ->stopwatchEvent
196
183
->expects ($ this ->once ())
197
184
->method ('stop ' )
@@ -211,12 +198,6 @@ public function testOnFulfilled(): void
211
198
212
199
public function testOnRejected (): void
213
200
{
214
- $ this ->collector
215
- ->expects ($ this ->once ())
216
- ->method ('activateStack ' )
217
- ->with ($ this ->activeStack )
218
- ;
219
-
220
201
$ this ->stopwatchEvent
221
202
->expects ($ this ->once ())
222
203
->method ('stop ' )
@@ -227,16 +208,10 @@ public function testOnRejected(): void
227
208
->willReturn ($ this ->rejectedPromise )
228
209
;
229
210
230
- $ this ->formatter
231
- ->method ('formatException ' )
232
- ->with ($ this ->exception )
233
- ->willReturn ('FormattedException ' )
234
- ;
235
-
236
211
$ this ->subject ->sendAsyncRequest ($ this ->request );
237
212
238
213
$ this ->assertEquals (42 , $ this ->activeStack ->getDuration ());
239
- $ this ->assertEquals ('FormattedException ' , $ this ->activeStack ->getClientException ());
214
+ $ this ->assertEquals ('FormattedResponse ' , $ this ->activeStack ->getClientException ());
240
215
}
241
216
}
242
217
0 commit comments