1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 17:24:03 +00:00

Fix #25 better error handling

This commit is contained in:
Samuel Štancl 2019-02-13 16:26:00 +01:00
parent fa5334f83e
commit d2ec7f171d
2 changed files with 15 additions and 2 deletions

View file

@ -147,9 +147,15 @@ class TenantManager
*/ */
public function findByDomain(string $domain = null, $fields = []) public function findByDomain(string $domain = null, $fields = [])
{ {
$domain = $domain ?: $this->currentDomain(); $domain = $domain ? : $this->currentDomain();
return $this->find($this->getIdByDomain($domain), $fields); $uuid = $this->getIdByDomain($domain);
if (is_null($uuid)) {
throw new \Exception("Tenant with domain $domain could not be identified.");
}
return $this->find($uuid, $fields);
} }
public static function currentDomain(): ?string public static function currentDomain(): ?string

View file

@ -91,4 +91,11 @@ class TenantManagerTest extends TestCase
$this->assertSame($domain, tenant()->create($domain)['domain']); $this->assertSame($domain, tenant()->create($domain)['domain']);
} }
/** @test */
public function find_by_domain_throws_an_exception_when_an_unused_domain_is_supplied()
{
$this->expectException(\Exception::class);
tenancy()->findByDomain('nonexistent.domain');
}
} }