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 ;
@@ -90,31 +91,27 @@ class ProfileClientTest extends TestCase
9091
9192 public function setUp ()
9293 {
93- $ this ->collector = $ this ->getMockBuilder (Collector::class)->disableOriginalConstructor ()->getMock ();
94+ $ messageFormatter = $ this ->createMock (MessageFormatter::class);
95+ $ this ->formatter = new Formatter ($ messageFormatter , $ this ->createMock (MessageFormatter::class));
96+ $ this ->collector = new Collector ();
97+ $ this ->stopwatch = $ this ->createMock (Stopwatch::class);
98+
9499 $ this ->activeStack = new Stack ('default ' , 'FormattedRequest ' );
95100 $ this ->client = $ this ->getMockBuilder (ClientInterface::class)->getMock ();
96101 $ this ->uri = new Uri ('https://example.com/target ' );
97102 $ this ->request = new Request ('GET ' , $ this ->uri );
98- $ this ->formatter = $ this ->getMockBuilder (Formatter::class)->disableOriginalConstructor ()->getMock ();
99- $ this ->stopwatch = $ this ->getMockBuilder (Stopwatch::class)->disableOriginalConstructor ()->getMock ();
100- $ this ->stopwatchEvent = $ this ->getMockBuilder (StopwatchEvent::class)->disableOriginalConstructor ()->getMock ();
103+ $ this ->stopwatchEvent = $ this ->createMock (StopwatchEvent::class);
101104 $ this ->subject = new ProfileClient ($ this ->client , $ this ->collector , $ this ->formatter , $ this ->stopwatch );
102105 $ this ->response = new Response ();
103106 $ this ->exception = new \Exception ();
104107 $ this ->fulfilledPromise = new FulfilledPromise ($ this ->response );
105108 $ this ->rejectedPromise = new RejectedPromise ($ this ->exception );
106109
107- $ this ->collector ->method ('getActiveStack ' )->willReturn ($ this ->activeStack );
108- $ this ->formatter
110+ $ messageFormatter
109111 ->method ('formatResponse ' )
110112 ->with ($ this ->response )
111113 ->willReturn ('FormattedResponse ' )
112114 ;
113- $ this ->formatter
114- ->method ('formatException ' )
115- ->with ($ this ->exception )
116- ->willReturn ('FormattedException ' )
117- ;
118115
119116 $ this ->stopwatch
120117 ->method ('start ' )
@@ -154,11 +151,6 @@ public function testSendAsyncRequest()
154151 ->willReturn ($ this ->fulfilledPromise )
155152 ;
156153
157- $ this ->collector
158- ->expects ($ this ->once ())
159- ->method ('deactivateStack ' )
160- ;
161-
162154 $ promise = $ this ->subject ->sendAsyncRequest ($ this ->request );
163155
164156 $ this ->assertEquals ($ this ->fulfilledPromise , $ promise );
@@ -170,12 +162,6 @@ public function testSendAsyncRequest()
170162
171163 public function testOnFulfilled ()
172164 {
173- $ this ->collector
174- ->expects ($ this ->once ())
175- ->method ('activateStack ' )
176- ->with ($ this ->activeStack )
177- ;
178-
179165 $ this ->stopwatchEvent
180166 ->expects ($ this ->once ())
181167 ->method ('stop ' )
@@ -195,12 +181,6 @@ public function testOnFulfilled()
195181
196182 public function testOnRejected ()
197183 {
198- $ this ->collector
199- ->expects ($ this ->once ())
200- ->method ('activateStack ' )
201- ->with ($ this ->activeStack )
202- ;
203-
204184 $ this ->stopwatchEvent
205185 ->expects ($ this ->once ())
206186 ->method ('stop ' )
@@ -214,7 +194,7 @@ public function testOnRejected()
214194 $ this ->subject ->sendAsyncRequest ($ this ->request );
215195
216196 $ this ->assertEquals (42 , $ this ->activeStack ->getDuration ());
217- $ this ->assertEquals ('FormattedException ' , $ this ->activeStack ->getClientException ());
197+ $ this ->assertEquals ('FormattedResponse ' , $ this ->activeStack ->getClientException ());
218198 }
219199}
220200
0 commit comments