Commit eafa3a2a authored by catch's avatar catch

Issue #2533360 by hussainweb: Upgrade to Symfony 2.7.2

parent 3ed1ebc8
This diff is collapsed.
This diff is collapsed.
......@@ -77,12 +77,11 @@ public function __construct($name, $value, $expires = null, $path = null, $domai
if (null !== $expires) {
$timestampAsDateTime = \DateTime::createFromFormat('U', $expires);
if (false === $timestampAsDateTime) {
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $expires);
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.', $expires));
}
$this->expires = $timestampAsDateTime->getTimestamp();
}
}
/**
......
......@@ -22,7 +22,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
public function prepare_workspace()
{
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000);
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().mt_rand(0, 1000);
mkdir($this->workspace, 0777, true);
$this->workspace = realpath($this->workspace);
}
......
......@@ -20,8 +20,6 @@ class LegacyApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
if (!extension_loaded('apc')) {
$this->markTestSkipped('The apc extension is not available.');
}
......
......@@ -18,11 +18,6 @@
*/
class LegacyUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
}
/**
* @dataProvider getLoadClassTests
*/
......
......@@ -1142,7 +1142,7 @@ private function splitStringByWidth($string, $width)
$lines[] = str_pad($line, $width);
$line = $char;
}
if (strlen($line)) {
if ('' !== $line) {
$lines[] = count($lines) ? str_pad($line, $width) : $line;
}
......
......@@ -40,7 +40,7 @@ protected function describeInputArgument(InputArgument $argument, array $options
$totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName());
$spacingWidth = $totalWidth - strlen($argument->getName()) + 2;
$this->writeText(sprintf(" <info>%s</info>%s%s%s",
$this->writeText(sprintf(' <info>%s</info>%s%s%s',
$argument->getName(),
str_repeat(' ', $spacingWidth),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
......@@ -77,7 +77,7 @@ protected function describeInputOption(InputOption $option, array $options = arr
$spacingWidth = $totalWidth - strlen($synopsis) + 2;
$this->writeText(sprintf(" <info>%s</info>%s%s%s%s",
$this->writeText(sprintf(' <info>%s</info>%s%s%s%s',
$synopsis,
str_repeat(' ', $spacingWidth),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
......@@ -207,7 +207,7 @@ protected function describeApplication(Application $application, array $options
foreach ($namespace['commands'] as $name) {
$this->writeText("\n");
$spacingWidth = $width - strlen($name);
$this->writeText(sprintf(" <info>%s</info>%s%s", $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
}
}
......@@ -266,7 +266,8 @@ private function calculateTotalWidthForOptions($options)
{
$totalWidth = 0;
foreach ($options as $option) {
$nameLength = 4 + strlen($option->getName()) + 2; // - + shortcut + , + whitespace + name + --
// "-" + shortcut + ", --" + name
$nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + strlen($option->getName());
if ($option->acceptValue()) {
$valueLength = 1 + strlen($option->getName()); // = + value
......
......@@ -33,7 +33,7 @@ class OutputFormatter implements OutputFormatterInterface
*/
public static function escape($text)
{
return preg_replace('/([^\\\\]?)</is', '$1\\<', $text);
return preg_replace('/([^\\\\]?)</', '$1\\<', $text);
}
/**
......@@ -146,7 +146,7 @@ public function format($message)
$offset = 0;
$output = '';
$tagRegex = '[a-z][a-z0-9_=;-]*';
preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#isx", $message, $matches, PREG_OFFSET_CAPTURE);
preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
foreach ($matches[0] as $i => $match) {
$pos = $match[1];
$text = $match[0];
......
......@@ -29,6 +29,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
'magenta' => array('set' => 35, 'unset' => 39),
'cyan' => array('set' => 36, 'unset' => 39),
'white' => array('set' => 37, 'unset' => 39),
'default' => array('set' => 39, 'unset' => 39),
);
private static $availableBackgroundColors = array(
'black' => array('set' => 40, 'unset' => 49),
......@@ -39,6 +40,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
'magenta' => array('set' => 45, 'unset' => 49),
'cyan' => array('set' => 46, 'unset' => 49),
'white' => array('set' => 47, 'unset' => 49),
'default' => array('set' => 49, 'unset' => 49),
);
private static $availableOptions = array(
'bold' => array('set' => 1, 'unset' => 22),
......
......@@ -20,7 +20,7 @@
*/
class DebugFormatterHelper extends Helper
{
private $colors = array('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white');
private $colors = array('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default');
private $started = array();
private $count = -1;
......
......@@ -466,18 +466,18 @@ private function hasSttyAvailable()
*/
private function validateAttempts($interviewer, OutputInterface $output, $validator, $attempts)
{
$error = null;
$e = null;
while (false === $attempts || $attempts--) {
if (null !== $error) {
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
if (null !== $e) {
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($e->getMessage(), 'error'));
}
try {
return call_user_func($validator, $interviewer());
} catch (\Exception $error) {
} catch (\Exception $e) {
}
}
throw $error;
throw $e;
}
}
......@@ -374,7 +374,7 @@ public function setCurrent($step)
}
/**
* Sets whether to overwrite the progressbar, false for new line
* Sets whether to overwrite the progressbar, false for new line.
*
* @param bool $overwrite
*/
......@@ -401,8 +401,8 @@ public function setProgress($step)
$this->max = $step;
}
$prevPeriod = intval($this->step / $this->redrawFreq);
$currPeriod = intval($step / $this->redrawFreq);
$prevPeriod = (int) ($this->step / $this->redrawFreq);
$currPeriod = (int) ($step / $this->redrawFreq);
$this->step = $step;
$this->percent = $this->max ? (float) $this->step / $this->max : 0;
if ($prevPeriod !== $currPeriod || $this->max === $step) {
......
......@@ -171,7 +171,7 @@ public function addRow($row)
if ($row instanceof TableSeparator) {
$this->rows[] = $row;
return;
return $this;
}
if (!is_array($row)) {
......
......@@ -221,7 +221,7 @@ private function addLongOption($name, $value)
}
if (null !== $value && !$option->acceptValue()) {
throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name, $value));
throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
}
if (null === $value && $option->acceptValue() && count($this->parsed)) {
......
......@@ -30,6 +30,9 @@
*/
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
{
/**
* @var StreamOutput
*/
private $stderr;
/**
......@@ -43,14 +46,12 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
*/
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
{
$outputStream = 'php://stdout';
if (!$this->hasStdoutSupport()) {
$outputStream = 'php://output';
}
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
$this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $this->getFormatter());
$this->stderr = new StreamOutput(fopen($errorStream, 'w'), $verbosity, $decorated, $this->getFormatter());
}
/**
......@@ -100,14 +101,32 @@ public function setErrorOutput(OutputInterface $error)
* Returns true if current environment supports writing console output to
* STDOUT.
*
* IBM iSeries (OS400) exhibits character-encoding issues when writing to
* STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
* output.
*
* @return bool
*/
protected function hasStdoutSupport()
{
return ('OS400' != php_uname('s'));
return false === $this->isRunningOS400();
}
/**
* Returns true if current environment supports writing console output to
* STDERR.
*
* @return bool
*/
protected function hasStderrSupport()
{
return false === $this->isRunningOS400();
}
/**
* Checks if current executing environment is IBM iSeries (OS400), which
* doesn't properly convert character-encodings between ASCII to EBCDIC.
*
* @return bool
*/
private function isRunningOS400()
{
return 'OS400' === php_uname('s');
}
}
......@@ -161,7 +161,8 @@ private function getDefaultValidator()
if (false === $result) {
throw new \InvalidArgumentException(sprintf($errorMessage, $value));
}
array_push($multiselectChoices, (string) $result);
$multiselectChoices[] = $choices[(string) $result];
}
if ($multiselect) {
......
......@@ -206,7 +206,7 @@ private function readline()
} else {
$this->output->write($this->getPrompt());
$line = fgets(STDIN, 1024);
$line = (!$line && strlen($line) == 0) ? false : rtrim($line);
$line = (false === $line || '' === $line) ? false : rtrim($line);
}
return $line;
......
......@@ -495,8 +495,6 @@ public function testSetCatchExceptions()
*/
public function testLegacyAsText()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$application = new Application();
$application->add(new \FooCommand());
$this->ensureStaticCommandHelp($application);
......@@ -509,8 +507,6 @@ public function testLegacyAsText()
*/
public function testLegacyAsXml()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$application = new Application();
$application->add(new \FooCommand());
$this->ensureStaticCommandHelp($application);
......@@ -679,7 +675,7 @@ public function testRun()
}
/**
* Issue #9285
* Issue #9285.
*
* If the "verbose" option is just before an argument in ArgvInput,
* an argument value should not be treated as verbosity value.
......
......@@ -314,8 +314,6 @@ public function callableMethodCommand(InputInterface $input, OutputInterface $ou
*/
public function testLegacyAsText()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$command = new \TestCommand();
$command->setApplication(new Application());
$tester = new CommandTester($command);
......@@ -328,8 +326,6 @@ public function testLegacyAsText()
*/
public function testLegacyAsXml()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$command = new \TestCommand();
$command->setApplication(new Application());
$tester = new CommandTester($command);
......
......@@ -42,6 +42,7 @@ public static function getInputOptions()
'input_option_3' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description'),
'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()),
'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"),
'input_option_6' => new InputOption('option_name', array('o', 'O'), InputOption::VALUE_REQUIRED, 'option with multiple shortcuts'),
);
}
......
{"name":"--option_name","shortcut":"-o|-O","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"option with multiple shortcuts","default":null}
**option_name:**
* Name: `--option_name`
* Shortcut: `-o|-O`
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: option with multiple shortcuts
* Default: `NULL`
<info>-o|O, --option_name=OPTION_NAME</info> option with multiple shortcuts
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" shortcuts="-o|-O" accept_value="1" is_value_required="1" is_multiple="0">
<description>option with multiple shortcuts</description>
<defaults/>
</option>
......@@ -37,6 +37,9 @@ public function testForeground()
$style->setForeground('blue');
$this->assertEquals("\033[34mfoo\033[39m", $style->apply('foo'));
$style->setForeground('default');
$this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo'));
$this->setExpectedException('InvalidArgumentException');
$style->setForeground('undefined-color');
}
......@@ -51,6 +54,9 @@ public function testBackground()
$style->setBackground('yellow');
$this->assertEquals("\033[43mfoo\033[49m", $style->apply('foo'));
$style->setBackground('default');
$this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo'));
$this->setExpectedException('InvalidArgumentException');
$style->setBackground('undefined-color');
}
......
......@@ -22,11 +22,6 @@
*/
class LegacyDialogHelperTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
}
public function testSelect()
{
$dialog = new DialogHelper();
......
......@@ -19,11 +19,6 @@
*/
class LegacyProgressHelperTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
}
public function testAdvance()
{
$progress = new ProgressHelper();
......
......@@ -23,7 +23,6 @@ class LegacyTableHelperTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$this->stream = fopen('php://memory', 'r+');
}
......
......@@ -13,7 +13,6 @@
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Process\Process;
......@@ -59,7 +58,7 @@ public function provideCommandsAndOutput()
EOT;
$successOutputDebugWithTags = <<<EOT
RUN php -r "echo \"<info>42</info>\";"
RUN php -r "echo '<info>42</info>';"
OUT <info>42</info>
RES Command ran successfully
......@@ -92,7 +91,7 @@ public function provideCommandsAndOutput()
array('', 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERBOSE, null),
array($successOutputVerbose, 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERY_VERBOSE, null),
array($successOutputDebug, 'php -r "echo 42;"', StreamOutput::VERBOSITY_DEBUG, null),
array($successOutputDebugWithTags, 'php -r "echo \"<info>42</info>\";"', StreamOutput::VERBOSITY_DEBUG, null),
array($successOutputDebugWithTags, 'php -r "echo \'<info>42</info>\';"', StreamOutput::VERBOSITY_DEBUG, null),
array('', 'php -r "syntax error"', StreamOutput::VERBOSITY_VERBOSE, null),
array($syntaxErrorOutputVerbose, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERY_VERBOSE, null),
array($syntaxErrorOutputDebug, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_DEBUG, null),
......
......@@ -323,17 +323,17 @@ public function testNonDecoratedOutput()
rewind($output->getStream());
$this->assertEquals(
" 0/200 [>---------------------------] 0%\n".
" 20/200 [==>-------------------------] 10%\n".
" 40/200 [=====>----------------------] 20%\n".
" 60/200 [========>-------------------] 30%\n".
" 80/200 [===========>----------------] 40%\n".
" 100/200 [==============>-------------] 50%\n".
" 120/200 [================>-----------] 60%\n".
" 140/200 [===================>--------] 70%\n".
" 160/200 [======================>-----] 80%\n".
" 180/200 [=========================>--] 90%\n".
" 200/200 [============================] 100%",
' 0/200 [>---------------------------] 0%'.PHP_EOL.
' 20/200 [==>-------------------------] 10%'.PHP_EOL.
' 40/200 [=====>----------------------] 20%'.PHP_EOL.
' 60/200 [========>-------------------] 30%'.PHP_EOL.
' 80/200 [===========>----------------] 40%'.PHP_EOL.
' 100/200 [==============>-------------] 50%'.PHP_EOL.
' 120/200 [================>-----------] 60%'.PHP_EOL.
' 140/200 [===================>--------] 70%'.PHP_EOL.
' 160/200 [======================>-----] 80%'.PHP_EOL.
' 180/200 [=========================>--] 90%'.PHP_EOL.
' 200/200 [============================] 100%',
stream_get_contents($output->getStream())
);
}
......@@ -349,9 +349,9 @@ public function testNonDecoratedOutputWithClear()
rewind($output->getStream());
$this->assertEquals(
" 0/50 [>---------------------------] 0%\n".
" 25/50 [==============>-------------] 50%\n".
" 50/50 [============================] 100%",
' 0/50 [>---------------------------] 0%'.PHP_EOL.
' 25/50 [==============>-------------] 50%'.PHP_EOL.
' 50/50 [============================] 100%',
stream_get_contents($output->getStream())
);
}
......@@ -364,8 +364,8 @@ public function testNonDecoratedOutputWithoutMax()
rewind($output->getStream());
$this->assertEquals(
" 0 [>---------------------------]\n".
" 1 [->--------------------------]",
' 0 [>---------------------------]'.PHP_EOL.
' 1 [->--------------------------]',
stream_get_contents($output->getStream())
);
}
......@@ -500,7 +500,7 @@ public function testAnsiColorsAndEmojis()
$mem = 100000 * $i;
$colors = $i++ ? '41;37' : '44;37';
return "\033[".$colors."m ".Helper::formatMemory($mem)." \033[0m";
return "\033[".$colors.'m '.Helper::formatMemory($mem)." \033[0m";
});
$bar->setFormat(" \033[44;37m %title:-37s% \033[0m\n %current%/%max% %bar% %percent:3s%%\n 🏁 %remaining:-10s% %memory:37s%");
$bar->setBarCharacter($done = "\033[32m●\033[0m");
......@@ -518,17 +518,17 @@ public function testAnsiColorsAndEmojis()
$this->assertEquals(
$this->generateOutput(
" \033[44;37m Starting the demo... fingers crossed \033[0m\n".
" 0/15 ".$progress.str_repeat($empty, 26)." 0%\n".
' 0/15 '.$progress.str_repeat($empty, 26)." 0%\n".
" \xf0\x9f\x8f\x81 1 sec \033[44;37m 0 B \033[0m"
).
$this->generateOutput(
" \033[44;37m Looks good to me... \033[0m\n".
" 4/15 ".str_repeat($done, 7).$progress.str_repeat($empty, 19)." 26%\n".
' 4/15 '.str_repeat($done, 7).$progress.str_repeat($empty, 19)." 26%\n".
" \xf0\x9f\x8f\x81 1 sec \033[41;37m 97 KiB \033[0m"
).
$this->generateOutput(
" \033[44;37m Thanks, bye \033[0m\n".
" 15/15 ".str_repeat($done, 28)." 100%\n".
' 15/15 '.str_repeat($done, 28)." 100%\n".
" \xf0\x9f\x8f\x81 1 sec \033[41;37m 195 KiB \033[0m"
),
stream_get_contents($output->getStream())
......@@ -570,7 +570,7 @@ public function testFormatsWithoutMax($format)
}
/**
* Provides each defined format
* Provides each defined format.
*
* @return array
*/
......
......@@ -180,10 +180,10 @@ public function testRenderProvider()
array(
array('ISBN', 'Title', 'Author'),
array(
array("99921-58-10-7", "Divine\nComedy", "Dante Alighieri"),
array("9971-5-0210-2", "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."),
array("9971-5-0210-2", "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."),
array("960-425-059-0", "The Lord of the Rings", "J. R. R.\nTolkien"),
array('99921-58-10-7', "Divine\nComedy", 'Dante Alighieri'),
array('9971-5-0210-2', "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."),
array('9971-5-0210-2', "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."),
array('960-425-059-0', 'The Lord of the Rings', "J. R. R.\nTolkien"),
),