-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
source/Internal/Framework/Cache/Command/CachePoolListCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\EshopCommunity\Internal\Framework\Cache\Command; | ||
|
||
use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CachePoolName; | ||
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class CachePoolListCommand extends Command | ||
{ | ||
protected static $defaultName = 'oe:cache:pool:list'; | ||
|
||
public function __construct(private readonly ContextInterface $context) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setHelp( | ||
<<<'EOF' | ||
The <info>%command.name%</info> command lists all available dynamic cache pools. | ||
EOF | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$io->table( | ||
['Pool name'], | ||
array_map(static fn($pool) => [$pool], CachePoolName::getAll($this->context->getAllShopIds())) | ||
); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool; | ||
|
||
class CachePoolName | ||
{ | ||
private static string $namePrefix = 'oxid_pool_'; | ||
|
||
public static function get(int $shopId): string | ||
{ | ||
return static::$namePrefix . $shopId; | ||
} | ||
|
||
public static function getAll(array $shopIds): array | ||
{ | ||
return array_map( | ||
static fn($id) => static::$namePrefix . $id, | ||
$shopIds | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/Integration/Internal/Framework/Cache/Command/CachePoolListCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Framework\Cache\Command; | ||
|
||
use OxidEsales\EshopCommunity\Internal\Framework\Cache\Command\CachePoolListCommand; | ||
use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CachePoolName; | ||
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; | ||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
#[Group('cache')] | ||
class CachePoolListCommandTest extends TestCase | ||
{ | ||
public function testClearCacheTriggersRegularAndTemplatesCleaners(): void | ||
{ | ||
$context = $this->createStub(ContextInterface::class); | ||
$context->method('getAllShopIds')->willReturn([1, 3, 4, 2,]); | ||
|
||
$application = new Application(); | ||
$application->add(new CachePoolListCommand($context)); | ||
|
||
$command = $application->find('oe:cache:pool:list'); | ||
$commandTester = new CommandTester($command); | ||
$commandTester->execute([]); | ||
|
||
$commandTester->assertCommandIsSuccessful(); | ||
|
||
$output = $commandTester->getDisplay(); | ||
$this->assertStringContainsString(CachePoolName::get(3), $output); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/Integration/Internal/Framework/Cache/Pool/CachePoolNameTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Framework\Cache\Pool; | ||
|
||
use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CachePoolName; | ||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[Group('cache')] | ||
class CachePoolNameTest extends TestCase | ||
{ | ||
public function testGetPoolName(): void | ||
{ | ||
$shopId = 1; | ||
$this->assertSame( | ||
'oxid_pool_' . $shopId, | ||
CachePoolName::get($shopId) | ||
); | ||
} | ||
|
||
public function testGetAllPoolName(): void | ||
{ | ||
$this->assertSame( | ||
['oxid_pool_1', 'oxid_pool_2', 'oxid_pool_3', 'oxid_pool_4', 'oxid_pool_5'], | ||
CachePoolName::getAll([1, 2, 3, 4, 5,]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters