Skip to content

Commit 0a0cb93

Browse files
[ci] Collect and replay skipped tests
1 parent 491c12c commit 0a0cb93

File tree

51 files changed

+289
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+289
-4
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ install:
4848
- if [ "$deps" != "skip" ] && [ "$deps" != "no" ]; then php .travis.php $TRAVIS_COMMIT_RANGE $TRAVIS_BRANCH $COMPONENTS; fi;
4949

5050
script:
51-
- if [ "$deps" = "no" ]; then echo "$COMPONENTS" | parallel --gnu 'echo -e "\\nRunning {} tests"; $PHPUNIT --exclude-group tty,benchmark,intl-data {}'; fi;
51+
- if [ "$deps" = "no" ]; then echo "$COMPONENTS" | parallel --gnu '$PHPUNIT --exclude-group tty,benchmark,intl-data {}'; fi;
5252
- if [ "$deps" = "no" ]; then echo -e "\\nRunning tests requiring tty"; $PHPUNIT --group tty; fi;
53-
- 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,legacy'; fi;
54-
- 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;
53+
- if [ "$deps" = "high" ]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer --prefer-source update; $PHPUNIT --exclude-group tty,benchmark,intl-data,legacy'; fi;
54+
- if [ "$deps" = "low" ]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer --prefer-source --prefer-lowest --prefer-stable update; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi;
5555
- if [ "$deps" = "skip" ]; then echo 'This matrix line is skipped for pull requests.'; fi;

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ init:
1414
- SET PHP=1
1515
- SET ANSICON=121x90 (121x90)
1616
- SET PHP_INI_MATRIX=php.ini-min php.ini-max
17+
- SET SYMFONY_PHPUNIT_SKIPPED_TESTS=phpunit.skipped
1718

1819
install:
1920
- IF EXIST c:\php (SET PHP=0) ELSE (mkdir c:\php)

phpunit

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")) {
2828
// Build a standalone phpunit without symfony/yaml
2929

3030
$oldPwd = getcwd();
31-
mkdir($PHPUNIT_DIR);
31+
@mkdir($PHPUNIT_DIR);
3232
chdir($PHPUNIT_DIR);
3333
if (extension_loaded('openssl') && ini_get('allow_url_fopen')) {
3434
stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb'));
@@ -41,7 +41,16 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")) {
4141
$zip->close();
4242
chdir("phpunit-$PHPUNIT_VERSION");
4343
passthru("$COMPOSER remove --no-update symfony/yaml");
44+
passthru("$COMPOSER require --no-update symfony/phpunit-bridge ~2.8");
4445
passthru("$COMPOSER install --prefer-source --no-progress --ansi");
46+
rename('./vendor/autoload.php', './vendor/autoload_real.php');
47+
file_put_contents('./vendor/autoload.php', <<<EOPHP
48+
<?php
49+
50+
\$loader = require __DIR__.'/autoload_real.php';
51+
\$loader->setPsr4('Symfony\Bridge\PhpUnit\\\\', array(dirname(dirname(dirname(__DIR__))).'/src/Symfony/Bridge/PhpUnit'));
52+
EOPHP
53+
);
4554
chdir($oldPwd);
4655
}
4756

@@ -80,6 +89,7 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
8089
$finder = new RecursiveIteratorIterator($finder);
8190
$finder->setMaxDepth(3);
8291

92+
$skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
8393
$runningProcs = array();
8494

8595
foreach ($finder as $file => $fileInfo) {
@@ -88,6 +98,10 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
8898

8999
// Run phpunit tests in parallel
90100

101+
if ($skippedTests) {
102+
putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
103+
}
104+
91105
$c = ProcessUtils::escapeArgument($component);
92106

93107
if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
@@ -139,6 +153,9 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
139153
}
140154
unlink($file);
141155
}
156+
if ($skippedTests) {
157+
unlink("$component/$skippedTests");
158+
}
142159

143160
if ($procStatus) {
144161
$exit = 1;

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@
4343
</exclude>
4444
</whitelist>
4545
</filter>
46+
47+
<listeners>
48+
<listener class="Symfony\Bridge\PhpUnit\SkippedTestsListener" />
49+
</listeners>
4650
</phpunit>

src/Symfony/Bridge/Doctrine/phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
</exclude>
2626
</whitelist>
2727
</filter>
28+
29+
<listeners>
30+
<listener class="Symfony\Bridge\PhpUnit\SkippedTestsListener" />
31+
</listeners>
2832
</phpunit>

src/Symfony/Bridge/Monolog/phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
</exclude>
2626
</whitelist>
2727
</filter>
28+
29+
<listeners>
30+
<listener class="Symfony\Bridge\PhpUnit\SkippedTestsListener" />
31+
</listeners>
2832
</phpunit>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit;
13+
14+
/**
15+
* Collects and replays skipped tests.
16+
*
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
class SkippedTestsListener extends \PHPUnit_Framework_BaseTestListener
20+
{
21+
private $state = -1;
22+
private $skippedFile = false;
23+
private $wasSkipped = array();
24+
private $isSkipped = array();
25+
26+
public function __destruct()
27+
{
28+
if (0 < $this->state) {
29+
file_put_contents($this->skippedFile, '<?php return '.var_export($this->isSkipped, true).';');
30+
}
31+
}
32+
33+
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
34+
{
35+
$suiteName = $suite->getName();
36+
37+
if (-1 === $this->state) {
38+
printf("\nTesting %s\n", $suiteName);
39+
$this->state = 0;
40+
41+
if ($this->skippedFile = getenv('SYMFONY_PHPUNIT_SKIPPED_TESTS')) {
42+
$this->state = 1;
43+
44+
if (file_exists($this->skippedFile)) {
45+
$this->state = 2;
46+
47+
if (!$this->wasSkipped = require $this->skippedFile) {
48+
exit("All tests already ran successfully.\n");
49+
}
50+
}
51+
}
52+
} elseif (2 === $this->state) {
53+
$skipped = array();
54+
foreach ($suite->tests() as $test) {
55+
if (!$test instanceof \PHPUnit_Framework_TestCase
56+
|| isset($this->wasSkipped[$suiteName]['*'])
57+
|| isset($this->wasSkipped[$suiteName][$test->getName()])) {
58+
$skipped[] = $test;
59+
}
60+
}
61+
$suite->setTests($skipped);
62+
}
63+
}
64+
65+
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
66+
{
67+
if (0 < $this->state) {
68+
if ($test instanceof \PHPUnit_Framework_TestCase) {
69+
$class = get_class($test);
70+
$method = $test->getName();
71+
} else {
72+
$class = $test->getName();
73+
$method = '*';
74+
}
75+
76+
$this->isSkipped[$class][$method] = 1;
77+
}
78+
}
79+
}

src/Symfony/Bridge/PhpUnit/phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
</exclude>
2626
</whitelist>
2727
</filter>
28+
29+
<listeners>
30+
<listener class="Symfony\Bridge\PhpUnit\SkippedTestsListener" />
31+
</listeners>
2832
</phpunit>

src/Symfony/Bridge/ProxyManager/phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626
</exclude>
2727
</whitelist>
2828
</filter>
29+
30+
<listeners>
31+
<listener class="Symfony\Bridge\PhpUnit\SkippedTestsListener" />
32+
</listeners>
2933
</phpunit>

src/Symfony/Bridge/Twig/phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626
</exclude>
2727
</whitelist>
2828
</filter>
29+
30+
<listeners>
31+
<listener class="Symfony\Bridge\PhpUnit\SkippedTestsListener" />
32+
</listeners>
2933
</phpunit>

0 commit comments

Comments
 (0)