Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add TestResponse::assertContent($string) #44580

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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