Skip to content

Commit

Permalink
Closes #4491
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 25, 2020
1 parent b29ed05 commit 86b17e8
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 31 deletions.
1 change: 1 addition & 0 deletions ChangeLog-9.5.md
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/Framework/TestBuilder.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/Framework/TestCase.php
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions src/Framework/TestResult.php
Expand Up @@ -676,6 +676,7 @@ public function run(Test $test): void
}

$collectCodeCoverage = $this->codeCoverage !== null &&
!$test instanceof ErrorTestCase &&
!$test instanceof WarningTestCase &&
$isAnyCoverageRequired;

Expand All @@ -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 */
Expand All @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Runner/Filter/NameFilterIterator.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Util/TestDox/ResultPrinter.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions tests/end-to-end/regression/GitHub/2137-filter.phpt
Expand Up @@ -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.
12 changes: 6 additions & 6 deletions tests/end-to-end/regression/GitHub/2137-no_filter.phpt
Expand Up @@ -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.
10 changes: 5 additions & 5 deletions tests/end-to-end/regression/GitHub/498.phpt
Expand Up @@ -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.
10 changes: 5 additions & 5 deletions tests/end-to-end/regression/GitHub/765.phpt
Expand Up @@ -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: <no message>
%sIssue765Test.php:%d

WARNINGS!
Tests: 2, Assertions: 1, Warnings: 1.
ERRORS!
Tests: 2, Assertions: 1, Errors: 1.

0 comments on commit 86b17e8

Please sign in to comment.