|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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 <[email protected]> |
| 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 | + echo "Testing $suiteName\n"; |
| 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 | +} |
0 commit comments