File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -572,6 +572,19 @@ public function assertContent($value)
572
572
return $ this ;
573
573
}
574
574
575
+ /**
576
+ * Assert that the given string matches the streamed response content.
577
+ *
578
+ * @param $value
579
+ * @return $this
580
+ */
581
+ public function assertStreamedContent ($ value )
582
+ {
583
+ PHPUnit::assertSame ($ value , $ this ->streamedContent ());
584
+
585
+ return $ this ;
586
+ }
587
+
575
588
/**
576
589
* Assert that the given string or array of strings are contained within the response.
577
590
*
Original file line number Diff line number Diff line change 28
28
use PHPUnit \Framework \TestCase ;
29
29
use Symfony \Component \HttpFoundation \BinaryFileResponse ;
30
30
use Symfony \Component \HttpFoundation \Cookie ;
31
+ use Symfony \Component \HttpFoundation \StreamedResponse ;
31
32
32
33
class TestResponseTest extends TestCase
33
34
{
@@ -234,6 +235,34 @@ public function testAssertContent()
234
235
}
235
236
}
236
237
238
+ public function testAssertStreamedContent ()
239
+ {
240
+ $ response = TestResponse::fromBaseResponse (
241
+ new StreamedResponse (function () {
242
+ $ stream = fopen ('php://memory ' , 'r+ ' );
243
+ fwrite ($ stream , 'expected response data ' );
244
+ rewind ($ stream );
245
+ fpassthru ($ stream );
246
+ })
247
+ );
248
+
249
+ $ response ->assertStreamedContent ('expected response data ' );
250
+
251
+ try {
252
+ $ response ->assertStreamedContent ('expected ' );
253
+ $ this ->fail ('xxxx ' );
254
+ } catch (AssertionFailedError $ e ) {
255
+ $ this ->assertSame ('Failed asserting that two strings are identical. ' , $ e ->getMessage ());
256
+ }
257
+
258
+ try {
259
+ $ response ->assertStreamedContent ('expected response data with extra ' );
260
+ $ this ->fail ('xxxx ' );
261
+ } catch (AssertionFailedError $ e ) {
262
+ $ this ->assertSame ('Failed asserting that two strings are identical. ' , $ e ->getMessage ());
263
+ }
264
+ }
265
+
237
266
public function testAssertSee ()
238
267
{
239
268
$ response = $ this ->makeMockResponse ([
You can’t perform that action at this time.
0 commit comments