From 86b17e899c05b9c9e9accceea56e7044555169ae Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 25 Oct 2020 11:11:23 +0100 Subject: [PATCH] Closes #4491 --- ChangeLog-9.5.md | 1 + src/Framework/TestBuilder.php | 4 ++-- src/Framework/TestCase.php | 5 +++-- src/Framework/TestResult.php | 11 +++++++---- src/Runner/Filter/NameFilterIterator.php | 3 ++- src/Util/TestDox/ResultPrinter.php | 3 ++- tests/end-to-end/regression/GitHub/2137-filter.phpt | 10 +++++----- .../end-to-end/regression/GitHub/2137-no_filter.phpt | 12 ++++++------ tests/end-to-end/regression/GitHub/498.phpt | 10 +++++----- tests/end-to-end/regression/GitHub/765.phpt | 10 +++++----- 10 files changed, 38 insertions(+), 31 deletions(-) diff --git a/ChangeLog-9.5.md b/ChangeLog-9.5.md index 2646df236a3..d91fd1764e4 100644 --- a/ChangeLog-9.5.md +++ b/ChangeLog-9.5.md @@ -7,5 +7,6 @@ All notable changes of the PHPUnit 9.5 release series are documented in this fil ### Changed * [#4490](https://github.com/sebastianbergmann/phpunit/issues/4490): Emit Error instead of Warning when test case class cannot be instantiated +* [#4491](https://github.com/sebastianbergmann/phpunit/issues/4491): Emit Error instead of Warning when data provider does not work correctly [9.5.0]: https://github.com/sebastianbergmann/phpunit/compare/9.4...master diff --git a/src/Framework/TestBuilder.php b/src/Framework/TestBuilder.php index 92a57d02f8d..5dd91e2196b 100644 --- a/src/Framework/TestBuilder.php +++ b/src/Framework/TestBuilder.php @@ -99,7 +99,7 @@ public function build(ReflectionClass $theClass, string $methodName): Test $this->throwableToString($t) ); - $data = new WarningTestCase($message); + $data = new ErrorTestCase($message); } // Test method with @dataProvider. @@ -154,7 +154,7 @@ private function buildDataProviderTestSuite( $groups = TestUtil::getGroups($className, $methodName); - if ($data instanceof WarningTestCase || + if ($data instanceof ErrorTestCase || $data instanceof SkippedTestCase || $data instanceof IncompleteTestCase) { $dataProviderTestSuite->addTest($data, $groups); diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index db2833837c8..3f29bf406b0 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -736,11 +736,12 @@ public function run(TestResult $result = null): TestResult $result = $this->createResult(); } - if (!$this instanceof WarningTestCase) { + if (!$this instanceof ErrorTestCase && !$this instanceof WarningTestCase) { $this->setTestResultObject($result); } - if (!$this instanceof WarningTestCase && + if (!$this instanceof ErrorTestCase && + !$this instanceof WarningTestCase && !$this instanceof SkippedTestCase && !$this->handleDependencies()) { return $result; diff --git a/src/Framework/TestResult.php b/src/Framework/TestResult.php index a9c5d76b8b3..7b589a019c6 100644 --- a/src/Framework/TestResult.php +++ b/src/Framework/TestResult.php @@ -676,6 +676,7 @@ public function run(Test $test): void } $collectCodeCoverage = $this->codeCoverage !== null && + !$test instanceof ErrorTestCase && !$test instanceof WarningTestCase && $isAnyCoverageRequired; @@ -684,9 +685,10 @@ public function run(Test $test): void } $monitorFunctions = $this->beStrictAboutResourceUsageDuringSmallTests && - !$test instanceof WarningTestCase && - $test->getSize() === \PHPUnit\Util\Test::SMALL && - function_exists('xdebug_start_function_monitor'); + !$test instanceof ErrorTestCase && + !$test instanceof WarningTestCase && + $test->getSize() === \PHPUnit\Util\Test::SMALL && + function_exists('xdebug_start_function_monitor'); if ($monitorFunctions) { /* @noinspection ForgottenDebugOutputInspection */ @@ -699,7 +701,8 @@ function_exists('xdebug_start_function_monitor'); try { $invoker = new Invoker; - if (!$test instanceof WarningTestCase && + if (!$test instanceof ErrorTestCase && + !$test instanceof WarningTestCase && $this->enforceTimeLimit && ($this->defaultTimeLimit || $test->getSize() != \PHPUnit\Util\Test::UNKNOWN) && $invoker->canInvokeWithTimeout()) { diff --git a/src/Runner/Filter/NameFilterIterator.php b/src/Runner/Filter/NameFilterIterator.php index d90054d84c6..7057e1c470e 100644 --- a/src/Runner/Filter/NameFilterIterator.php +++ b/src/Runner/Filter/NameFilterIterator.php @@ -15,6 +15,7 @@ use function sprintf; use function str_replace; use Exception; +use PHPUnit\Framework\ErrorTestCase; use PHPUnit\Framework\TestSuite; use PHPUnit\Framework\WarningTestCase; use PHPUnit\Util\RegularExpression; @@ -64,7 +65,7 @@ public function accept(): bool $tmp = \PHPUnit\Util\Test::describe($test); - if ($test instanceof WarningTestCase) { + if ($test instanceof ErrorTestCase || $test instanceof WarningTestCase) { $name = $test->getMessage(); } elseif ($tmp[0] !== '') { $name = implode('::', $tmp); diff --git a/src/Util/TestDox/ResultPrinter.php b/src/Util/TestDox/ResultPrinter.php index feaee82d3a3..c4b63644fa2 100644 --- a/src/Util/TestDox/ResultPrinter.php +++ b/src/Util/TestDox/ResultPrinter.php @@ -12,6 +12,7 @@ use function get_class; use function in_array; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\ErrorTestCase; use PHPUnit\Framework\Test; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestSuite; @@ -313,7 +314,7 @@ private function isOfInterest(Test $test): bool return false; } - if ($test instanceof WarningTestCase) { + if ($test instanceof ErrorTestCase || $test instanceof WarningTestCase) { return false; } diff --git a/tests/end-to-end/regression/GitHub/2137-filter.phpt b/tests/end-to-end/regression/GitHub/2137-filter.phpt index d309208a5c7..37d58972f58 100644 --- a/tests/end-to-end/regression/GitHub/2137-filter.phpt +++ b/tests/end-to-end/regression/GitHub/2137-filter.phpt @@ -12,15 +12,15 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -W 1 / 1 (100%) +E 1 / 1 (100%) Time: %s, Memory: %s -There was 1 warning: +There was 1 error: -1) Warning +1) Error The data provider specified for Issue2137Test::testBrandService is invalid. Data set #0 is invalid. -WARNINGS! -Tests: 1, Assertions: 0, Warnings: 1. +ERRORS! +Tests: 1, Assertions: 0, Errors: 1. diff --git a/tests/end-to-end/regression/GitHub/2137-no_filter.phpt b/tests/end-to-end/regression/GitHub/2137-no_filter.phpt index f621bb36c6c..4d8f885655d 100644 --- a/tests/end-to-end/regression/GitHub/2137-no_filter.phpt +++ b/tests/end-to-end/regression/GitHub/2137-no_filter.phpt @@ -10,19 +10,19 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -WW 2 / 2 (100%) +EE 2 / 2 (100%) Time: %s, Memory: %s -There were 2 warnings: +There were 2 errors: -1) Warning +1) Error The data provider specified for Issue2137Test::testBrandService is invalid. Data set #0 is invalid. -2) Warning +2) Error The data provider specified for Issue2137Test::testSomethingElseInvalid is invalid. Data set #0 is invalid. -WARNINGS! -Tests: 2, Assertions: 0, Warnings: 2. +ERRORS! +Tests: 2, Assertions: 0, Errors: 2. diff --git a/tests/end-to-end/regression/GitHub/498.phpt b/tests/end-to-end/regression/GitHub/498.phpt index 71ac2f6f5d9..604c6d0d3e5 100644 --- a/tests/end-to-end/regression/GitHub/498.phpt +++ b/tests/end-to-end/regression/GitHub/498.phpt @@ -12,16 +12,16 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -W 1 / 1 (100%) +E 1 / 1 (100%) Time: %s, Memory: %s -There was 1 warning: +There was 1 error: -1) Warning +1) Error The data provider specified for Issue498Test::shouldBeFalse is invalid. Exception: Can't create the data %sIssue498Test.php:%d -WARNINGS! -Tests: 1, Assertions: 0, Warnings: 1. +ERRORS! +Tests: 1, Assertions: 0, Errors: 1. diff --git a/tests/end-to-end/regression/GitHub/765.phpt b/tests/end-to-end/regression/GitHub/765.phpt index 7c37776b889..86416d8bffd 100644 --- a/tests/end-to-end/regression/GitHub/765.phpt +++ b/tests/end-to-end/regression/GitHub/765.phpt @@ -10,16 +10,16 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -.W 2 / 2 (100%) +.E 2 / 2 (100%) Time: %s, Memory: %s -There was 1 warning: +There was 1 error: -1) Warning +1) Error The data provider specified for Issue765Test::testDependent is invalid. Exception: %sIssue765Test.php:%d -WARNINGS! -Tests: 2, Assertions: 1, Warnings: 1. +ERRORS! +Tests: 2, Assertions: 1, Errors: 1.