10000 build up · symfony/symfony@007be88 · GitHub
[go: up one dir, main page]

Skip to content

Commit 007be88

Browse files
committed
build up
1 parent 7b097ae commit 007be88

File tree

4 files changed

+96
-45
lines changed

4 files changed

+96
-45
lines changed

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
1515

1616
/**
17-
* ConsoleOutput is the default class for all CLI output. It uses STDOUT.
17+
* ConsoleOutput is the default class for all CLI output. It uses STDOUT and STDERR.
1818
*
1919
* This class is a convenient wrapper around `StreamOutput`.
2020
*
@@ -96,8 +96,7 @@ public function setErrorOutput(OutputInterface $error)
9696
}
9797

9898
/**
99-
* Returns true if current environment supports writing console output to
100-
* STDOUT.
99+
* Returns true if current environment supports writing console output to STDOUT.
101100
*
102101
* @return bool
103102
*/
@@ -107,8 +106,7 @@ protected function hasStdoutSupport()
107106
}
108107

109108
/**
110-
* Returns true if current environment supports writing console output to
111-
* STDERR.
109+
* Returns true if current environment supports writing console output to STDERR.
112110
*
113111
* @return bool
114112
*/
@@ -118,39 +116,39 @@ protected function hasStderrSupport()
118116
}
119117

120118
/**
121-
* Checks if current executing environment is IBM iSeries (OS400), which
122-
* doesn't properly convert character-encodings between ASCII to EBCDIC.
123-
*
124-
* @return bool
119+
* @return resource
125120
*/
126-
private function isRunningOS400()
121+
protected function openOutputStream()
127122
{
128-
$checks = array(
129-
function_exists('php_uname') ? php_uname('s') : '',
130-
getenv('OSTYPE'),
131-
PHP_OS,
132-
);
123+
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
133124

134-
return false !== stristr(implode(';', $checks), 'OS400');
125+
return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
135126
}
136127

137128
/**
138129
* @return resource
139130
*/
140-
private function openOutputStream()
131+
protected function openErrorStream()
141132
{
142-
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
133+
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
143134

144-
return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
135+
return fopen($errorStream, 'w');
145136
}
146137

147138
/**
148-
* @return resource
139+
* Checks if current executing environment is IBM iSeries (OS400), which
140+
* doesn't properly convert character-encodings between ASCII to EBCDIC.
141+
*
142+
* @return bool
149143
*/
150-
private function openErrorStream()
144+
private function isRunningOS400()
151145
{
152-
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
146+
$checks = array(
147+
function_exists('php_uname') ? php_uname('s') : '',
148+
getenv('OSTYPE'),
149+
PHP_OS,
150+
);
153151

154-
return fopen($errorStream, 'w');
152+
return false !== stristr(implode(';', $checks), 'OS400');
155153
}
156154
}

src/Symfony/Component/Console/Tester/ApplicationTester.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Input\ArrayInput;
1616
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\ConsoleOutput;
1718
use Symfony\Component\Console\Output\OutputInterface;
18-
use Symfony\Component\Console\Output\StreamOutput;
1919

2020
/**
2121
* Eases the testing of console applications.
@@ -31,12 +31,16 @@ class ApplicationTester
3131
{
3232
private $application;
3333
private $input;
34+
35+
/**
36+
* @var TestConsoleOutput
37+
*/
3438
private $output;
3539

3640
/**
3741
* Constructor.
3842
*
39-
* @param Application $application An Application instance to test.
43+
* @param Application $application Application to test.
4044
*/
4145
public function __construct(Application 10000 $application)
4246
{
@@ -48,9 +52,9 @@ public function __construct(Application $application)
4852
*
4953
* Available options:
5054
*
51-
* * interactive: Sets the input interactive flag
52-
* * decorated: Sets the output decorated flag
53-
* * verbosity: Sets the output verbosity flag
55+
* * interactive: Sets the input interactive flag
56+
* * decorated: Sets the output decorated flag
57+
* * verbosity: Sets the output verbosity flag
5458
*
5559
* @param array $input An array of arguments and options
5660
* @param array $options An array of options
@@ -64,13 +68,10 @@ public function run(array $input, $options = array())
6468
$this->input->setInteractive($options['interactive']);
6569
}
6670

67-
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
68-
if (isset($options['decorated'])) {
69-
$this->output->setDecorated($options['decorated']);
70-
}
71-
if (isset($options['verbosity'])) {
72-
$this->output->setVerbosity($options['verbosity']);
73-
}
71+
$this->output = new TestConsoleOutput(
72+
isset($options['verbosity']) ? $options['verbosity'] : ConsoleOutput::VERBOSITY_NORMAL,
73+
isset($options['decorated']) ? $options['decorated'] : null
74+
);
7475

7576
return $this->application->run($this->input, $this->output);
7677
}
@@ -95,6 +96,19 @@ public function getDisplay($normalize = false)
9596
return $display;
9697
}
9798

99+
public function getErrorOutput($normalize = false)
100+
{
101+
rewind($this->output->getErrorOutput()->getStream());
102+
103+
$display = stream_get_contents($this->output->getErrorOutput()->getStream());
104+
105+
if ($normalize) {
106+
$display = str_replace(PHP_EOL, "\n", $display);
107+
}
108+
109+
return $display;
110+
}
111+
98112
/**
99113
* Gets the input instance used by the last execution of the application.
100114
*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tester;
13+
14+
use Symfony\Component\Console\Output\ConsoleOutput;
15+
16+
/**
17+
* Test output class for testing console applications.
18+
*
19+
* @author SpacePossum
20+
*/
21+
class TestConsoleOutput extends ConsoleOutput
22+
{
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
protected function openOutputStream()
27+
{
28+
return @fopen('php://memory', 'w', false);
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
protected function openErrorStream()
35+
{
36+
return @fopen('php://memory', 'w', false);
37+
}
38+
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ public function testSetCatchExceptions()
412412

413413
$application->setCatchExceptions(true);
414414
$tester->run(array('command' => 'foo'), array('decorated' => false));
415-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->setCatchExceptions() sets the catch exception flag');
415+
416+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getErrorOutput(true), '->setCatchExceptions() sets the catch exception flag');
416417

417418
$application->setCatchExceptions(false);
418419
try {
@@ -462,21 +463,21 @@ public function testRenderException()
462463
$tester = new ApplicationTester($application);
463464

464465
$tester->run(array('command' => ' 10000 ;foo'), array('decorated' => false));
465-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->renderException() renders a pretty exception');
466+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exception');
466467

467468
$tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
468-
$this->assertContains('Exception trace', $tester->getDisplay(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
469+
$this->assertContains('Exception trace', $tester->getErrorOutput(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
469470

470471
$tester->run(array('command' => 'list', '--foo' => true), array('decorated' => false));
471-
$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');
472+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $tester->getErrorOutput(true), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
472473

473474
$application->add(new \Foo3Command());
474475
$tester = new ApplicationTester($application);
475476
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
476-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
477+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');
477478

478479
$tester->run(array('command' => 'foo3:bar'), array('decorated' => true));
479-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
480+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');
480481

481482
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
482483
$application->setAutoExit(false);
@@ -486,7 +487,7 @@ public function testRenderException()
486487
$tester = new ApplicationTester($application);
487488

488489
$tester->run(array('command' => 'foo'), array('decorated' => false));
489-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
490+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getErrorOutput(true), '->renderException() wraps messages when they are bigger than the terminal');
490491
}
491492

492493
/**
@@ -505,10 +506,10 @@ public function testRenderExceptionWithDoubleWidthCharacters()
505506
$tester = new ApplicationTester($application);
506507

507508
$tester->run(array('command' => 'foo'), array('decorated' => false));
508-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth1.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
509+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth1.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');
509510

510511
$tester->run(array('command' => 'foo'), array('decorated' => true));
511-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth1decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
512+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth1decorated.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');
512513

513514
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
514515
$application->setAutoExit(false);
@@ -520,7 +521,7 @@ public function testRenderExceptionWithDoubleWidthCharacters()
520521
});
521522
$tester = new ApplicationTester($application);
522523
$tester->run(array('command' => 'foo'), array('decorated' => false));
523-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth2.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
524+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth2.txt', $tester->getErrorOutput(true), '->renderException() wraps messages when they are bigger than the terminal');
524525
}
525526

526527
public function testRun()

0 commit comments

Comments
 (0)
0