|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Tests\Command; |
| 13 | + |
| 14 | +use PHPUnit\Framework\MockObject\MockObject; |
| 15 | +use Psr\Cache\CacheItemPoolInterface; |
| 16 | +use Symfony\Bundle\FrameworkBundle\Command\CachePoolClearCommand; |
| 17 | +use Symfony\Bundle\FrameworkBundle\Console\Application; |
| 18 | +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; |
| 19 | +use Symfony\Component\Console\Tester\CommandCompletionTester; |
| 20 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
| 21 | +use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer; |
| 22 | +use Symfony\Component\HttpKernel\KernelInterface; |
| 23 | + |
| 24 | +class CachePoolClearCommandTest extends TestCase |
| 25 | +{ |
| 26 | + private $cachePool; |
| 27 | + |
| 28 | + protected function setUp(): void |
| 29 | + { |
| 30 | + $this->cachePool = $this->createMock(CacheItemPoolInterface::class); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @dataProvider provideCompletionSuggestions |
| 35 | + */ |
| 36 | + public function testComplete(array $input, array $expectedSuggestions) |
| 37 | + { |
| 38 | + $application = new Application($this->getKernel()); |
| 39 | + $application->add(new CachePoolClearCommand(new Psr6CacheClearer(['foo' => $this->cachePool]), ['foo'])); |
| 40 | + $tester = new CommandCompletionTester($application->get('cache:pool:clear')); |
| 41 | + |
| 42 | + $suggestions = $tester->complete($input); |
| 43 | + |
| 44 | + $this->assertSame($expectedSuggestions, $suggestions); |
| 45 | + } |
| 46 | + |
| 47 | + public function provideCompletionSuggestions() |
| 48 | + { |
| 49 | + yield 'pool_name' => [ |
| 50 | + ['f'], |
| 51 | + ['foo'], |
| 52 | + ]; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @return MockObject&KernelInterface |
| 57 | + */ |
| 58 | + private function getKernel(): KernelInterface |
| 59 | + { |
| 60 | + $container = $this->createMock(ContainerInterface::class); |
| 61 | + |
| 62 | + $kernel = $this->createMock(KernelInterface::class); |
| 63 | + $kernel |
| 64 | + ->expects($this->any()) |
| 65 | + ->method('getContainer') |
| 66 | + ->willReturn($container); |
| 67 | + |
| 68 | + $kernel |
| 69 | + ->expects($this->once()) |
| 70 | + ->method('getBundles') |
| 71 | + ->willReturn([]); |
| 72 | + |
| 73 | + return $kernel; |
| 74 | + } |
| 75 | +} |
0 commit comments