Skip to content

Commit 0df822d

Browse files
minor symfony#15621 [appveyor] minor enhancements (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [appveyor] minor enhancements | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- ea9780e [appveyor] minor enhancements
2 parents 034c247 + ea9780e commit 0df822d

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

phpunit

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $PHPUNIT_VERSION = 4.8;
77
$PHPUNIT_DIR = __DIR__.'/.phpunit';
88

99
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")) {
10-
# Build a standalone phpunit without symfony/yaml
10+
// Build a standalone phpunit without symfony/yaml
1111

1212
$oldPwd = getcwd();
1313
mkdir($PHPUNIT_DIR);
@@ -31,7 +31,7 @@ $cmd = array_map('escapeshellarg', $argv);
3131
$exit = 0;
3232

3333
if (isset($argv[1]) && 'symfony' === $argv[1]) {
34-
# Find Symfony components in plain php for Windows portability
34+
// Find Symfony components in plain php for Windows portability
3535

3636
$finder = new RecursiveDirectoryIterator('src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
3737
$finder = new RecursiveIteratorIterator($finder);
@@ -45,7 +45,7 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
4545
if ('phpunit.xml.dist' === $file) {
4646
$component = dirname($fileInfo->getPathname());
4747

48-
# Run phpunit tests in parallel
48+
// Run phpunit tests in parallel
4949

5050
$c = escapeshellarg($component);
5151

@@ -58,20 +58,34 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
5858
}
5959
}
6060

61+
// Fixes for colors support on appveyor
62+
// See http://help.appveyor.com/discussions/suggestions/197-support-ansi-color-codes
63+
$colorFixes = array(
64+
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"),
65+
array("SS", "EE", "II", "FF"),
66+
);
67+
$colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]);
68+
$colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]);
69+
6170
foreach ($procs as $component => $proc) {
6271
$procStatus = proc_close($proc);
6372

6473
foreach (array('out', 'err') as $file) {
6574
$file = "$component/phpunit.std$file";
66-
$h = fopen($file, 'rb');
67-
while (false !== $line = fgets($h)) {
68-
echo preg_replace_callback(
69-
'/\033\[[0-9]++(?:;[0-9]++)++m/',
70-
function ($m) {return str_replace(';', "m\033[", $m[0]);},
71-
$line
72-
);
75+
76+
if ('\\' === DIRECTORY_SEPARATOR) {
77+
$h = fopen($file, 'rb');
78+
while (false !== $line = fgets($h)) {
79+
echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
80+
'/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
81+
"$1m\033[$2$3$4$4",
82+
$line
83+
));
84+
}
85+
fclose($h);
86+
} else {
87+
readfile($file);
7388
}
74-
fclose($h);
7589
unlink($file);
7690
}
7791

@@ -84,32 +98,28 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
8498
}
8599

86100
} elseif (!isset($argv[1]) || 'install' !== $argv[1]) {
87-
# Run regular phpunit in a subprocess
101+
// Run regular phpunit in a subprocess
88102

89103
$cmd[0] = "php $PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit --colors=always";
90104

91105
$errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.');
92106
if ($proc = proc_open(implode(' ', $cmd).' 2> '.escapeshellarg($errFile), array(1 => array('pipe', 'w')), $pipes)) {
93-
while (false !== $line = fgets($pipes[1])) {
94-
echo $line;
95-
}
107+
stream_copy_to_stream($pipes[1], STDOUT);
96108
fclose($pipes[1]);
97109
$exit = proc_close($proc);
98110

99-
$h = fopen($errFile, 'rb');
100-
while (false !== $line = fgets($h)) {
101-
echo $line;
102-
}
103-
fclose($h);
111+
readfile($errFile);
104112
unlink($errFile);
105113
}
106114

107-
if (file_exists($component = array_pop($argv))) {
108-
if ($exit) {
109-
echo "\033[41mKO\033[0m $component\n\n";
110-
} else {
111-
echo "\033[32mOK\033[0m $component\n\n";
112-
}
115+
if (!file_exists($component = array_pop($argv))) {
116+
$component = basename(getcwd());
117+
}
118+
119+
if ($exit) {
120+
echo "\033[41mKO\033[0m $component\n\n";
121+
} else {
122+
echo "\033[32mOK\033[0m $component\n\n";
113123
}
114124
}
115125

0 commit comments

Comments
 (0)