From dc25c65e8417288114325f5412d5a594458c637b Mon Sep 17 00:00:00 2001 From: Ollie Read Date: Tue, 19 Nov 2024 12:56:19 +0000 Subject: [PATCH] test: Add unit test for eloquent tenant provider --- tests/Unit/Providers/EloquentProviderTest.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/Unit/Providers/EloquentProviderTest.php diff --git a/tests/Unit/Providers/EloquentProviderTest.php b/tests/Unit/Providers/EloquentProviderTest.php new file mode 100644 index 0000000..0689aa8 --- /dev/null +++ b/tests/Unit/Providers/EloquentProviderTest.php @@ -0,0 +1,71 @@ +set('multitenancy.providers.tenants.model', TenantModel::class); + }); + } + + #[Test] + public function hasARegisteredName(): void + { + $provider = provider('tenants'); + + $this->assertInstanceOf(EloquentTenantProvider::class, $provider); + $this->assertSame('tenants', $provider->getName()); + } + + #[Test] + public function hasAModelClass(): void + { + $provider = provider('tenants'); + + $this->assertInstanceOf(EloquentTenantProvider::class, $provider); + $this->assertSame(TenantModel::class, $provider->getModelClass()); + } + + #[Test] + public function retrievesTenantsByTheirIdentifier(): void + { + $provider = provider('tenants'); + + $tenant = TenantModel::factory()->createOne(); + + $found = $provider->retrieveByIdentifier($tenant->getTenantIdentifier()); + + $this->assertNotNull($found); + $this->assertTrue($tenant->is($found)); + + $this->assertNull($provider->retrieveByIdentifier('fake-identifier')); + } + + #[Test] + public function retrievesTenantsByTheirKey(): void + { + $provider = provider('tenants'); + + $tenant = TenantModel::factory()->createOne(); + + $found = $provider->retrieveByKey($tenant->getTenantKey()); + + $this->assertNotNull($found); + $this->assertTrue($tenant->is($found)); + + $this->assertNull($provider->retrieveByKey(-999)); + } +}