暂无描述

SymfonyStyleTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. 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. }