1
0
Fork 0

Merge branch '1.9'

pull/8528/head
Jordi Boggiano 2020-01-13 13:30:52 +01:00
commit 3d72b56ed6
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
4 changed files with 66 additions and 4 deletions

View File

@ -65,6 +65,22 @@ abstract class BaseIO implements IOInterface, LoggerInterface
$this->authentications[$repositoryName] = array('username' => $username, 'password' => $password);
}
/**
* {@inheritDoc}
*/
public function writeRaw($messages, $newline = true, $verbosity = self::NORMAL)
{
$this->write($messages, $newline, $verbosity);
}
/**
* {@inheritDoc}
*/
public function writeErrorRaw($messages, $newline = true, $verbosity = self::NORMAL)
{
$this->writeError($messages, $newline, $verbosity);
}
/**
* Check for overwrite and set the authentication information for the repository.
*

View File

@ -129,13 +129,29 @@ class ConsoleIO extends BaseIO
$this->doWrite($messages, $newline, true, $verbosity);
}
/**
* {@inheritDoc}
*/
public function writeRaw($messages, $newline = true, $verbosity = self::NORMAL)
{
$this->doWrite($messages, $newline, false, $verbosity, true);
}
/**
* {@inheritDoc}
*/
public function writeErrorRaw($messages, $newline = true, $verbosity = self::NORMAL)
{
$this->doWrite($messages, $newline, true, $verbosity, true);
}
/**
* @param array|string $messages
* @param bool $newline
* @param bool $stderr
* @param int $verbosity
*/
private function doWrite($messages, $newline, $stderr, $verbosity)
private function doWrite($messages, $newline, $stderr, $verbosity, $raw = false)
{
$sfVerbosity = $this->verbosityMap[$verbosity];
if ($sfVerbosity > $this->output->getVerbosity()) {
@ -149,6 +165,14 @@ class ConsoleIO extends BaseIO
$sfVerbosity = OutputInterface::OUTPUT_NORMAL;
}
if ($raw) {
if ($sfVerbosity === OutputInterface::OUTPUT_NORMAL) {
$sfVerbosity = OutputInterface::OUTPUT_RAW;
} else {
$sfVerbosity |= OutputInterface::OUTPUT_RAW;
}
}
if (null !== $this->startTime) {
$memoryUsage = memory_get_usage() / 1024 / 1024;
$timeSpent = microtime(true) - $this->startTime;

View File

@ -112,12 +112,20 @@ class ProcessExecutor
return;
}
if (method_exists($this->io, 'writeRaw')) {
if (Process::ERR === $type) {
$this->io->writeErrorRaw($buffer, false);
} else {
$this->io->writeRaw($buffer, false);
}
} else {
if (Process::ERR === $type) {
$this->io->writeError($buffer, false);
} else {
$this->io->write($buffer, false);
}
}
}
public static function getTimeout()
{

View File

@ -12,9 +12,14 @@
namespace Composer\Test\Util;
use Composer\IO\ConsoleIO;
use Composer\Util\ProcessExecutor;
use Composer\Test\TestCase;
use Composer\IO\BufferIO;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
class ProcessExecutorTest extends TestCase
@ -99,4 +104,13 @@ class ProcessExecutorTest extends TestCase
$this->assertEquals(array('foo', 'bar'), $process->splitLines("foo\r\nbar"));
$this->assertEquals(array('foo', 'bar'), $process->splitLines("foo\r\nbar\n"));
}
public function testConsoleIODoesNotFormatSymfonyConsoleStyle()
{
$output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
$process = new ProcessExecutor(new ConsoleIO(new ArrayInput([]), $output, new HelperSet([])));
$process->execute('echo \'<error>foo</error>\'');
$this->assertSame('<error>foo</error>'.PHP_EOL, $output->fetch());
}
}