Skip to content

Commit

Permalink
Closes #5178
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 7, 2023
1 parent 79f446b commit b4d036a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
</file>
<file src="src/Runner/TestResult/Collector.php">
<RedundantCondition>
<code>assert($testSuite instanceof TestSuiteForTestClass)</code>
<code>assert($testSuite instanceof TestSuiteForTestMethodWithDataProvider)</code>
</RedundantCondition>
</file>
<file src="src/Runner/TestSuiteLoader.php">
Expand Down
7 changes: 7 additions & 0 deletions ChangeLog-10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes of the PHPUnit 10.0 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.

## [10.0.6] - 2023-MM-DD

### Fixed

* [#5178](https://github.com/sebastianbergmann/phpunit/issues/5178): Test depending on a test with data provider is always skipped

## [10.0.5] - 2023-02-07

### Fixed
Expand Down Expand Up @@ -166,6 +172,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
* PHP 7.3, PHP 7.4, and PHP 8.0 are no longer supported
* `phpunit/php-code-coverage` [no longer supports PHPDBG and Xdebug 2](https://github.com/sebastianbergmann/php-code-coverage/blob/10.0.0/ChangeLog.md#1000---2023-02-03)

[10.0.6]: https://github.com/sebastianbergmann/phpunit/compare/10.0.5...10.0
[10.0.5]: https://github.com/sebastianbergmann/phpunit/compare/10.0.4...10.0.5
[10.0.4]: https://github.com/sebastianbergmann/phpunit/compare/10.0.3...10.0.4
[10.0.3]: https://github.com/sebastianbergmann/phpunit/compare/10.0.2...10.0.3
Expand Down
10 changes: 6 additions & 4 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,12 @@ final public function runBare(): void
$this->valueObjectForEvents(),
);

PassedTests::instance()->testMethodPassed(
$this->valueObjectForEvents(),
$this->testResult
);
if (!$this->usesDataProvider()) {
PassedTests::instance()->testMethodPassed(
$this->valueObjectForEvents(),
$this->testResult
);
}
}

$this->mockObjects = [];
Expand Down
28 changes: 24 additions & 4 deletions src/Runner/TestResult/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use function assert;
use function str_contains;
use PHPUnit\Event\Code\TestMethod;
use PHPUnit\Event\EventFacadeIsSealedException;
use PHPUnit\Event\Facade;
use PHPUnit\Event\Test\BeforeFirstTestMethodErrored;
Expand All @@ -30,13 +31,15 @@
use PHPUnit\Event\Test\PhpWarningTriggered;
use PHPUnit\Event\Test\Skipped as TestSkipped;
use PHPUnit\Event\Test\WarningTriggered;
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;
use PHPUnit\Event\TestRunner\DeprecationTriggered as TestRunnerDeprecationTriggered;
use PHPUnit\Event\TestRunner\ExecutionStarted;
use PHPUnit\Event\TestRunner\WarningTriggered as TestRunnerWarningTriggered;
use PHPUnit\Event\TestSuite\Finished as TestSuiteFinished;
use PHPUnit\Event\TestSuite\Skipped as TestSuiteSkipped;
use PHPUnit\Event\TestSuite\Started as TestSuiteStarted;
use PHPUnit\Event\TestSuite\TestSuiteForTestClass;
use PHPUnit\Event\TestSuite\TestSuiteForTestMethodWithDataProvider;
use PHPUnit\Event\UnknownSubscriberTypeException;

/**
Expand Down Expand Up @@ -266,19 +269,36 @@ public function testSuiteStarted(TestSuiteStarted $event): void
$this->currentTestSuiteForTestClassFailed = false;
}

/**
* @throws NoDataSetFromDataProviderException
*/
public function testSuiteFinished(TestSuiteFinished $event): void
{
if ($this->currentTestSuiteForTestClassFailed) {
return;
}

$testSuite = $event->testSuite();

if (!$testSuite->isForTestClass()) {
if ($testSuite->isWithName()) {
return;
}

assert($testSuite instanceof TestSuiteForTestClass);
if ($testSuite->isForTestMethodWithDataProvider()) {
assert($testSuite instanceof TestSuiteForTestMethodWithDataProvider);

if (!$this->currentTestSuiteForTestClassFailed) {
PassedTests::instance()->testClassPassed($testSuite->className());
$test = $testSuite->tests()->asArray()[0];

assert($test instanceof TestMethod);

PassedTests::instance()->testMethodPassed($test, null);

return;
}

assert($testSuite instanceof TestSuiteForTestClass);

PassedTests::instance()->testClassPassed($testSuite->className());
}

public function testPrepared(): void
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/TestResult/PassedTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testMethodPassed(TestMethod $test, mixed $returnValue): void
$test->methodName()
);

$this->passedTestMethods[$test->id()] = [
$this->passedTestMethods[$test->className() . '::' . $test->methodName()] = [
'returnValue' => $returnValue,
'size' => $size,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace PHPUnit\TestRunner\TestResult;

use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;
use PHPUnit\Event\TestSuite\Finished;
use PHPUnit\Event\TestSuite\FinishedSubscriber;

Expand All @@ -17,6 +18,9 @@
*/
final class TestSuiteFinishedSubscriber extends Subscriber implements FinishedSubscriber
{
/**
* @throws NoDataSetFromDataProviderException
*/
public function notify(Finished $event): void
{
$this->collector()->testSuiteFinished($event);
Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/regression/5178.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ $_SERVER['argv'][] = __DIR__ . '/5178/Issue5178Test.php';

require_once __DIR__ . '/../../bootstrap.php';
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--XFAIL--
https://github.com/sebastianbergmann/phpunit/issues/5178
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Expand Down

0 comments on commit b4d036a

Please sign in to comment.