Skip to content

Commit

Permalink
add TestResponse::assertContent() (#44580)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald authored Oct 14, 2022
1 parent dca2f47 commit c703de3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,19 @@ public function getCookie($cookieName, $decrypt = true, $unserialize = false)
}
}

/**
* Assert that the given string matches the response content.
*
* @param string $value
* @return $this
*/
public function assertContent($value)
{
PHPUnit::assertSame($value, $this->content());

return $this;
}

/**
* Assert that the given string or array of strings are contained within the response.
*
Expand Down
23 changes: 23 additions & 0 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,29 @@ public function testAssertViewMissingNested()
$response->assertViewMissing('foo.baz');
}

public function testAssertContent()
{
$response = $this->makeMockResponse([
'render' => 'expected response data',
]);

$response->assertContent('expected response data');

try {
$response->assertContent('expected');
$this->fail('xxxx');
} catch (AssertionFailedError $e) {
$this->assertSame('Failed asserting that two strings are identical.', $e->getMessage());
}

try {
$response->assertContent('expected response data with extra');
$this->fail('xxxx');
} catch (AssertionFailedError $e) {
$this->assertSame('Failed asserting that two strings are identical.', $e->getMessage());
}
}

public function testAssertSee()
{
$response = $this->makeMockResponse([
Expand Down

0 comments on commit c703de3

Please sign in to comment.