diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index c36d5d871946..369b00ac5dca 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -197,6 +197,19 @@ public function assertSee($value) return $this; } + /** + * Assert that the given string is contained within the response text. + * + * @param string $value + * @return $this + */ + public function assertSeeText($value) + { + PHPUnit::assertContains($value, strip_tags($this->getContent())); + + return $this; + } + /** * Assert that the given string is not contained within the response. * @@ -210,6 +223,19 @@ public function assertDontSee($value) return $this; } + /** + * Assert that the given string is not contained within the response text. + * + * @param string $value + * @return $this + */ + public function assertDontSeeText($value) + { + PHPUnit::assertNotContains($value, strip_tags($this->getContent())); + + return $this; + } + /** * Assert that the response is a superset of the given JSON. * diff --git a/tests/Foundation/FoundationTestResponseTest.php b/tests/Foundation/FoundationTestResponseTest.php index 475e4afc46f7..289664890ae2 100644 --- a/tests/Foundation/FoundationTestResponseTest.php +++ b/tests/Foundation/FoundationTestResponseTest.php @@ -26,6 +26,19 @@ public function testAssertViewHas() $response->assertViewHas('foo'); } + public function testAssertSeeText() + { + $baseResponse = tap(new Response, function ($response) { + $response->setContent(\Mockery::mock(View::class, [ + 'render' => 'foobar', + ])); + }); + + $response = TestResponse::fromBaseResponse($baseResponse); + + $response->assertSeeText('foobar'); + } + public function testAssertJsonWithArray() { $response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceStub));