feat: tenant management console commands
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXT\Unit\Console\Tenant;
|
||||
|
||||
use KTXC\Console\Tenant\TenantListCommand;
|
||||
use KTXC\Models\Tenant\DomainCollection;
|
||||
use KTXC\Models\Tenant\TenantObject;
|
||||
use KTXC\Service\TenantService;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class TenantListCommandTest extends TestCase
|
||||
{
|
||||
private TenantService&MockObject $tenantService;
|
||||
private CommandTester $tester;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->tenantService = $this->createMock(TenantService::class);
|
||||
$this->tester = new CommandTester(
|
||||
new TenantListCommand($this->tenantService)
|
||||
);
|
||||
}
|
||||
|
||||
public function testReportsWhenNoTenantsExist(): void
|
||||
{
|
||||
$this->tenantService->method('list')->willReturn([]);
|
||||
|
||||
$status = $this->tester->execute([]);
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $status);
|
||||
$this->assertStringContainsString('No tenants found', $this->tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testListsTenantsWithDomains(): void
|
||||
{
|
||||
$acme = (new TenantObject())
|
||||
->setIdentifier('acme')
|
||||
->setLabel('Acme Inc')
|
||||
->setEnabled(true)
|
||||
->setDomains(new DomainCollection(['acme.test', 'acme.example']));
|
||||
|
||||
$wayne = (new TenantObject())
|
||||
->setIdentifier('wayne')
|
||||
->setLabel('Wayne Corp')
|
||||
->setEnabled(false)
|
||||
->setDomains(new DomainCollection(['wayne.test']));
|
||||
|
||||
$this->tenantService->method('list')->willReturn(['a' => $acme, 'b' => $wayne]);
|
||||
|
||||
$status = $this->tester->execute([]);
|
||||
$display = $this->tester->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $status);
|
||||
$this->assertStringContainsString('acme', $display);
|
||||
$this->assertStringContainsString('Acme Inc', $display);
|
||||
$this->assertStringContainsString('acme.test, acme.example', $display);
|
||||
$this->assertStringContainsString('Wayne Corp', $display);
|
||||
$this->assertStringContainsString('wayne.test', $display);
|
||||
$this->assertStringContainsString('Total: 2 tenant(s)', $display);
|
||||
}
|
||||
|
||||
public function testHandlesTenantWithoutDomains(): void
|
||||
{
|
||||
$legacy = (new TenantObject())
|
||||
->setIdentifier('legacy')
|
||||
->setLabel('Legacy')
|
||||
->setEnabled(true);
|
||||
|
||||
$this->tenantService->method('list')->willReturn(['l' => $legacy]);
|
||||
|
||||
$status = $this->tester->execute([]);
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $status);
|
||||
$this->assertStringContainsString('legacy', $this->tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testFailsWhenServiceThrows(): void
|
||||
{
|
||||
$this->tenantService
|
||||
->method('list')
|
||||
->willThrowException(new \RuntimeException('datastore unavailable'));
|
||||
|
||||
$status = $this->tester->execute([]);
|
||||
|
||||
$this->assertSame(Command::FAILURE, $status);
|
||||
$this->assertStringContainsString('datastore unavailable', $this->tester->getDisplay());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user