Skip to content

Commit

Permalink
feature #31021 [Cache] Added command for list all available cache poo…
Browse files Browse the repository at this point in the history
…ls (Nyholm)

This PR was squashed before being merged into the 4.3-dev branch (closes #31021).

Discussion
----------

[Cache] Added command for list all available cache pools

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony-docs#9782
| License       | MIT
| Doc PR        |

Commits
-------

5c210e6 [Cache] Added command for list all available cache pools
  • Loading branch information
nicolas-grekas committed Apr 10, 2019
2 parents 2243bf5 + 5c210e6 commit b09dfd9
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
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
-----
Expand Down
@@ -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));
}
}
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
@@ -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', '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'));
}
}
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 comments on commit b09dfd9

Please sign in to comment.