8000 [Cache] Added command for list all available cache pools by Nyholm · Pull Request #31021 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Added command for list all available cache pools #31021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CHANGELOG
* Added the `messenger:setup-transports` command to setup messenger transports
* Added a `InMemoryTransport` to Messenger. Use it with a DSN starting with `in-memory://`.
* Added `framework.property_access.throw_exception_on_invalid_property_path` config option.
* Added `cache:pool:list` command to list all available cache pools.

4.2.0
-----
8000 Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* List available cache pools.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class CachePoolListCommand extends Command
{
protected static $defaultName = 'cache:pool:list';

private $poolNames;

public function __construct(array $poolNames)
{
parent::__construct();

$this->poolNames = $poolNames;
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setDescription('List available cache pools')
->setHelp(<<<'EOF'
The <info>%command.name%</info> command lists all available cache pools.
EOF
)
;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);

$io->table(['Pool name'], array_map(function ($pool) {
return [$pool];
}, $this->poolNames));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<tag name="console.command" command="cache:pool:delete" />
</service>

<service id="console.command.cache_pool_list" class="Symfony\Bundle\FrameworkBundle\Command\CachePoolListCommand">
<argument /> <!-- Pool names -->
<tag name="console.command" command="cache:pool:list" />
</service>

<service id="console.command.cache_warmup" class="Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand">
<argument type="service" id="cache_warmer" />
<tag name="console.command" command="cache:warmup" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Command\CachePoolListCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

/**
* @group functional
*/
class CachePoolListCommandTest extends WebTestCase
{
protected function setUp()
{
static::bootKernel(['test_case' => 'CachePools', 'root_config' => 'config.yml']);
}

public function testListPools()
{
$tester = $this->createCommandTester(['cache.app', 8000 'cache.system']);
$tester->execute([]);

$this->assertSame(0, $tester->getStatusCode(), 'cache:pool:list exits with 0 in case of success');
$this->assertContains('cache.app', $tester->getDisplay());
$this->assertContains('cache.system', $tester->getDisplay());
}

public function testEmptyList()
{
$tester = $this->createCommandTester([]);
$tester->execute([]);

$this->assertSame(0, $tester->getStatusCode(), 'cache:pool:list exits with 0 in case of success');
}

private function createCommandTester(array $poolNames)
{
$application = new Application(static::$kernel);
$application->add(new CachePoolListCommand($poolNames));

return new CommandTester($application->find('cache:pool:list'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public function process(ContainerBuilder $container)
$clearer->addTag($this->cacheSystemClearerTag);
}
}

if ($container->hasDefinition('console.command.cache_pool_list')) {
$container->getDefinition('console.command.cache_pool_list')->replaceArgument(0, array_keys($pools));
}
}

private function getNamespace($seed, $id)
Expand Down
0