Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[Console] added a way to normalize a command display when using the t…

…ester
  • Loading branch information...
commit be6788704894460cc94da1d2abe00a0ddf0892af 1 parent ce8d34e
Fabien Potencier fabpot authored
1  CHANGELOG.md
Source Rendered
@@ -4,6 +4,7 @@ CHANGELOG
4 4 2.3.0
5 5 -----
6 6
  7 + * added a way to normalize EOLs in `ApplicationTester::getDisplay()` and `CommandTester::getDisplay()`
7 8 * added a way to set the progress bar progress via the `setCurrent` method
8 9
9 10 2.2.0
12 Tester/ApplicationTester.php
@@ -78,13 +78,21 @@ public function run(array $input, $options = array())
78 78 /**
79 79 * Gets the display returned by the last execution of the application.
80 80 *
  81 + * @param Boolean $normalize Whether to normalize end of lines to \n or not
  82 + *
81 83 * @return string The display
82 84 */
83   - public function getDisplay()
  85 + public function getDisplay($normalize = false)
84 86 {
85 87 rewind($this->output->getStream());
86 88
87   - return stream_get_contents($this->output->getStream());
  89 + $display = stream_get_contents($this->output->getStream());
  90 +
  91 + if ($normalize) {
  92 + $display = str_replace(PHP_EOL, "\n", $display);
  93 + }
  94 +
  95 + return $display;
88 96 }
89 97
90 98 /**
12 Tester/CommandTester.php
@@ -71,13 +71,21 @@ public function execute(array $input, array $options = array())
71 71 /**
72 72 * Gets the display returned by the last execution of the command.
73 73 *
  74 + * @param Boolean $normalize Whether to normalize end of lines to \n or not
  75 + *
74 76 * @return string The display
75 77 */
76   - public function getDisplay()
  78 + public function getDisplay($normalize = false)
77 79 {
78 80 rewind($this->output->getStream());
79 81
80   - return stream_get_contents($this->output->getStream());
  82 + $display = stream_get_contents($this->output->getStream());
  83 +
  84 + if ($normalize) {
  85 + $display = str_replace(PHP_EOL, "\n", $display);
  86 + }
  87 +
  88 + return $display;
81 89 }
82 90
83 91 /**
24 Tests/ApplicationTest.php
@@ -356,7 +356,7 @@ public function testSetCatchExceptions()
356 356
357 357 $application->setCatchExceptions(true);
358 358 $tester->run(array('command' => 'foo'), array('decorated' => false));
359   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->setCatchExceptions() sets the catch exception flag');
  359 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->setCatchExceptions() sets the catch exception flag');
360 360
361 361 $application->setCatchExceptions(false);
362 362 try {
@@ -396,18 +396,18 @@ public function testRenderException()
396 396 $tester = new ApplicationTester($application);
397 397
398 398 $tester->run(array('command' => 'foo'), array('decorated' => false));
399   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exception');
  399 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->renderException() renders a pretty exception');
400 400
401 401 $tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
402 402 $this->assertContains('Exception trace', $tester->getDisplay(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
403 403
404 404 $tester->run(array('command' => 'list', '--foo' => true), array('decorated' => false));
405   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
  405 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $tester->getDisplay(true), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
406 406
407 407 $application->add(new \Foo3Command);
408 408 $tester = new ApplicationTester($application);
409 409 $tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
410   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions');
  410 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
411 411
412 412 $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
413 413 $application->setAutoExit(false);
@@ -417,7 +417,7 @@ public function testRenderException()
417 417 $tester = new ApplicationTester($application);
418 418
419 419 $tester->run(array('command' => 'foo'), array('decorated' => false));
420   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() wraps messages when they are bigger than the terminal');
  420 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
421 421 }
422 422
423 423 public function testRun()
@@ -443,19 +443,19 @@ public function testRun()
443 443 $tester = new ApplicationTester($application);
444 444
445 445 $tester->run(array(), array('decorated' => false));
446   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the list command if no argument is passed');
  446 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $tester->getDisplay(true), '->run() runs the list command if no argument is passed');
447 447
448 448 $tester->run(array('--help' => true), array('decorated' => false));
449   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if --help is passed');
  449 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if --help is passed');
450 450
451 451 $tester->run(array('-h' => true), array('decorated' => false));
452   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if -h is passed');
  452 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if -h is passed');
453 453
454 454 $tester->run(array('command' => 'list', '--help' => true), array('decorated' => false));
455   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the help if --help is passed');
  455 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if --help is passed');
456 456
457 457 $tester->run(array('command' => 'list', '-h' => true), array('decorated' => false));
458   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the help if -h is passed');
  458 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if -h is passed');
459 459
460 460 $tester->run(array('--ansi' => true));
461 461 $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');
@@ -464,10 +464,10 @@ public function testRun()
464 464 $this->assertFalse($tester->getOutput()->isDecorated(), '->run() forces color output to be disabled if --no-ansi is passed');
465 465
466 466 $tester->run(array('--version' => true), array('decorated' => false));
467   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the program version if --version is passed');
  467 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if --version is passed');
468 468
469 469 $tester->run(array('-V' => true), array('decorated' => false));
470   - $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the program version if -v is passed');
  470 + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if -v is passed');
471 471
472 472 $tester->run(array('command' => 'list', '--quiet' => true));
473 473 $this->assertSame('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');

0 comments on commit be67887

Please sign in to comment.
Something went wrong with that request. Please try again.