72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXT\Unit\Service;
|
|
|
|
use KTXC\Models\Tenant\DomainCollection;
|
|
use KTXC\Models\Tenant\TenantObject;
|
|
use KTXC\Service\TenantService;
|
|
use KTXC\Stores\TenantStore;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class TenantServiceTest extends TestCase
|
|
{
|
|
private TenantStore&MockObject $store;
|
|
private TenantService $service;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->store = $this->createMock(TenantStore::class);
|
|
$this->service = new TenantService($this->store);
|
|
}
|
|
|
|
public function testDepositRejectsTenantWithoutDomains(): void
|
|
{
|
|
$this->store->expects($this->never())->method('deposit');
|
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('at least one domain');
|
|
|
|
$this->service->deposit(new TenantObject());
|
|
}
|
|
|
|
public function testDepositRejectsTenantWithEmptyDomainCollection(): void
|
|
{
|
|
$tenant = (new TenantObject())->setDomains(new DomainCollection([]));
|
|
$this->store->expects($this->never())->method('deposit');
|
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$this->service->deposit($tenant);
|
|
}
|
|
|
|
public function testDepositPassesTenantWithDomainsToStore(): void
|
|
{
|
|
$tenant = (new TenantObject())
|
|
->setIdentifier('acme')
|
|
->setDomains(new DomainCollection(['acme.test']));
|
|
|
|
$this->store->expects($this->once())->method('deposit')->with($tenant)->willReturn($tenant);
|
|
|
|
$this->assertSame($tenant, $this->service->deposit($tenant));
|
|
}
|
|
|
|
public function testListDelegatesToStore(): void
|
|
{
|
|
$tenants = ['a' => new TenantObject()];
|
|
$this->store->expects($this->once())->method('list')->willReturn($tenants);
|
|
|
|
$this->assertSame($tenants, $this->service->list());
|
|
}
|
|
|
|
public function testDestroyDelegatesToStore(): void
|
|
{
|
|
$tenant = new TenantObject();
|
|
$this->store->expects($this->once())->method('destroy')->with($tenant);
|
|
|
|
$this->service->destroy($tenant);
|
|
}
|
|
}
|