1111use Http \HttplugBundle \Collector \Formatter ;
1212use Http \HttplugBundle \Collector \ProfileClient ;
1313use Http \HttplugBundle \Collector \Stack ;
14+ use Http \Message \Formatter as MessageFormatter ;
1415use Http \Promise \FulfilledPromise ;
1516use Http \Promise \Promise ;
1617use Http \Promise \RejectedPromise ;
@@ -91,22 +92,23 @@ class ProfileClientTest extends TestCase
9192
9293 public function setUp (): void
9394 {
94- $ this ->collector = $ this ->getMockBuilder (Collector::class)->disableOriginalConstructor ()->getMock ();
95+ $ messageFormatter = $ this ->createMock (MessageFormatter::class);
96+ $ this ->formatter = new Formatter ($ messageFormatter , $ this ->createMock (MessageFormatter::class));
97+ $ this ->collector = new Collector ();
98+ $ this ->stopwatch = $ this ->createMock (Stopwatch::class);
99+
95100 $ this ->activeStack = new Stack ('default ' , 'FormattedRequest ' );
96101 $ this ->client = $ this ->getMockBuilder (ClientInterface::class)->getMock ();
97102 $ this ->uri = new Uri ('https://example.com/target ' );
98103 $ this ->request = new Request ('GET ' , $ this ->uri );
99- $ this ->formatter = $ this ->getMockBuilder (Formatter::class)->disableOriginalConstructor ()->getMock ();
100- $ this ->stopwatch = $ this ->getMockBuilder (Stopwatch::class)->disableOriginalConstructor ()->getMock ();
101- $ this ->stopwatchEvent = $ this ->getMockBuilder (StopwatchEvent::class)->disableOriginalConstructor ()->getMock ();
104+ $ this ->stopwatchEvent = $ this ->createMock (StopwatchEvent::class);
102105 $ this ->subject = new ProfileClient ($ this ->client , $ this ->collector , $ this ->formatter , $ this ->stopwatch );
103106 $ this ->response = new Response ();
104107 $ this ->exception = new \Exception ();
105108 $ this ->fulfilledPromise = new FulfilledPromise ($ this ->response );
106109 $ this ->rejectedPromise = new RejectedPromise ($ this ->exception );
107110
108- $ this ->collector ->method ('getActiveStack ' )->willReturn ($ this ->activeStack );
109- $ this ->formatter
111+ $ messageFormatter
110112 ->method ('formatResponse ' )
111113 ->with ($ this ->response )
112114 ->willReturn ('FormattedResponse ' )
@@ -170,11 +172,6 @@ public function testSendAsyncRequest(): void
170172 ->willReturn ($ this ->fulfilledPromise )
171173 ;
172174
173- $ this ->collector
174- ->expects ($ this ->once ())
175- ->method ('deactivateStack ' )
176- ;
177-
178175 $ promise = $ this ->subject ->sendAsyncRequest ($ this ->request );
179176
180177 $ this ->assertEquals ($ this ->fulfilledPromise , $ promise );
@@ -186,12 +183,6 @@ public function testSendAsyncRequest(): void
186183
187184 public function testOnFulfilled (): void
188185 {
189- $ this ->collector
190- ->expects ($ this ->once ())
191- ->method ('activateStack ' )
192- ->with ($ this ->activeStack )
193- ;
194-
195186 $ this ->stopwatchEvent
196187 ->expects ($ this ->once ())
197188 ->method ('stop ' )
@@ -211,12 +202,6 @@ public function testOnFulfilled(): void
211202
212203 public function testOnRejected (): void
213204 {
214- $ this ->collector
215- ->expects ($ this ->once ())
216- ->method ('activateStack ' )
217- ->with ($ this ->activeStack )
218- ;
219-
220205 $ this ->stopwatchEvent
221206 ->expects ($ this ->once ())
222207 ->method ('stop ' )
@@ -236,7 +221,7 @@ public function testOnRejected(): void
236221 $ this ->subject ->sendAsyncRequest ($ this ->request );
237222
238223 $ this ->assertEquals (42 , $ this ->activeStack ->getDuration ());
239- $ this ->assertEquals ('FormattedException ' , $ this ->activeStack ->getClientException ());
224+ $ this ->assertEquals ('FormattedResponse ' , $ this ->activeStack ->getClientException ());
240225 }
241226}
242227
0 commit comments