From 8cd20d72562e121ccde78c43d12f1e2927279a93 Mon Sep 17 00:00:00 2001 From: Sebastian Feldmann Date: Fri, 7 Sep 2018 16:00:10 +0200 Subject: [PATCH 1/2] Add unit test to reproduce issue #3254 --- tests/unit/TextUI/TestRunnerTest.php | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/unit/TextUI/TestRunnerTest.php diff --git a/tests/unit/TextUI/TestRunnerTest.php b/tests/unit/TextUI/TestRunnerTest.php new file mode 100644 index 00000000000..b2f8bdf05b2 --- /dev/null +++ b/tests/unit/TextUI/TestRunnerTest.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TextUI; + +use PHPUnit\Framework\TestCase; + +class TestRunnerTest extends TestCase +{ + public function testTestIsRunnable() + { + $runner = new TestRunner(); + $runner->setPrinter($this->getResultPrinterMock()); + $runner->doRun(new \Success(), ['filter' => 'foo'], false); + } + + public function testSuiteIsRunnable() + { + $runner = new TestRunner(); + $runner->setPrinter($this->getResultPrinterMock()); + $runner->doRun($this->getSuiteMock(), ['filter' => 'foo'], false); + } + + /** + * @return \PHPUnit\TextUI\ResultPrinter + */ + private function getResultPrinterMock() + { + return $this->createMock(\PHPUnit\TextUI\ResultPrinter::class); + } + + /** + * @return \PHPUnit\Framework\TestSuite + */ + private function getSuiteMock() + { + $suite = $this->createMock(\PHPUnit\Framework\TestSuite::class); + $suite->expects($this->once())->method('injectFilter'); + $suite->expects($this->once())->method('run'); + + return $suite; + } +} From d8bdb500fddf6771502104b8a5bf786a4c9b3eb1 Mon Sep 17 00:00:00 2001 From: Sebastian Feldmann Date: Fri, 7 Sep 2018 16:01:37 +0200 Subject: [PATCH 2/2] Prevent failing filter handling on 'Test' instances Make sure the 'processSuiteFilters' method is only called for 'TestSuite' objects not for 'Test' objects. To achieve this, the 'processSuiteFilters' method call got moved to an existing type check. Fix issue #3254 --- src/TextUI/TestRunner.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TextUI/TestRunner.php b/src/TextUI/TestRunner.php index 17eeca5f3b7..f6719eca86d 100644 --- a/src/TextUI/TestRunner.php +++ b/src/TextUI/TestRunner.php @@ -190,8 +190,6 @@ public function doRun(Test $suite, array $arguments = [], $exit = true) $this->handleConfiguration($arguments); - $this->processSuiteFilters($suite, $arguments); - if (isset($arguments['bootstrap'])) { $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap']; } @@ -540,6 +538,7 @@ public function doRun(Test $suite, array $arguments = [], $exit = true) $result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']); if ($suite instanceof TestSuite) { + $this->processSuiteFilters($suite, $arguments); $suite->setRunTestInSeparateProcess($arguments['processIsolation']); }