CompletionOutputTestCase.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Tests\Completion\Output;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Completion\CompletionSuggestions;
  13. use Symfony\Component\Console\Completion\Output\CompletionOutputInterface;
  14. use Symfony\Component\Console\Input\InputOption;
  15. use Symfony\Component\Console\Output\StreamOutput;
  16. abstract class CompletionOutputTestCase extends TestCase
  17. {
  18. abstract public function getCompletionOutput(): CompletionOutputInterface;
  19. abstract public function getExpectedOptionsOutput(): string;
  20. abstract public function getExpectedValuesOutput(): string;
  21. public function testOptionsOutput()
  22. {
  23. $options = [
  24. new InputOption('option1', 'o', InputOption::VALUE_NONE),
  25. new InputOption('negatable', null, InputOption::VALUE_NEGATABLE),
  26. ];
  27. $suggestions = new CompletionSuggestions();
  28. $suggestions->suggestOptions($options);
  29. $stream = fopen('php://memory', 'rw+');
  30. $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream));
  31. fseek($stream, 0);
  32. $this->assertEquals($this->getExpectedOptionsOutput(), stream_get_contents($stream));
  33. }
  34. public function testValuesOutput()
  35. {
  36. $suggestions = new CompletionSuggestions();
  37. $suggestions->suggestValues(['Green', 'Red', 'Yellow']);
  38. $stream = fopen('php://memory', 'rw+');
  39. $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream));
  40. fseek($stream, 0);
  41. $this->assertEquals($this->getExpectedValuesOutput(), stream_get_contents($stream));
  42. }
  43. }