SymfonyStyleTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 PHPUnit_Framework_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. $this->command = null;
  29. $this->tester = null;
  30. }
  31. /**
  32. * @dataProvider inputCommandToOutputFilesProvider
  33. */
  34. public function testOutputs($inputCommandFilepath, $outputFilepath)
  35. {
  36. $code = require $inputCommandFilepath;
  37. $this->command->setCode($code);
  38. $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
  39. $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
  40. }
  41. /**
  42. * @dataProvider inputInteractiveCommandToOutputFilesProvider
  43. */
  44. public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath)
  45. {
  46. $code = require $inputCommandFilepath;
  47. $this->command->setCode($code);
  48. $this->tester->execute(array(), array('interactive' => true, 'decorated' => false));
  49. $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
  50. }
  51. public function inputInteractiveCommandToOutputFilesProvider()
  52. {
  53. $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
  54. return array_map(null, glob($baseDir.'/command/interactive_command_*.php'), glob($baseDir.'/output/interactive_output_*.txt'));
  55. }
  56. public function inputCommandToOutputFilesProvider()
  57. {
  58. $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
  59. return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
  60. }
  61. }