11
11
use Http \HttplugBundle \Collector \Formatter ;
12
12
use Http \HttplugBundle \Collector \ProfileClient ;
13
13
use Http \HttplugBundle \Collector \Stack ;
14
+ use Http \Message \Formatter as MessageFormatter ;
14
15
use Http \Promise \FulfilledPromise ;
15
16
use Http \Promise \Promise ;
16
17
use Http \Promise \RejectedPromise ;
@@ -90,31 +91,27 @@ class ProfileClientTest extends TestCase
90
91
91
92
public function setUp ()
92
93
{
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
+
94
99
$ this ->activeStack = new Stack ('default ' , 'FormattedRequest ' );
95
100
$ this ->client = $ this ->getMockBuilder (ClientInterface::class)->getMock ();
96
101
$ this ->uri = new Uri ('https://example.com/target ' );
97
102
$ 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);
101
104
$ this ->subject = new ProfileClient ($ this ->client , $ this ->collector , $ this ->formatter , $ this ->stopwatch );
102
105
$ this ->response = new Response ();
103
106
$ this ->exception = new \Exception ();
104
107
$ this ->fulfilledPromise = new FulfilledPromise ($ this ->response );
105
108
$ this ->rejectedPromise = new RejectedPromise ($ this ->exception );
106
109
107
- $ this ->collector ->method ('getActiveStack ' )->willReturn ($ this ->activeStack );
108
- $ this ->formatter
110
+ $ messageFormatter
109
111
->method ('formatResponse ' )
110
112
->with ($ this ->response )
111
113
->willReturn ('FormattedResponse ' )
112
114
;
113
- $ this ->formatter
114
- ->method ('formatException ' )
115
- ->with ($ this ->exception )
116
- ->willReturn ('FormattedException ' )
117
- ;
118
115
119
116
$ this ->stopwatch
120
117
->method ('start ' )
@@ -154,11 +151,6 @@ public function testSendAsyncRequest()
154
151
->willReturn ($ this ->fulfilledPromise )
155
152
;
156
153
157
- $ this ->collector
158
- ->expects ($ this ->once ())
159
- ->method ('deactivateStack ' )
160
- ;
161
-
162
154
$ promise = $ this ->subject ->sendAsyncRequest ($ this ->request );
163
155
164
156
$ this ->assertEquals ($ this ->fulfilledPromise , $ promise );
@@ -170,12 +162,6 @@ public function testSendAsyncRequest()
170
162
171
163
public function testOnFulfilled ()
172
164
{
173
- $ this ->collector
174
- ->expects ($ this ->once ())
175
- ->method ('activateStack ' )
176
- ->with ($ this ->activeStack )
177
- ;
178
-
179
165
$ this ->stopwatchEvent
180
166
->expects ($ this ->once ())
181
167
->method ('stop ' )
@@ -195,12 +181,6 @@ public function testOnFulfilled()
195
181
196
182
public function testOnRejected ()
197
183
{
198
- $ this ->collector
199
- ->expects ($ this ->once ())
200
- ->method ('activateStack ' )
201
- ->with ($ this ->activeStack )
202
- ;
203
-
204
184
$ this ->stopwatchEvent
205
185
->expects ($ this ->once ())
206
186
->method ('stop ' )
@@ -214,7 +194,7 @@ public function testOnRejected()
214
194
$ this ->subject ->sendAsyncRequest ($ this ->request );
215
195
216
196
$ this ->assertEquals (42 , $ this ->activeStack ->getDuration ());
217
- $ this ->assertEquals ('FormattedException ' , $ this ->activeStack ->getClientException ());
197
+ $ this ->assertEquals ('FormattedResponse ' , $ this ->activeStack ->getClientException ());
218
198
}
219
199
}
220
200
0 commit comments