Skip to content

Commit 373fe08

Browse files
authored
assert streamed content (#45288)
1 parent ff7c673 commit 373fe08

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,19 @@ public function assertContent($value)
572572
return $this;
573573
}
574574

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+
575588
/**
576589
* Assert that the given string or array of strings are contained within the response.
577590
*

tests/Testing/TestResponseTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,29 @@ public function testAssertContent()
234234
}
235235
}
236236

237+
public function testAssertStreamedContent()
238+
{
239+
$response = TestResponse::fromBaseResponse(
240+
(new StreamedResponse)->setContent('expected response data')
241+
);
242+
243+
$this->assertStreamedContent('expected response data');
244+
245+
try {
246+
$response->assertStreamedContent('expected');
247+
$this->fail('xxxx');
248+
} catch (AssertionFailedError $e) {
249+
$this->assertSame('Failed asserting that two strings are identical.', $e->getMessage());
250+
}
251+
252+
try {
253+
$response->assertStreamedContent('expected response data with extra');
254+
$this->fail('xxxx');
255+
} catch (AssertionFailedError $e) {
256+
$this->assertSame('Failed asserting that two strings are identical.', $e->getMessage());
257+
}
258+
}
259+
237260
public function testAssertSee()
238261
{
239262
$response = $this->makeMockResponse([

0 commit comments

Comments
 (0)