Files
server/tests/php/Unit/Service/TenantServiceTest.php
T
Sebastian b570150258
JS Unit Tests / test (pull_request) Failing after 43s
Build Test / build (pull_request) Successful in 44s
PHP Unit Tests / test (pull_request) Successful in 1m9s
PHP Integration Tests / Integration Tests (pull_request) Successful in 1m28s
chore: implement php test suites
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-23 22:20:35 -04:00

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);
}
}