From 276d44ac0489dc83424e3f968af1798670c1ad12 Mon Sep 17 00:00:00 2001 From: Chinmay Purav Date: Thu, 12 Sep 2024 23:41:11 +0530 Subject: [PATCH] tests added --- tests/MaintenanceModeTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/MaintenanceModeTest.php b/tests/MaintenanceModeTest.php index 4a8d8d0c..93d3b3fe 100644 --- a/tests/MaintenanceModeTest.php +++ b/tests/MaintenanceModeTest.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; +use Illuminate\Support\Facades\Event; +use Stancl\Tenancy\Events\TenantGoingInMaintenanceMode; +use Stancl\Tenancy\Events\TenantWentInMaintenanceMode; use Symfony\Component\HttpKernel\Exception\HttpException; use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException; use Illuminate\Support\Facades\Route; @@ -18,6 +21,8 @@ class MaintenanceModeTest extends TestCase /** @test */ public function tenant_can_be_in_maintenance_mode() { + Event::fake([TenantGoingInMaintenanceMode::class, TenantWentInMaintenanceMode::class]); + Route::get('/foo', function () { return 'bar'; })->middleware([InitializeTenancyByDomain::class, CheckTenantForMaintenanceMode::class]); @@ -32,8 +37,14 @@ class MaintenanceModeTest extends TestCase tenancy()->end(); // flush stored tenant instance + Event::assertNotDispatched(TenantGoingInMaintenanceMode::class); + Event::assertNotDispatched(TenantWentInMaintenanceMode::class); + $tenant->putDownForMaintenance(); + Event::assertDispatched(TenantGoingInMaintenanceMode::class); + Event::assertDispatched(TenantWentInMaintenanceMode::class); + $this->expectException(HttpException::class); $this->withoutExceptionHandling() ->get('http://acme.localhost/foo');