Skip to content

Commit

Permalink
Merge branch '2.3' into 2.7
Browse files Browse the repository at this point in the history
* 2.3:
  [DependencyInjection] improved a comment for reading fluency
  [HttpKernel] change a class in tests to avoid depending on SQLite
  [ci] Display fastest results first when running tests in parallel
  [Yaml] Improve newline handling in folded scalar blocks
  • Loading branch information
fabpot committed Sep 30, 2015
2 parents 899c212 + 5e46485 commit f80e6c6
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 63 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -46,7 +46,7 @@ install:
- if [ "$deps" != "no" ]; then php .travis.php $TRAVIS_COMMIT_RANGE $TRAVIS_BRANCH $COMPONENTS; fi;

script:
- if [ "$deps" = "no" ]; then echo "$COMPONENTS" | parallel --gnu --keep-order 'echo -e "\\nRunning {} tests"; $PHPUNIT --exclude-group tty,benchmark,intl-data {}'; fi;
- if [ "$deps" = "no" ]; then echo "$COMPONENTS" | parallel --gnu 'echo -e "\\nRunning {} tests"; $PHPUNIT --exclude-group tty,benchmark,intl-data {}'; fi;
- if [ "$deps" = "no" ]; then echo -e "\\nRunning tests requiring tty"; $PHPUNIT --group tty; fi;
- if [ "$deps" = "high" ]; then echo "$COMPONENTS" | parallel --gnu --keep-order -j10% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi;
- if [ "$deps" = "low" ]; then echo "$COMPONENTS" | parallel --gnu --keep-order -j10% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source --prefer-lowest --prefer-stable update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi;
- if [ "$deps" = "high" ]; then echo "$COMPONENTS" | parallel --gnu -j10% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi;
- if [ "$deps" = "low" ]; then echo "$COMPONENTS" | parallel --gnu -j10% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source --prefer-lowest --prefer-stable update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi;
66 changes: 38 additions & 28 deletions phpunit
Expand Up @@ -33,13 +33,13 @@ $exit = 0;
if (isset($argv[1]) && 'symfony' === $argv[1]) {
// Find Symfony components in plain php for Windows portability

$finder = new RecursiveDirectoryIterator('src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
$finder = new RecursiveDirectoryIterator(__DIR__.'/src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
$finder = new RecursiveIteratorIterator($finder);
$finder->setMaxDepth(3);

array_shift($cmd);
$cmd[0] = "php $PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit --colors=always";
$procs = array();
$runningProcs = array();

foreach ($finder as $file => $fileInfo) {
if ('phpunit.xml.dist' === $file) {
Expand All @@ -50,7 +50,7 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
$c = escapeshellarg($component);

if ($proc = proc_open(implode(' ', $cmd)." $c > $c/phpunit.stdout 2> $c/phpunit.stderr", array(), $pipes)) {
$procs[$component] = $proc;
$runningProcs[$component] = $proc;
} else {
$exit = 1;
echo "\033[41mKO\033[0m $component\n\n";
Expand All @@ -59,44 +59,54 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
}

// Fixes for colors support on appveyor
// See http://help.appveyor.com/discussions/suggestions/197-support-ansi-color-codes
// See https://github.com/appveyor/ci/issues/373
$colorFixes = array(
array("S\033[0m\033[0m\033[36m\033[1mS", "E\033[0m\033[0m\033[31m\033[1mE", "I\033[0m\033[0m\033[33m\033[1mI", "F\033[0m\033[0m\033[41m\033[37mF"),
array("SS", "EE", "II", "FF"),
);
$colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]);
$colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]);

foreach ($procs as $component => $proc) {
$procStatus = proc_close($proc);

foreach (array('out', 'err') as $file) {
$file = "$component/phpunit.std$file";
while ($runningProcs) {
usleep(300000);
$terminatedProcs = array();
foreach ($runningProcs as $component => $proc) {
$procStatus = proc_get_status($proc);
if (!$procStatus['running']) {
$terminatedProcs[$component] = $procStatus['exitcode'];
unset($runningProcs[$component]);
proc_close($proc);
}
}

if ('\\' === DIRECTORY_SEPARATOR) {
$h = fopen($file, 'rb');
while (false !== $line = fgets($h)) {
echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
'/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
"$1m\033[$2$3$4$4",
$line
));
foreach ($terminatedProcs as $component => $procStatus) {
foreach (array('out', 'err') as $file) {
$file = "$component/phpunit.std$file";

if ('\\' === DIRECTORY_SEPARATOR) {
$h = fopen($file, 'rb');
while (false !== $line = fgets($h)) {
echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
'/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
"$1m\033[$2$3$4$4",
$line
));
}
fclose($h);
} else {
readfile($file);
}
fclose($h);
} else {
readfile($file);
unlink($file);
}
unlink($file);
}

if ($procStatus) {
$exit = 1;
echo "\033[41mKO\033[0m $component\n\n";
} else {
echo "\033[32mOK\033[0m $component\n\n";
if ($procStatus) {
$exit = 1;
echo "\033[41mKO\033[0m $component\n\n";
} else {
echo "\033[32mOK\033[0m $component\n\n";
}
}
}

} elseif (!isset($argv[1]) || 'install' !== $argv[1]) {
// Run regular phpunit in a subprocess

Expand Down
Expand Up @@ -21,7 +21,7 @@ class RecursiveDirectoryIteratorTest extends IteratorTestCase
public function testRewindOnFtp()
{
try {
$i = new RecursiveDirectoryIterator('ftp://ftp.mozilla.org/', \RecursiveDirectoryIterator::SKIP_DOTS);
$i = new RecursiveDirectoryIterator('ftp://speedtest.tele2.net/', \RecursiveDirectoryIterator::SKIP_DOTS);
} catch (\UnexpectedValueException $e) {
$this->markTestSkipped('Unsupported stream "ftp".');
}
Expand All @@ -37,14 +37,14 @@ public function testRewindOnFtp()
public function testSeekOnFtp()
{
try {
$i = new RecursiveDirectoryIterator('ftp://ftp.mozilla.org/', \RecursiveDirectoryIterator::SKIP_DOTS);
$i = new RecursiveDirectoryIterator('ftp://speedtest.tele2.net/', \RecursiveDirectoryIterator::SKIP_DOTS);
} catch (\UnexpectedValueException $e) {
$this->markTestSkipped('Unsupported stream "ftp".');
}

$contains = array(
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'README',
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'pub',
'ftp://speedtest.tele2.net'.DIRECTORY_SEPARATOR.'1000GB.zip',
'ftp://speedtest.tele2.net'.DIRECTORY_SEPARATOR.'100GB.zip',
);
$actual = array();

Expand Down
Expand Up @@ -17,11 +17,11 @@
* This extension sub-class provides first-class integration with the
* Config/Definition Component.
*
* You can use this as base class if you
* You can use this as base class if
*
* a) use the Config/Definition component for configuration
* b) your configuration class is named "Configuration" and
* c) the configuration class resides in the DependencyInjection sub-folder
* a) you use the Config/Definition component for configuration,
* b) your configuration class is named "Configuration", and
* c) the configuration class resides in the DependencyInjection sub-folder.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
Expand Down
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\HttpKernel\Tests\Profiler;

use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
use Symfony\Component\HttpKernel\Profiler\SqliteProfilerStorage;
use Symfony\Component\HttpKernel\Profiler\FileProfilerStorage;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -61,16 +61,12 @@ public function testFindWorksWithInvalidDates()

protected function setUp()
{
if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) {
$this->markTestSkipped('This test requires SQLite support in your environment');
}

$this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
if (file_exists($this->tmp)) {
@unlink($this->tmp);
}

$this->storage = new SqliteProfilerStorage('sqlite:'.$this->tmp);
$this->storage = new FileProfilerStorage('file:'.$this->tmp);
$this->storage->purge();
}

Expand Down
40 changes: 24 additions & 16 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -20,7 +20,9 @@
*/
class Parser
{
const FOLDED_SCALAR_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';
const BLOCK_SCALAR_HEADER_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';
// BC - wrongly named
const FOLDED_SCALAR_PATTERN = self::BLOCK_SCALAR_HEADER_PATTERN;

private $offset = 0;
private $lines = array();
Expand Down Expand Up @@ -373,8 +375,8 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)

$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);

// Comments must not be removed inside a string block (ie. after a line ending with "|")
$removeCommentsPattern = '~'.self::FOLDED_SCALAR_PATTERN.'$~';
// Comments must not be removed inside a block scalar
$removeCommentsPattern = '~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~';
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);

while ($this->moveToNextLine()) {
Expand Down Expand Up @@ -464,10 +466,10 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport, $ob
return $this->refs[$value];
}

if (preg_match('/^'.self::FOLDED_SCALAR_PATTERN.'$/', $value, $matches)) {
if (preg_match('/^'.self::BLOCK_SCALAR_HEADER_PATTERN.'$/', $value, $matches)) {
$modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';

return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers));
return $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers));
}

try {
Expand All @@ -481,15 +483,15 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport, $ob
}

/**
* Parses a folded scalar.
* Parses a block scalar.
*
* @param string $separator The separator that was used to begin this folded scalar (| or >)
* @param string $indicator The indicator that was used to begin this folded scalar (+ or -)
* @param int $indentation The indentation that was used to begin this folded scalar
* @param string $style The style indicator that was used to begin this block scalar (| or >)
* @param string $chomping The chomping indicator that was used to begin this block scalar (+ or -)
* @param int $indentation The indentation indicator that was used to begin this block scalar
*
* @return string The text value
*/
private function parseFoldedScalar($separator, $indicator = '', $indentation = 0)
private function parseBlockScalar($style, $chomping = '', $indentation = 0)
{
$notEOF = $this->moveToNextLine();
if (!$notEOF) {
Expand Down Expand Up @@ -544,17 +546,23 @@ private function parseFoldedScalar($separator, $indicator = '', $indentation = 0
$this->moveToPreviousLine();
}

// replace all non-trailing single newlines with spaces in folded blocks
if ('>' === $separator) {
// folded style
if ('>' === $style) {
// folded lines
// replace all non-leading/non-trailing single newlines with spaces
preg_match('/(\n*)$/', $text, $matches);
$text = preg_replace('/(?<!\n)\n(?!\n)/', ' ', rtrim($text, "\n"));
$text = preg_replace('/(?<!\n|^)\n(?!\n)/', ' ', rtrim($text, "\n"));
$text .= $matches[1];

// empty separation lines
// remove one newline from each group of non-leading/non-trailing newlines
$text = preg_replace('/[^\n]\n+\K\n(?=[^\n])/', '', $text);
}

// deal with trailing newlines as indicated
if ('' === $indicator) {
// deal with trailing newlines
if ('' === $chomping) {
$text = preg_replace('/\n+$/', "\n", $text);
} elseif ('-' === $indicator) {
} elseif ('-' === $chomping) {
$text = preg_replace('/\n+$/', '', $text);
}

Expand Down
18 changes: 16 additions & 2 deletions src/Symfony/Component/Yaml/Tests/Fixtures/sfTests.yml
Expand Up @@ -51,9 +51,9 @@ php: |
'~',
)
---
test: Empty lines in folded blocks
test: Empty lines in literal blocks
brief: >
Empty lines in folded blocks
Empty lines in literal blocks
yaml: |
foo:
bar: |
Expand All @@ -65,6 +65,20 @@ yaml: |
php: |
array('foo' => array('bar' => "foo\n\n\n \nbar\n"))
---
test: Empty lines in folded blocks
brief: >
Empty lines in folded blocks
yaml: |
foo:
bar: >
foo
bar
php: |
array('foo' => array('bar' => "\nfoo\n\nbar\n"))
---
test: IP addresses
brief: >
IP addresses
Expand Down

0 comments on commit f80e6c6

Please sign in to comment.