@@ -86,28 +86,30 @@ public function requestShouldBindToStreamEventsAndUseconnector()
86
86
$ request ->handleData ("\r\nbody " );
87
87
}
88
88
89
+ /**
90
+ * @test
91
+ */
92
+ public function requestShouldConnectViaTlsIfUrlUsesHttpsScheme ()
93
+ {
94
+ $ requestData = new RequestData ('GET ' , 'https://www.example.com ' );
95
+ $ request = new Request ($ this ->connector , $ requestData );
96
+
97
+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tls://www.example.com:443 ' )->willReturn (new Promise (function () { }));
98
+
99
+ $ request ->end ();
100
+ }
101
+
89
102
/** @test */
90
103
public function requestShouldEmitErrorIfConnectionFails ()
91
104
{
92
105
$ requestData = new RequestData ('GET ' , 'http://www.example.com ' );
93
106
$ request = new Request ($ this ->connector , $ requestData );
94
107
95
- $ this ->rejectedConnectionMock ();
96
-
97
- $ handler = $ this ->createCallableMock ();
98
- $ handler ->expects ($ this ->once ())
99
- ->method ('__invoke ' )
100
- ->with (
101
- $ this ->isInstanceOf ('RuntimeException ' )
102
- );
103
-
104
- $ request ->on ('error ' , $ handler );
108
+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (\React \Promise \reject (new \RuntimeException ()));
105
109
106
- $ handler = $ this ->createCallableMock ();
107
- $ handler ->expects ($ this ->once ())
108
- ->method ('__invoke ' );
110
+ $ request ->on ('error ' , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('RuntimeException ' )));
109
111
110
- $ request ->on ('close ' , $ handler );
112
+ $ request ->on ('close ' , $ this -> expectCallableOnce () );
111
113
$ request ->on ('end ' , $ this ->expectCallableNever ());
112
114
113
115
$ request ->end ();
@@ -121,20 +123,9 @@ public function requestShouldEmitErrorIfConnectionClosesBeforeResponseIsParsed()
121
123
122
124
$ this ->successfulConnectionMock ();
123
125
124
- $ handler = $ this ->createCallableMock ();
125
- $ handler ->expects ($ this ->once ())
126
- ->method ('__invoke ' )
127
- ->with (
128
- $ this ->isInstanceOf ('RuntimeException ' )
129
- );
130
-
131
- $ request ->on ('error ' , $ handler );
132
-
133
- $ handler = $ this ->createCallableMock ();
134
- $ handler ->expects ($ this ->once ())
135
- ->method ('__invoke ' );
126
+ $ request ->on ('error ' , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('RuntimeException ' )));
136
127
137
- $ request ->on ('close ' , $ handler );
128
+ $ request ->on ('close ' , $ this -> expectCallableOnce () );
138
129
$ request ->on ('end ' , $ this ->expectCallableNever ());
139
130
140
131
$ request ->end ();
@@ -149,20 +140,9 @@ public function requestShouldEmitErrorIfConnectionEmitsError()
149
140
150
141
$ this ->successfulConnectionMock ();
151
142
152
- $ handler = $ this ->createCallableMock ();
153
- $ handler ->expects ($ this ->once ())
154
- ->method ('__invoke ' )
155
- ->with (
156
- $ this ->isInstanceOf ('Exception ' )
157
- );
158
-
159
- $ request ->on ('error ' , $ handler );
143
+ $ request ->on ('error ' , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('Exception ' )));
160
144
161
- $ handler = $ this ->createCallableMock ();
162
- $ handler ->expects ($ this ->once ())
163
- ->method ('__invoke ' );
164
-
165
- $ request ->on ('close ' , $ handler );
145
+ $ request ->on ('close ' , $ this ->expectCallableOnce ());
166
146
$ request ->on ('end ' , $ this ->expectCallableNever ());
167
147
168
148
$ request ->end ();
@@ -177,14 +157,7 @@ public function requestShouldEmitErrorIfRequestParserThrowsException()
177
157
178
158
$ this ->successfulConnectionMock ();
179
159
180
- $ handler = $ this ->createCallableMock ();
181
- $ handler ->expects ($ this ->once ())
182
- ->method ('__invoke ' )
183
- ->with (
184
- $ this ->isInstanceOf ('\InvalidArgumentException ' )
185
- );
186
-
187
- $ request ->on ('error ' , $ handler );
160
+ $ request ->on ('error ' , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('InvalidArgumentException ' )));
188
161
189
162
$ request ->end ();
190
163
$ request ->handleData ("\r\n\r\n" );
@@ -198,14 +171,7 @@ public function requestShouldEmitErrorIfUrlIsInvalid()
198
171
$ requestData = new RequestData ('GET ' , 'ftp://www.example.com ' );
199
172
$ request = new Request ($ this ->connector , $ requestData );
200
173
201
- $ handler = $ this ->createCallableMock ();
202
- $ handler ->expects ($ this ->once ())
203
- ->method ('__invoke ' )
204
- ->with (
205
- $ this ->isInstanceOf ('\InvalidArgumentException ' )
206
- );
207
-
208
- $ request ->on ('error ' , $ handler );
174
+ $ request ->on ('error ' , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('InvalidArgumentException ' )));
209
175
210
176
$ this ->connector ->expects ($ this ->never ())
211
177
->method ('connect ' );
@@ -221,14 +187,7 @@ public function requestShouldEmitErrorIfUrlHasNoScheme()
221
187
$ requestData = new RequestData ('GET ' , 'www.example.com ' );
222
188
$ request = new Request ($ this ->connector , $ requestData );
223
189
224
- $ handler = $ this ->createCallableMock ();
225
- $ handler ->expects ($ this ->once ())
226
- ->method ('__invoke ' )
227
- ->with (
228
- $ this ->isInstanceOf ('\InvalidArgumentException ' )
229
- );
230
-
231
- $ request ->on ('error ' , $ handler );
190
+ $ request ->on ('error ' , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('InvalidArgumentException ' )));
232
191
233
192
$ this ->connector ->expects ($ this ->never ())
234
193
->method ('connect ' );
@@ -533,15 +492,6 @@ private function successfulAsyncConnectionMock()
533
492
};
534
493
}
535
494
536
- private function rejectedConnectionMock ()
537
- {
538
- $ this ->connector
539
- ->expects ($ this ->once ())
540
- ->method ('connect ' )
541
- ->with ('www.example.com:80 ' )
542
- ->will ($ this ->returnValue (new RejectedPromise (new \RuntimeException ())));
543
- }
544
-
545
495
/** @test */
546
496
public function multivalueHeader ()
547
497
{
0 commit comments