Skip to content

Commit c703de3

Browse files
authored
add TestResponse::assertContent() (#44580)
1 parent dca2f47 commit c703de3

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
@@ -514,6 +514,19 @@ public function getCookie($cookieName, $decrypt = true, $unserialize = false)
514514
}
515515
}
516516

517+
/**
518+
* Assert that the given string matches the response content.
519+
*
520+
* @param string $value
521+
* @return $this
522+
*/
523+
public function assertContent($value)
524+
{
525+
PHPUnit::assertSame($value, $this->content());
526+
527+
return $this;
528+
}
529+
517530
/**
518531
* Assert that the given string or array of strings are contained within the response.
519532
*

tests/Testing/TestResponseTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,29 @@ public function testAssertViewMissingNested()
211211
$response->assertViewMissing('foo.baz');
212212
}
213213

214+
public function testAssertContent()
215+
{
216+
$response = $this->makeMockResponse([
217+
'render' => 'expected response data',
218+
]);
219+
220+
$response->assertContent('expected response data');
221+
222+
try {
223+
$response->assertContent('expected');
224+
$this->fail('xxxx');
225+
} catch (AssertionFailedError $e) {
226+
$this->assertSame('Failed asserting that two strings are identical.', $e->getMessage());
227+
}
228+
229+
try {
230+
$response->assertContent('expected response data with extra');
231+
$this->fail('xxxx');
232+
} catch (AssertionFailedError $e) {
233+
$this->assertSame('Failed asserting that two strings are identical.', $e->getMessage());
234+
}
235+
}
236+
214237
public function testAssertSee()
215238
{
216239
$response = $this->makeMockResponse([

0 commit comments

Comments
 (0)