SymfonyStyleTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Style;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Tester\CommandTester;
  14. class SymfonyStyleTest extends TestCase
  15. {
  16. /** @var Command */
  17. protected $command;
  18. /** @var CommandTester */
  19. protected $tester;
  20. protected function setUp()
  21. {
  22. putenv('COLUMNS=121');
  23. $this->command = new Command('sfstyle');
  24. $this->tester = new CommandTester($this->command);
  25. }
  26. protected function tearDown()
  27. {
  28. putenv('COLUMNS');
  29. $this->command = null;
  30. $this->tester = null;
  31. }
  32. /**
  33. * @dataProvider inputCommandToOutputFilesProvider
  34. */
  35. public function testOutputs($inputCommandFilepath, $outputFilepath)
  36. {
  37. $code = require $inputCommandFilepath;
  38. $this->command->setCode($code);
  39. $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
  40. $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
  41. }
  42. /**
  43. * @dataProvider inputInteractiveCommandToOutputFilesProvider
  44. */
  45. public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath)
  46. {
  47. $code = require $inputCommandFilepath;
  48. $this->command->setCode($code);
  49. $this->tester->execute(array(), array('interactive' => true, 'decorated' => false));
  50. $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
  51. }
  52. public function inputInteractiveCommandToOutputFilesProvider()
  53. {
  54. $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
  55. return array_map(null, glob($baseDir.'/command/interactive_command_*.php'), glob($baseDir.'/output/interactive_output_*.txt'));
  56. }
  57. public function inputCommandToOutputFilesProvider()
  58. {
  59. $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
  60. return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
  61. }
  62. }