feat(core): add CLI management for tenant system stores

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-28 20:56:17 -04:00
parent e137de1183
commit 545a776aeb
8 changed files with 458 additions and 0 deletions
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace KTXT\Unit\Console\Tenant;
use KTXC\Console\Tenant\TenantStoreListCommand;
use KTXC\Console\Tenant\TenantStoreRemoveCommand;
use KTXC\Console\Tenant\TenantStoreSetCommand;
use KTXC\SystemStore\SystemStoreConfigurationService;
use KTXF\SystemStore\StoreReference;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
final class TenantStoreCommandsTest extends TestCase
{
#[Test]
public function listsTenantStores(): void
{
$stores = $this->createStub(SystemStoreConfigurationService::class);
$stores->method('list')->willReturn([
'previews' => new StoreReference('local', 'default', 'previews'),
]);
$tester = new CommandTester(new TenantStoreListCommand($stores));
$status = $tester->execute(['tenant' => 'tenant-a']);
self::assertSame(Command::SUCCESS, $status);
self::assertStringContainsString('previews', $tester->getDisplay());
self::assertStringContainsString('local', $tester->getDisplay());
}
#[Test]
public function configuresATenantStore(): void
{
$stores = $this->createMock(SystemStoreConfigurationService::class);
$stores->expects(self::once())
->method('set')
->with('tenant-a', 'previews', 'local', 'default', 'previews')
->willReturn(new StoreReference('local', 'default', 'previews'));
$tester = new CommandTester(new TenantStoreSetCommand($stores, new NullLogger()));
$status = $tester->execute([
'tenant' => 'tenant-a',
'name' => 'previews',
'provider' => 'local',
'service' => 'default',
'namespace' => 'previews',
]);
self::assertSame(Command::SUCCESS, $status);
self::assertStringContainsString('configured', $tester->getDisplay());
}
#[Test]
public function removesATenantStore(): void
{
$stores = $this->createMock(SystemStoreConfigurationService::class);
$stores->expects(self::once())->method('remove')->with('tenant-a', 'previews')->willReturn(true);
$tester = new CommandTester(new TenantStoreRemoveCommand($stores, new NullLogger()));
$status = $tester->execute(['tenant' => 'tenant-a', 'name' => 'previews']);
self::assertSame(Command::SUCCESS, $status);
self::assertStringContainsString('removed', $tester->getDisplay());
}
#[Test]
public function removingAnAbsentStoreIsIdempotent(): void
{
$stores = $this->createStub(SystemStoreConfigurationService::class);
$stores->method('remove')->willReturn(false);
$tester = new CommandTester(new TenantStoreRemoveCommand($stores, new NullLogger()));
$status = $tester->execute(['tenant' => 'tenant-a', 'name' => 'previews']);
self::assertSame(Command::SUCCESS, $status);
self::assertStringContainsString('not configured', $tester->getDisplay());
}
}