mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:34:04 +00:00
improve test logic
This commit is contained in:
parent
99b86bf07a
commit
9358819c24
2 changed files with 11 additions and 26 deletions
|
|
@ -13,7 +13,7 @@ class Up extends Command
|
||||||
|
|
||||||
protected $signature = 'tenants:up';
|
protected $signature = 'tenants:up';
|
||||||
|
|
||||||
protected $description = 'Put tenants out of maintenance';
|
protected $description = 'Put tenants out of maintenance mode.';
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,12 @@ declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Stancl\Tenancy\Database\Concerns\MaintenanceMode;
|
use Stancl\Tenancy\Database\Concerns\MaintenanceMode;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode;
|
use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode;
|
||||||
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
|
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
|
|
||||||
test('tenant can be in maintenance mode', function () {
|
test('tenants can be in maintenance mode', function () {
|
||||||
Route::get('/foo', function () {
|
Route::get('/foo', function () {
|
||||||
return 'bar';
|
return 'bar';
|
||||||
})->middleware([InitializeTenancyByDomain::class, CheckTenantForMaintenanceMode::class]);
|
})->middleware([InitializeTenancyByDomain::class, CheckTenantForMaintenanceMode::class]);
|
||||||
|
|
@ -20,27 +19,20 @@ test('tenant can be in maintenance mode', function () {
|
||||||
'domain' => 'acme.localhost',
|
'domain' => 'acme.localhost',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
pest()->get('http://acme.localhost/foo')
|
pest()->get('http://acme.localhost/foo')->assertStatus(200);
|
||||||
->assertSuccessful();
|
|
||||||
|
|
||||||
tenancy()->end(); // Flush stored tenant instance
|
|
||||||
|
|
||||||
$tenant->putDownForMaintenance();
|
$tenant->putDownForMaintenance();
|
||||||
|
|
||||||
|
tenancy()->end(); // End tenancy before making a request
|
||||||
pest()->get('http://acme.localhost/foo')->assertStatus(503);
|
pest()->get('http://acme.localhost/foo')->assertStatus(503);
|
||||||
|
|
||||||
tenancy()->end();
|
|
||||||
|
|
||||||
$tenant->bringUpFromMaintenance();
|
$tenant->bringUpFromMaintenance();
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end(); // End tenancy before making a request
|
||||||
|
pest()->get('http://acme.localhost/foo')->assertStatus(200);
|
||||||
pest()->get('http://acme.localhost/foo')
|
|
||||||
->assertSuccessful()
|
|
||||||
->assertSeeText('bar');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tenant can be in maintenance mode from command', function() {
|
test('tenants can be put into maintenance mode using artisan commands', function() {
|
||||||
Route::get('/foo', function () {
|
Route::get('/foo', function () {
|
||||||
return 'bar';
|
return 'bar';
|
||||||
})->middleware([InitializeTenancyByDomain::class, CheckTenantForMaintenanceMode::class]);
|
})->middleware([InitializeTenancyByDomain::class, CheckTenantForMaintenanceMode::class]);
|
||||||
|
|
@ -50,24 +42,17 @@ test('tenant can be in maintenance mode from command', function() {
|
||||||
'domain' => 'acme.localhost',
|
'domain' => 'acme.localhost',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
pest()->get('http://acme.localhost/foo')
|
pest()->get('http://acme.localhost/foo')->assertStatus(200);
|
||||||
->assertSuccessful();
|
|
||||||
|
|
||||||
tenancy()->end(); // Flush stored tenant instance
|
|
||||||
|
|
||||||
Artisan::call('tenants:down');
|
Artisan::call('tenants:down');
|
||||||
|
|
||||||
|
tenancy()->end(); // End tenancy before making a request
|
||||||
pest()->get('http://acme.localhost/foo')->assertStatus(503);
|
pest()->get('http://acme.localhost/foo')->assertStatus(503);
|
||||||
|
|
||||||
tenancy()->end();
|
|
||||||
|
|
||||||
Artisan::call('tenants:up');
|
Artisan::call('tenants:up');
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end(); // End tenancy before making a request
|
||||||
|
pest()->get('http://acme.localhost/foo')->assertStatus(200);
|
||||||
pest()->get('http://acme.localhost/foo')
|
|
||||||
->assertSuccessful()
|
|
||||||
->assertSeeText('bar');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
class MaintenanceTenant extends Tenant
|
class MaintenanceTenant extends Tenant
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue