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 ;
@@ -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 ' )
@@ -170,11 +172,6 @@ public function testSendAsyncRequest(): void
170
172
->willReturn ($ this ->fulfilledPromise )
171
173
;
172
174
173
- $ this ->collector
174
- ->expects ($ this ->once ())
175
- ->method ('deactivateStack ' )
176
- ;
177
-
178
175
$ promise = $ this ->subject ->sendAsyncRequest ($ this ->request );
179
176
180
177
$ this ->assertEquals ($ this ->fulfilledPromise , $ promise );
@@ -186,12 +183,6 @@ public function testSendAsyncRequest(): void
186
183
187
184
public function testOnFulfilled (): void
188
185
{
189
- $ this ->collector
190
- ->expects ($ this ->once ())
191
- ->method ('activateStack ' )
192
- ->with ($ this ->activeStack )
193
- ;
194
-
195
186
$ this ->stopwatchEvent
196
187
->expects ($ this ->once ())
197
188
->method ('stop ' )
@@ -211,12 +202,6 @@ public function testOnFulfilled(): void
211
202
212
203
public function testOnRejected (): void
213
204
{
214
- $ this ->collector
215
- ->expects ($ this ->once ())
216
- ->method ('activateStack ' )
217
- ->with ($ this ->activeStack )
218
- ;
219
-
220
205
$ this ->stopwatchEvent
221
206
->expects ($ this ->once ())
222
207
->method ('stop ' )
@@ -236,7 +221,7 @@ public function testOnRejected(): void
236
221
$ this ->subject ->sendAsyncRequest ($ this ->request );
237
222
238
223
$ this ->assertEquals (42 , $ this ->activeStack ->getDuration ());
239
- $ this ->assertEquals ('FormattedException ' , $ this ->activeStack ->getClientException ());
224
+ $ this ->assertEquals ('FormattedResponse ' , $ this ->activeStack ->getClientException ());
240
225
}
241
226
}
242
227
0 commit comments