37
37
use Psr \Http \Message \ResponseInterface ;
38
38
use RuntimeException ;
39
39
use Symfony \Component \VarDumper \VarDumper ;
40
+ use Throwable ;
40
41
41
42
class HttpClientTest extends TestCase
42
43
{
@@ -2200,30 +2201,60 @@ public function testFakeConnectionException()
2200
2201
{
2201
2202
$ this ->factory ->fake ($ this ->factory ->failedConnection ('Fake ' ));
2202
2203
2203
- $ this ->expectException (ConnectionException::class);
2204
- $ this ->expectExceptionMessage ('Fake ' );
2204
+ $ exception = null ;
2205
+
2206
+ try {
2207
+ $ this ->factory ->post ('https://example.com ' );
2208
+ } catch (Throwable $ e ) {
2209
+ $ exception = $ e ;
2210
+ }
2211
+
2212
+ $ this ->assertNotNull ($ exception );
2213
+ $ this ->assertInstanceOf (ConnectionException::class, $ exception );
2214
+ $ this ->assertSame ('Fake ' , $ exception ->getMessage ());
2205
2215
2206
- $ this ->factory ->post ('https://example.com ' );
2216
+ $ this ->factory ->assertSentCount (1 );
2217
+ $ this ->factory ->assertSent (function (Request $ request , ?Response $ response ) {
2218
+ return $ request ->url () === 'https://example.com ' && $ response === null ;
2219
+ });
2207
2220
}
2208
2221
2209
2222
public function testFakeConnectionExceptionWithinFakeClosure ()
2210
2223
{
2211
2224
$ this ->factory ->fake (fn () => $ this ->factory ->failedConnection ('Fake ' ));
2212
2225
2213
- $ this ->expectException (ConnectionException::class);
2214
- $ this ->expectExceptionMessage ('Fake ' );
2226
+ $ exception = null ;
2227
+
2228
+ try {
2229
+ $ this ->factory ->post ('https://example.com ' );
2230
+ } catch (Throwable $ e ) {
2231
+ $ exception = $ e ;
2232
+ }
2215
2233
2216
- $ this ->factory ->post ('https://example.com ' );
2234
+ $ this ->assertNotNull ($ exception );
2235
+ $ this ->assertInstanceOf (ConnectionException::class, $ exception );
2236
+ $ this ->assertSame ('Fake ' , $ exception ->getMessage ());
2237
+
2238
+ $ this ->factory ->assertSentCount (1 );
2217
2239
}
2218
2240
2219
2241
public function testFakeConnectionExceptionWithinArray ()
2220
2242
{
2221
2243
$ this ->factory ->fake (['* ' => $ this ->factory ->failedConnection ('Fake ' )]);
2222
2244
2223
- $ this ->expectException (ConnectionException::class);
2224
- $ this ->expectExceptionMessage ('Fake ' );
2245
+ $ exception = null ;
2246
+
2247
+ try {
2248
+ $ this ->factory ->post ('https://example.com ' );
2249
+ } catch (Throwable $ e ) {
2250
+ $ exception = $ e ;
2251
+ }
2252
+
2253
+ $ this ->assertNotNull ($ exception );
2254
+ $ this ->assertInstanceOf (ConnectionException::class, $ exception );
2255
+ $ this ->assertSame ('Fake ' , $ exception ->getMessage ());
2225
2256
2226
- $ this ->factory ->post ( ' https://example.com ' );
2257
+ $ this ->factory ->assertSentCount ( 1 );
2227
2258
}
2228
2259
2229
2260
public function testFakeConnectionExceptionWithinSequence ()
@@ -2247,6 +2278,8 @@ public function testFakeConnectionExceptionWithinSequence()
2247
2278
$ this ->assertNotNull ($ exception );
2248
2279
$ this ->assertInstanceOf (ConnectionException::class, $ exception );
2249
2280
$ this ->assertSame ('Fake ' , $ exception ->getMessage ());
2281
+
2282
+ $ this ->factory ->assertSentCount (2 );
2250
2283
}
2251
2284
2252
2285
public function testMiddlewareRunsWhenFaked ()
0 commit comments