|
| 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\Component\Console\Tests\Completion\Output; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\Console\Completion\CompletionSuggestions; |
| 16 | +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; |
| 17 | +use Symfony\Component\Console\Input\InputOption; |
| 18 | +use Symfony\Component\Console\Output\StreamOutput; |
| 19 | + |
| 20 | +abstract class CompletionOutputTestCase extends TestCase |
| 21 | +{ |
| 22 | + abstract public function getCompletionOutput(): CompletionOutputInterface; |
| 23 | + |
| 24 | + abstract public function getExpectedOptionsOutput(): string; |
| 25 | + |
| 26 | + abstract public function getExpectedValuesOutput(): string; |
| 27 | + |
| 28 | + public function testOptionsOutput() |
| 29 | + { |
| 30 | + $options = [ |
| 31 | + new InputOption('option1', 'o', InputOption::VALUE_NONE), |
| 32 | + new InputOption('negatable', null, InputOption::VALUE_NEGATABLE), |
| 33 | + ]; |
| 34 | + $suggestions = new CompletionSuggestions(); |
| 35 | + $suggestions->suggestOptions($options); |
| 36 | + $stream = fopen('php://memory', 'rw+'); |
| 37 | + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); |
| 38 | + fseek($stream, 0); |
| 39 | + $this->assertEquals($this->getExpectedOptionsOutput(), stream_get_contents($stream)); |
| 40 | + } |
| 41 | + |
| 42 | + public function testValuesOutput() |
| 43 | + { |
| 44 | + $suggestions = new CompletionSuggestions(); |
| 45 | + $suggestions->suggestValues(['Green', 'Red', 'Yellow']); |
| 46 | + $stream = fopen('php://memory', 'rw+'); |
| 47 | + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); |
| 48 | + fseek($stream, 0); |
| 49 | + $this->assertEquals($this->getExpectedValuesOutput(), stream_get_contents($stream)); |
| 50 | + } |
| 51 | +} |
0 commit comments