From cb2bd018aad52f5646fa0d5d283f5409ee8a5527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sun, 10 May 2020 19:53:34 +0200 Subject: [PATCH] Improve HTTP tests with custom assertion method --- tests/TestCase.php | 11 ++++++++++- tests/v3/PathIdentificationTest.php | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 7594957c..f3079db2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,7 +4,8 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; -use Illuminate\Support\Facades\Redis; +use Illuminate\Testing\Assert as PHPUnit; +use Illuminate\Testing\TestResponse; use Stancl\Tenancy\Tenant; abstract class TestCase extends \Orchestra\Testbench\TestCase @@ -37,6 +38,14 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase if ($this->autoInitTenancy) { $this->initTenancy(); } + + TestResponse::macro('assertContent', function ($content) { + /** @var TestResponse $this */ + + PHPUnit::assertSame($content, $this->baseResponse->getContent()); + + return $this; + }); } public function createTenant($domains = ['test.localhost']) diff --git a/tests/v3/PathIdentificationTest.php b/tests/v3/PathIdentificationTest.php index dc440b2b..1190ce36 100644 --- a/tests/v3/PathIdentificationTest.php +++ b/tests/v3/PathIdentificationTest.php @@ -50,7 +50,7 @@ class PathIdentificationTest extends TestCase $this ->get('/acme/foo/abc/xyz') - ->assertSee('abc + xyz'); + ->assertContent('abc + xyz'); $this->assertTrue(tenancy()->initialized); $this->assertSame('acme', tenant('id')); @@ -77,6 +77,6 @@ class PathIdentificationTest extends TestCase $this ->get('/acme/foo/abc/xyz') - ->assertSee('foo'); + ->assertContent('foo'); } }