File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -532,6 +532,36 @@ public function assertContent($value)
532
532
return $ this ;
533
533
}
534
534
535
+ /**
536
+ * Assert that the response was streamed.
537
+ *
538
+ * @return $this
539
+ */
540
+ public function assertStreamed ()
541
+ {
542
+ PHPUnit::withResponse ($ this )->assertTrue (
543
+ $ this ->baseResponse instanceof StreamedResponse || $ this ->baseResponse instanceof StreamedJsonResponse,
544
+ 'Expected the response to be streamed, but it wasn \'t. '
545
+ );
546
+
547
+ return $ this ;
548
+ }
549
+
550
+ /**
551
+ * Assert that the response was not streamed.
552
+ *
553
+ * @return $this
554
+ */
555
+ public function assertNotStreamed ()
556
+ {
557
+ PHPUnit::withResponse ($ this )->assertTrue (
558
+ ! $ this ->baseResponse instanceof StreamedResponse && ! $ this ->baseResponse instanceof StreamedJsonResponse,
559
+ 'Response was unexpectedly streamed. '
560
+ );
561
+
562
+ return $ this ;
563
+ }
564
+
535
565
/**
536
566
* Assert that the given string matches the streamed response content.
537
567
*
Original file line number Diff line number Diff line change @@ -261,6 +261,39 @@ public function testAssertContent()
261
261
}
262
262
}
263
263
264
+ public function testAssertStreamedAndAssertNotStreamed ()
265
+ {
266
+ $ notStreamedResponse = $ this ->makeMockResponse ([
267
+ 'render ' => 'expected response data ' ,
268
+ ]);
269
+
270
+ $ streamedResponse = TestResponse::fromBaseResponse (
271
+ new StreamedResponse (function () {
272
+ $ stream = fopen ('php://memory ' , 'r+ ' );
273
+ fwrite ($ stream , 'expected response data ' );
274
+ rewind ($ stream );
275
+ fpassthru ($ stream );
276
+ })
277
+ );
278
+
279
+ $ notStreamedResponse ->assertNotStreamed ();
280
+ $ streamedResponse ->assertStreamed ();
281
+
282
+ try {
283
+ $ notStreamedResponse ->assertStreamed ();
284
+ $ this ->fail ('xxxx ' );
285
+ } catch (AssertionFailedError $ e ) {
286
+ $ this ->assertSame ("Expected the response to be streamed, but it wasn't. \nFailed asserting that false is true. " , $ e ->getMessage ());
287
+ }
288
+
289
+ try {
290
+ $ streamedResponse ->assertNotStreamed ();
291
+ $ this ->fail ('xxxx ' );
292
+ } catch (AssertionFailedError $ e ) {
293
+ $ this ->assertSame ("Response was unexpectedly streamed. \nFailed asserting that false is true. " , $ e ->getMessage ());
294
+ }
295
+ }
296
+
264
297
public function testAssertStreamedContent ()
265
298
{
266
299
$ response = TestResponse::fromBaseResponse (
You can’t perform that action at this time.
0 commit comments