Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #31021 [Cache] Added command for list all available cache poo…
…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
Showing
5 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
src/Symfony/Bundle/FrameworkBundle/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,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)); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/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,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')); | ||
} | ||
} |
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