1313use Http \HttplugBundle \Collector \Formatter ;
1414use Http \HttplugBundle \Collector \ProfileClient ;
1515use Http \HttplugBundle \Collector \Stack ;
16+ use Http \Message \Formatter as MessageFormatter ;
1617use Http \Promise \FulfilledPromise ;
1718use Http \Promise \Promise ;
1819use Http \Promise \RejectedPromise ;
@@ -47,7 +48,7 @@ class ProfileClientTest extends TestCase
4748 private $ request ;
4849
4950 /**
50- * @var Formatter|MockObject
51+ * @var Formatter
5152 */
5253 private $ formatter ;
5354
@@ -93,22 +94,23 @@ class ProfileClientTest extends TestCase
9394
9495 public function setUp (): void
9596 {
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+
97102 $ this ->activeStack = new Stack ('default ' , 'FormattedRequest ' );
98103 $ this ->client = $ this ->getMockBuilder (ClientInterface::class)->getMock ();
99104 $ this ->uri = new Uri ('https://example.com/target ' );
100105 $ 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);
104107 $ this ->subject = new ProfileClient ($ this ->client , $ this ->collector , $ this ->formatter , $ this ->stopwatch );
105108 $ this ->response = new Response ();
106109 $ this ->exception = new \Exception ();
107110 $ this ->fulfilledPromise = new FulfilledPromise ($ this ->response );
108111 $ this ->rejectedPromise = new RejectedPromise ($ this ->exception );
109112
110- $ this ->collector ->method ('getActiveStack ' )->willReturn ($ this ->activeStack );
111- $ this ->formatter
113+ $ messageFormatter
112114 ->method ('formatResponse ' )
113115 ->with ($ this ->response )
114116 ->willReturn ('FormattedResponse ' )
@@ -151,10 +153,6 @@ public function testSendRequestTypeError()
151153 ->willReturnCallback (function () {
152154 throw new \Error ('You set string to int prop ' );
153155 });
154- $ this ->formatter
155- ->expects ($ this ->once ())
156- ->method ('formatException ' )
157- ->with ($ this ->isInstanceOf (\Error::class));
158156
159157 $ this ->expectException (\Error::class);
160158 $ this ->expectExceptionMessage ('You set string to int prop ' );
@@ -170,11 +168,6 @@ public function testSendAsyncRequest(): void
170168 ->willReturn ($ this ->fulfilledPromise )
171169 ;
172170
173- $ this ->collector
174- ->expects ($ this ->once ())
175- ->method ('deactivateStack ' )
176- ;
177-
178171 $ promise = $ this ->subject ->sendAsyncRequest ($ this ->request );
179172
180173 $ this ->assertEquals ($ this ->fulfilledPromise , $ promise );
@@ -186,12 +179,6 @@ public function testSendAsyncRequest(): void
186179
187180 public function testOnFulfilled (): void
188181 {
189- $ this ->collector
190- ->expects ($ this ->once ())
191- ->method ('activateStack ' )
192- ->with ($ this ->activeStack )
193- ;
194-
195182 $ this ->stopwatchEvent
196183 ->expects ($ this ->once ())
197184 ->method ('stop ' )
@@ -211,12 +198,6 @@ public function testOnFulfilled(): void
211198
212199 public function testOnRejected (): void
213200 {
214- $ this ->collector
215- ->expects ($ this ->once ())
216- ->method ('activateStack ' )
217- ->with ($ this ->activeStack )
218- ;
219-
220201 $ this ->stopwatchEvent
221202 ->expects ($ this ->once ())
222203 ->method ('stop ' )
@@ -227,16 +208,10 @@ public function testOnRejected(): void
227208 ->willReturn ($ this ->rejectedPromise )
228209 ;
229210
230- $ this ->formatter
231- ->method ('formatException ' )
232- ->with ($ this ->exception )
233- ->willReturn ('FormattedException ' )
234- ;
235-
236211 $ this ->subject ->sendAsyncRequest ($ this ->request );
237212
238213 $ this ->assertEquals (42 , $ this ->activeStack ->getDuration ());
239- $ this ->assertEquals ('FormattedException ' , $ this ->activeStack ->getClientException ());
214+ $ this ->assertEquals ('FormattedResponse ' , $ this ->activeStack ->getClientException ());
240215 }
241216}
242217
0 commit comments