diff --git a/src/Symfony/Components/Console/Application.php b/src/Symfony/Components/Console/Application.php
index 7b1a8187fc..92783b6acb 100644
--- a/src/Symfony/Components/Console/Application.php
+++ b/src/Symfony/Components/Console/Application.php
@@ -187,7 +187,7 @@ class Application
if (true === $input->hasParameterOption(array('--version', '-V')))
{
- $output->write($this->getLongVersion());
+ $output->writeln($this->getLongVersion());
return 0;
}
@@ -732,22 +732,22 @@ class Application
$messages[] = str_repeat(' ', $len);
- $output->write("\n");
+ $output->writeln("\n");
foreach ($messages as $message)
{
- $output->write("$message");
+ $output->writeln("$message");
}
- $output->write("\n");
+ $output->writeln("\n");
if (null !== $this->runningCommand)
{
- $output->write(sprintf('%s', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
- $output->write("\n");
+ $output->writeln(sprintf('%s', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
+ $output->writeln("\n");
}
if (Output::VERBOSITY_VERBOSE === $output->getVerbosity())
{
- $output->write('Exception trace:');
+ $output->writeln('Exception trace:');
// exception related properties
$trace = $e->getTrace();
@@ -766,10 +766,10 @@ class Application
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
- $output->write(sprintf(' %s%s%s() at %s:%s', $class, $type, $function, $file, $line));
+ $output->writeln(sprintf(' %s%s%s() at %s:%s', $class, $type, $function, $file, $line));
}
- $output->write("\n");
+ $output->writeln("\n");
}
}
diff --git a/src/Symfony/Components/Console/Command/HelpCommand.php b/src/Symfony/Components/Console/Command/HelpCommand.php
index 9b9a0942e5..d5013cb385 100644
--- a/src/Symfony/Components/Console/Command/HelpCommand.php
+++ b/src/Symfony/Components/Console/Command/HelpCommand.php
@@ -72,11 +72,11 @@ EOF
if ($input->getOption('xml'))
{
- $output->write($this->command->asXml(), Output::OUTPUT_RAW);
+ $output->writeln($this->command->asXml(), Output::OUTPUT_RAW);
}
else
{
- $output->write($this->command->asText());
+ $output->writeln($this->command->asText());
}
}
}
diff --git a/src/Symfony/Components/Console/Command/ListCommand.php b/src/Symfony/Components/Console/Command/ListCommand.php
index 998cda8f19..3fddbc224c 100644
--- a/src/Symfony/Components/Console/Command/ListCommand.php
+++ b/src/Symfony/Components/Console/Command/ListCommand.php
@@ -62,11 +62,11 @@ EOF
{
if ($input->getOption('xml'))
{
- $output->write($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
+ $output->writeln($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
}
else
{
- $output->write($this->application->asText($input->getArgument('namespace')));
+ $output->writeln($this->application->asText($input->getArgument('namespace')));
}
}
}
diff --git a/src/Symfony/Components/Console/Helper/DialogHelper.php b/src/Symfony/Components/Console/Helper/DialogHelper.php
index 21b55cef03..a19c3d949a 100644
--- a/src/Symfony/Components/Console/Helper/DialogHelper.php
+++ b/src/Symfony/Components/Console/Helper/DialogHelper.php
@@ -34,7 +34,7 @@ class DialogHelper extends Helper
public function ask(OutputInterface $output, $question, $default = null)
{
// @codeCoverageIgnoreStart
- $output->write($question);
+ $output->writeln($question);
$ret = trim(fgets(STDIN));
@@ -91,7 +91,7 @@ class DialogHelper extends Helper
{
if (null !== $error)
{
- $output->write($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
+ $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
}
$value = $this->ask($output, $question, null);
diff --git a/src/Symfony/Components/Console/Output/NullOutput.php b/src/Symfony/Components/Console/Output/NullOutput.php
index b43a1c616a..86e2c326f8 100644
--- a/src/Symfony/Components/Console/Output/NullOutput.php
+++ b/src/Symfony/Components/Console/Output/NullOutput.php
@@ -26,8 +26,9 @@ class NullOutput extends Output
* Writes a message to the output.
*
* @param string $message A message to write to the output
+ * @param Boolean $newline Whether to add a newline or not
*/
- public function doWrite($message)
+ public function doWrite($message, $newline)
{
}
}
diff --git a/src/Symfony/Components/Console/Output/Output.php b/src/Symfony/Components/Console/Output/Output.php
index 9917c3b534..7bfa8bf012 100644
--- a/src/Symfony/Components/Console/Output/Output.php
+++ b/src/Symfony/Components/Console/Output/Output.php
@@ -111,12 +111,24 @@ abstract class Output implements OutputInterface
}
/**
- * Writes a message to the output.
+ * Writes a message to the output and adds a newline at the end.
*
* @param string|array $messages The message as an array of lines of a single string
* @param integer $type The type of output
*/
- public function write($messages, $type = 0)
+ public function writeln($messages, $type = 0)
+ {
+ $this->write($messages, true, $type);
+ }
+
+ /**
+ * Writes a message to the output.
+ *
+ * @param string|array $messages The message as an array of lines of a single string
+ * @param Boolean $newline Whether to add a newline or not
+ * @param integer $type The type of output
+ */
+ public function write($messages, $newline = false, $type = 0)
{
if (self::VERBOSITY_QUIET === $this->verbosity)
{
@@ -144,16 +156,17 @@ abstract class Output implements OutputInterface
throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
}
- $this->doWrite($message);
+ $this->doWrite($message, $newline);
}
}
/**
* Writes a message to the output.
*
- * @param string $message A message to write to the output
+ * @param string $message A message to write to the output
+ * @param Boolean $newline Whether to add a newline or not
*/
- abstract public function doWrite($message);
+ abstract public function doWrite($message, $newline);
/**
* Formats a message according to the given styles.
diff --git a/src/Symfony/Components/Console/Output/StreamOutput.php b/src/Symfony/Components/Console/Output/StreamOutput.php
index 4360776d75..fdb74debed 100644
--- a/src/Symfony/Components/Console/Output/StreamOutput.php
+++ b/src/Symfony/Components/Console/Output/StreamOutput.php
@@ -67,11 +67,12 @@ class StreamOutput extends Output
/**
* Writes a message to the output.
*
- * @param string $message A message to write to the output
+ * @param string $message A message to write to the output
+ * @param Boolean $newline Whether to add a newline or not
*/
- public function doWrite($message)
+ public function doWrite($message, $newline)
{
- if (false === @fwrite($this->stream, $message.PHP_EOL))
+ if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : '')))
{
// @codeCoverageIgnoreStart
// should never happen
diff --git a/src/Symfony/Components/Console/Shell.php b/src/Symfony/Components/Console/Shell.php
index a57ce6453f..e987cf133c 100644
--- a/src/Symfony/Components/Console/Shell.php
+++ b/src/Symfony/Components/Console/Shell.php
@@ -62,14 +62,14 @@ class Shell
readline_read_history($this->history);
readline_completion_function(array($this, 'autocompleter'));
- $this->output->write($this->getHeader());
+ $this->output->writeln($this->getHeader());
while (true)
{
$command = readline($this->application->getName().' > ');
if (false === $command)
{
- $this->output->write("\n");
+ $this->output->writeln("\n");
break;
}
@@ -79,7 +79,7 @@ class Shell
if (0 !== $ret = $this->application->run(new StringInput($command), $this->output))
{
- $this->output->write(sprintf('The command terminated with an error status (%s)', $ret));
+ $this->output->writeln(sprintf('The command terminated with an error status (%s)', $ret));
}
}
}
diff --git a/tests/fixtures/Symfony/Components/Console/FooCommand.php b/tests/fixtures/Symfony/Components/Console/FooCommand.php
index ce996235eb..7792254ddb 100644
--- a/tests/fixtures/Symfony/Components/Console/FooCommand.php
+++ b/tests/fixtures/Symfony/Components/Console/FooCommand.php
@@ -20,7 +20,7 @@ class FooCommand extends Command
protected function interact(InputInterface $input, OutputInterface $output)
{
- $output->write('interact called');
+ $output->writeln('interact called');
}
protected function execute(InputInterface $input, OutputInterface $output)
@@ -28,6 +28,6 @@ class FooCommand extends Command
$this->input = $input;
$this->output = $output;
- $output->write('called');
+ $output->writeln('called');
}
}
diff --git a/tests/fixtures/Symfony/Components/Console/TestCommand.php b/tests/fixtures/Symfony/Components/Console/TestCommand.php
index c0c02dd280..751570f2e3 100644
--- a/tests/fixtures/Symfony/Components/Console/TestCommand.php
+++ b/tests/fixtures/Symfony/Components/Console/TestCommand.php
@@ -28,11 +28,11 @@ class TestCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output)
{
- $output->write('execute called');
+ $output->writeln('execute called');
}
protected function interact(InputInterface $input, OutputInterface $output)
{
- $output->write('interact called');
+ $output->writeln('interact called');
}
}
diff --git a/tests/unit/Symfony/Components/Console/Command/CommandTest.php b/tests/unit/Symfony/Components/Console/Command/CommandTest.php
index b3f734b46f..3b5b1ec515 100644
--- a/tests/unit/Symfony/Components/Console/Command/CommandTest.php
+++ b/tests/unit/Symfony/Components/Console/Command/CommandTest.php
@@ -190,7 +190,7 @@ $command = new TestCommand();
$command->setApplication($application);
$ret = $command->setCode(function (InputInterface $input, OutputInterface $output)
{
- $output->write('from the code...');
+ $output->writeln('from the code...');
});
$t->is($ret, $command, '->setCode() implements a fluent interface');
$tester = new CommandTester($command);
diff --git a/tests/unit/Symfony/Components/Console/Output/OutputTest.php b/tests/unit/Symfony/Components/Console/Output/OutputTest.php
index 50e3cca560..03bed431b7 100644
--- a/tests/unit/Symfony/Components/Console/Output/OutputTest.php
+++ b/tests/unit/Symfony/Components/Console/Output/OutputTest.php
@@ -23,9 +23,9 @@ class TestOutput extends Output
return static::$styles[$name];
}
- public function doWrite($message)
+ public function doWrite($message, $newline)
{
- $this->output .= $message."\n";
+ $this->output .= $message.($newline ? "\n" : '');
}
}
@@ -51,50 +51,50 @@ $t->diag('::setStyle()');
Output::setStyle('FOO', array('bg' => 'red', 'fg' => 'yellow', 'blink' => true));
$t->is(TestOutput::getStyle('foo'), array('bg' => 'red', 'fg' => 'yellow', 'blink' => true), '::setStyle() sets a new style');
-// ->write()
-$t->diag('->write()');
+// ->writeln()
+$t->diag('->writeln()');
$output = new TestOutput(Output::VERBOSITY_QUIET);
-$output->write('foo');
-$t->is($output->output, '', '->write() outputs nothing if verbosity is set to VERBOSITY_QUIET');
+$output->writeln('foo');
+$t->is($output->output, '', '->writeln() outputs nothing if verbosity is set to VERBOSITY_QUIET');
$output = new TestOutput();
-$output->write(array('foo', 'bar'));
-$t->is($output->output, "foo\nbar\n", '->write() can take an array of messages to output');
+$output->writeln(array('foo', 'bar'));
+$t->is($output->output, "foo\nbar\n", '->writeln() can take an array of messages to output');
$output = new TestOutput();
-$output->write('foo', Output::OUTPUT_RAW);
-$t->is($output->output, "foo\n", '->write() outputs the raw message if OUTPUT_RAW is specified');
+$output->writeln('foo', Output::OUTPUT_RAW);
+$t->is($output->output, "foo\n", '->writeln() outputs the raw message if OUTPUT_RAW is specified');
$output = new TestOutput();
-$output->write('foo', Output::OUTPUT_PLAIN);
-$t->is($output->output, "foo\n", '->write() strips decoration tags if OUTPUT_PLAIN is specified');
+$output->writeln('foo', Output::OUTPUT_PLAIN);
+$t->is($output->output, "foo\n", '->writeln() strips decoration tags if OUTPUT_PLAIN is specified');
$output = new TestOutput();
$output->setDecorated(false);
-$output->write('foo');
-$t->is($output->output, "foo\n", '->write() strips decoration tags if decoration is set to false');
+$output->writeln('foo');
+$t->is($output->output, "foo\n", '->writeln() strips decoration tags if decoration is set to false');
$output = new TestOutput();
$output->setDecorated(true);
-$output->write('foo');
-$t->is($output->output, "\033[33;41;5mfoo\033[0m\n", '->write() decorates the output');
+$output->writeln('foo');
+$t->is($output->output, "\033[33;41;5mfoo\033[0m\n", '->writeln() decorates the output');
try
{
- $output->write('foo', 24);
- $t->fail('->write() throws an \InvalidArgumentException when the type does not exist');
+ $output->writeln('foo', 24);
+ $t->fail('->writeln() throws an \InvalidArgumentException when the type does not exist');
}
catch (\InvalidArgumentException $e)
{
- $t->pass('->write() throws an \InvalidArgumentException when the type does not exist');
+ $t->pass('->writeln() throws an \InvalidArgumentException when the type does not exist');
}
try
{
- $output->write('foo');
- $t->fail('->write() throws an \InvalidArgumentException when a style does not exist');
+ $output->writeln('foo');
+ $t->fail('->writeln() throws an \InvalidArgumentException when a style does not exist');
}
catch (\InvalidArgumentException $e)
{
- $t->pass('->write() throws an \InvalidArgumentException when a style does not exist');
+ $t->pass('->writeln() throws an \InvalidArgumentException when a style does not exist');
}
diff --git a/tests/unit/Symfony/Components/Console/Output/StreamOutputTest.php b/tests/unit/Symfony/Components/Console/Output/StreamOutputTest.php
index aad9c55dbe..e8db804a20 100644
--- a/tests/unit/Symfony/Components/Console/Output/StreamOutputTest.php
+++ b/tests/unit/Symfony/Components/Console/Output/StreamOutputTest.php
@@ -42,6 +42,6 @@ $t->is($output->getStream(), $stream, '->getStream() returns the current stream'
// ->doWrite()
$t->diag('->doWrite()');
$output = new StreamOutput($stream);
-$output->write('foo');
+$output->writeln('foo');
rewind($output->getStream());
$t->is(stream_get_contents($output->getStream()), "foo\n", '->doWrite() writes to the stream');
diff --git a/tests/unit/Symfony/Components/Console/Tester/ApplicationTesterTest.php b/tests/unit/Symfony/Components/Console/Tester/ApplicationTesterTest.php
index aba49cb825..d2cdb4883f 100644
--- a/tests/unit/Symfony/Components/Console/Tester/ApplicationTesterTest.php
+++ b/tests/unit/Symfony/Components/Console/Tester/ApplicationTesterTest.php
@@ -21,7 +21,7 @@ $application->setAutoExit(false);
$application->register('foo')
->addArgument('command')
->addArgument('foo')
- ->setCode(function ($input, $output) { $output->write('foo'); })
+ ->setCode(function ($input, $output) { $output->writeln('foo'); })
;
$tester = new ApplicationTester($application);
diff --git a/tests/unit/Symfony/Components/Console/Tester/CommandTesterTest.php b/tests/unit/Symfony/Components/Console/Tester/CommandTesterTest.php
index a6dcd5fb1d..aa48b83366 100644
--- a/tests/unit/Symfony/Components/Console/Tester/CommandTesterTest.php
+++ b/tests/unit/Symfony/Components/Console/Tester/CommandTesterTest.php
@@ -19,7 +19,7 @@ $t = new LimeTest(6);
$command = new Command('foo');
$command->addArgument('command');
$command->addArgument('foo');
-$command->setCode(function ($input, $output) { $output->write('foo'); });
+$command->setCode(function ($input, $output) { $output->writeln('foo'); });
$tester = new CommandTester($command);
$tester->execute(array('foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));