1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 08:24:03 +00:00

phpunit to pest

This commit is contained in:
Abrar Ahmad 2022-08-03 15:28:35 +05:00
parent 3990aa6eb6
commit e4442cf6cb

View file

@ -2,72 +2,53 @@
declare(strict_types=1); declare(strict_types=1);
namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Commands\ClearPendingTenants; use Stancl\Tenancy\Commands\ClearPendingTenants;
use Stancl\Tenancy\Commands\CreatePendingTenants; use Stancl\Tenancy\Commands\CreatePendingTenants;
use Stancl\Tenancy\Events\PullingPendingTenant;
use Stancl\Tenancy\Events\PendingTenantPulled;
use Stancl\Tenancy\Events\CreatingPendingTenant; use Stancl\Tenancy\Events\CreatingPendingTenant;
use Stancl\Tenancy\Events\PendingTenantCreated; use Stancl\Tenancy\Events\PendingTenantCreated;
use Stancl\Tenancy\Events\PendingTenantPulled;
use Stancl\Tenancy\Events\PullingPendingTenant;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
class PendingTenantsTest extends TestCase test('a tenant is correctly identified as pending', function (){
{
public function setUp(): void
{
parent::setUp();
}
/** @test */
public function a_tenant_is_correctly_identified_as_pending()
{
Tenant::createPending(); Tenant::createPending();
$this->assertCount(1, Tenant::onlyPending()->get()); expect(Tenant::onlyPending()->count())->toBe(1);
Tenant::onlyPending()->first()->update([ Tenant::onlyPending()->first()->update([
'pending_since' => null 'pending_since' => null
]); ]);
$this->assertCount(0, Tenant::onlyPending()->get()); expect(Tenant::onlyPending()->count())->toBe(0);
} });
/** @test */ test('pending trait imports query scopes', function () {
public function pending_trait_imports_query_scopes()
{
Tenant::createPending(); Tenant::createPending();
Tenant::create(); Tenant::create();
Tenant::create(); Tenant::create();
$this->assertCount(1, Tenant::onlyPending()->get()); expect(Tenant::onlyPending()->count())->toBe(1)
->and(Tenant::withPending(true)->count())->toBe(3)
->and(Tenant::withPending(false)->count())->toBe(2)
->and(Tenant::withoutPending()->count())->toBe(2);
$this->assertCount(3, Tenant::withPending(true)->get()); });
$this->assertCount(2, Tenant::withPending(false)->get()); test('pending tenants are created and deleted from the commands', function () {
$this->assertCount(2, Tenant::withoutPending()->get());
}
/** @test */
public function pending_tenants_are_created_and_deleted_from_the_commands()
{
config(['tenancy.pending.count' => 4]); config(['tenancy.pending.count' => 4]);
Artisan::call(CreatePendingTenants::class); Artisan::call(CreatePendingTenants::class);
$this->assertCount(4, Tenant::onlyPending()->get()); expect(Tenant::onlyPending()->count())->toBe(4);
Artisan::call(ClearPendingTenants::class); Artisan::call(ClearPendingTenants::class);
$this->assertCount(0, Tenant::onlyPending()->get()); expect(Tenant::onlyPending()->count())->toBe(0);
} });
/** @test */ test('clear pending tenants command only delete pending tenants older than', function () {
public function clear_pending_tenants_command_only_delete_pending_tenants_older_than()
{
config(['tenancy.pending.count' => 2]); config(['tenancy.pending.count' => 2]);
Artisan::call(CreatePendingTenants::class); Artisan::call(CreatePendingTenants::class);
@ -78,19 +59,15 @@ class PendingTenantsTest extends TestCase
Artisan::call('tenants:pending-clear --older-than-days=2'); Artisan::call('tenants:pending-clear --older-than-days=2');
$this->assertCount(1, Tenant::onlyPending()->get()); expect(Tenant::onlyPending()->count())->toBe(1);
} });
/** @test */ test('clear pending tenants command cannot run with both time constraints', function () {
public function clear_pending_tenants_command_cannot_run_with_both_time_constraints() pest()->artisan('tenants:pending-clear --older-than-days=2 --older-than-hours=2')
{
$this->artisan('tenants:pending-clear --older-than-days=2 --older-than-hours=2')
->assertFailed(); ->assertFailed();
} });
/** @test */ test('clear pending tenants command all option overrides config', function () {
public function clear_pending_tenants_command_all_option_overrides_config()
{
Tenant::createPending(); Tenant::createPending();
Tenant::createPending(); Tenant::createPending();
@ -104,59 +81,49 @@ class PendingTenantsTest extends TestCase
'--all' => true '--all' => true
]); ]);
$this->assertCount(0, Tenant::onlyPending()->get()); expect(Tenant::onlyPending()->count())->toBe(0);
} });
/** @test */ test('tenancy can check for rpending tenants', function () {
public function tenancy_can_check_for_rpending_tenants()
{
Tenant::query()->delete(); Tenant::query()->delete();
$this->assertFalse(Tenant::onlyPending()->exists()); expect(Tenant::onlyPending()->exists())->toBeFalse();
Tenant::createPending(); Tenant::createPending();
$this->assertTrue(Tenant::onlyPending()->exists()); expect(Tenant::onlyPending()->exists())->toBeTrue();
} });
/** @test */ test('tenancy can pull a pending tenant', function () {
public function tenancy_can_pull_a_pending_tenant() expect(Tenant::pullPendingTenant())->toBeNull();
{
$this->assertNull(Tenant::pullPendingTenant());
Tenant::createPending(); Tenant::createPending();
$this->assertInstanceOf(Tenant::class, Tenant::pullPendingTenant(true)); expect(Tenant::pullPendingTenant(true))->toBeInstanceOf(Tenant::class);
} });
/** @test */ test('tenancy can create if none are pending', function () {
public function tenancy_can_create_if_none_are_pending() expect(Tenant::all()->count())->toBe(0);
{
$this->assertCount(0, Tenant::all());
Tenant::pullPendingTenant(true); Tenant::pullPendingTenant(true);
$this->assertCount(1, Tenant::all()); expect(Tenant::all()->count())->toBe(1);
} });
/** @test */ test('pending tenants global scope config can include or exclude', function () {
public function pending_tenants_global_scope_config_can_include_or_exclude()
{
Tenant::createPending(); Tenant::createPending();
config(['tenancy.pending.include_in_queries' => false]); config(['tenancy.pending.include_in_queries' => false]);
$this->assertCount(0, Tenant::all()); expect(Tenant::all()->count())->toBe(0);
config(['tenancy.pending.include_in_queries' => true]); config(['tenancy.pending.include_in_queries' => true]);
$this->assertCount(1, Tenant::all()); expect(Tenant::all()->count())->toBe(1);
Tenant::all(); Tenant::all();
} });
/** @test */ test('pending events are triggerred', function () {
public function pending_events_are_triggerred()
{
Event::fake([ Event::fake([
CreatingPendingTenant::class, CreatingPendingTenant::class,
PendingTenantCreated::class, PendingTenantCreated::class,
@ -173,5 +140,4 @@ class PendingTenantsTest extends TestCase
Event::assertDispatched(PullingPendingTenant::class); Event::assertDispatched(PullingPendingTenant::class);
Event::assertDispatched(PendingTenantPulled::class); Event::assertDispatched(PendingTenantPulled::class);
} });
}