Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove DataProviderTestSuite #5988

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions src/Event/Value/TestSuite/TestSuiteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@

use function assert;
use function class_exists;
use function explode;
use function method_exists;
use PHPUnit\Event\Code\Test;
use PHPUnit\Event\Code\TestCollection;
use PHPUnit\Event\RuntimeException;
use PHPUnit\Framework\DataProviderTestSuite;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite as FrameworkTestSuite;
use PHPUnit\Runner\PhptTestCase;
use ReflectionClass;
use ReflectionMethod;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand All @@ -39,31 +35,6 @@ public static function from(FrameworkTestSuite $testSuite): TestSuite

self::process($testSuite, $tests);

if ($testSuite instanceof DataProviderTestSuite) {
[$className, $methodName] = explode('::', $testSuite->name());

assert(class_exists($className));
assert($methodName !== '' && method_exists($className, $methodName));

$reflector = new ReflectionMethod($className, $methodName);

$file = $reflector->getFileName();
$line = $reflector->getStartLine();

assert($file !== false);
assert($line !== false);

return new TestSuiteForTestMethodWithDataProvider(
$testSuite->name(),
$testSuite->count(),
TestCollection::fromArray($tests),
$className,
$methodName,
$file,
$line,
);
}

if ($testSuite->isForTestClass()) {
$testClassName = $testSuite->name();

Expand Down
85 changes: 0 additions & 85 deletions src/Framework/DataProviderTestSuite.php

This file was deleted.

35 changes: 15 additions & 20 deletions src/Framework/TestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
*/
namespace PHPUnit\Framework;

use function array_merge;
use function assert;
use PHPUnit\Metadata\Api\DataProvider;
use PHPUnit\Metadata\Api\Groups;
use PHPUnit\Metadata\Api\Requirements;
use PHPUnit\Metadata\BackupGlobals;
use PHPUnit\Metadata\BackupStaticProperties;
Expand All @@ -36,8 +34,10 @@
* @param list<non-empty-string> $groups
*
* @throws InvalidDataProviderException
*
* @return list<Test>
*/
public function build(ReflectionClass $theClass, string $methodName, array $groups = []): Test
public function build(ReflectionClass $theClass, string $methodName, array $groups = []): array
{
$className = $theClass->getName();

Expand All @@ -48,7 +48,7 @@ public function build(ReflectionClass $theClass, string $methodName, array $grou
}

if ($data !== null) {
return $this->buildDataProviderTestSuite(
return $this->buildDataProviderTests(
$methodName,
$className,
$data,
Expand All @@ -70,7 +70,7 @@ public function build(ReflectionClass $theClass, string $methodName, array $grou
$this->backupSettings($className, $methodName),
);

return $test;
return [$test];
}

/**
Expand All @@ -79,35 +79,30 @@ public function build(ReflectionClass $theClass, string $methodName, array $grou
* @param array<list<mixed>> $data
* @param array{backupGlobals: ?bool, backupGlobalsExcludeList: list<string>, backupStaticProperties: ?bool, backupStaticPropertiesExcludeList: array<string,list<string>>} $backupSettings
* @param list<non-empty-string> $groups
*
* @return list<Test>
*/
private function buildDataProviderTestSuite(string $methodName, string $className, array $data, bool $runTestInSeparateProcess, ?bool $preserveGlobalState, bool $runClassInSeparateProcess, array $backupSettings, array $groups): DataProviderTestSuite
private function buildDataProviderTests(string $methodName, string $className, array $data, bool $runTestInSeparateProcess, ?bool $preserveGlobalState, bool $runClassInSeparateProcess, array $backupSettings, array $groups): array
{
$dataProviderTestSuite = DataProviderTestSuite::empty(
$className . '::' . $methodName,
);

$groups = array_merge(
$groups,
(new Groups)->groups($className, $methodName),
);
$tests = [];

foreach ($data as $_dataName => $_data) {
$_test = new $className($methodName);
foreach ($data as $dataName => $_data) {
$test = new $className($methodName);

$_test->setData($_dataName, $_data);
$test->setData($dataName, $_data);

$this->configureTestCase(
$_test,
$test,
$runTestInSeparateProcess,
$preserveGlobalState,
$runClassInSeparateProcess,
$backupSettings,
);

$dataProviderTestSuite->addTest($_test, $groups);
$tests[] = $test;
}

return $dataProviderTestSuite;
return $tests;
}

/**
Expand Down
26 changes: 14 additions & 12 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ protected function addTestMethod(ReflectionClass $class, ReflectionMethod $metho
assert(!empty($methodName));

try {
$test = (new TestBuilder)->build($class, $methodName, $groups);
$tests = (new TestBuilder)->build($class, $methodName, $groups);
} catch (InvalidDataProviderException $e) {
Event\Facade::emitter()->testTriggeredPhpunitError(
new TestMethod(
Expand All @@ -537,19 +537,21 @@ protected function addTestMethod(ReflectionClass $class, ReflectionMethod $metho
return;
}

if ($test instanceof TestCase || $test instanceof DataProviderTestSuite) {
$test->setDependencies(
Dependencies::dependencies($class->getName(), $methodName),
foreach ($tests as $test) {
if ($test instanceof TestCase) {
$test->setDependencies(
Dependencies::dependencies($class->getName(), $methodName),
);
}

$this->addTest(
$test,
array_merge(
$groups,
(new Groups)->groups($class->getName(), $methodName),
),
);
}

$this->addTest(
$test,
array_merge(
$groups,
(new Groups)->groups($class->getName(), $methodName),
),
);
}

private function clearCaches(): void
Expand Down
11 changes: 5 additions & 6 deletions src/Runner/TestSuiteSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use function max;
use function shuffle;
use function usort;
use PHPUnit\Framework\DataProviderTestSuite;
use PHPUnit\Framework\Reorderable;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -174,7 +173,7 @@
$suite->setTests($this->sortDefectsFirst($suite->tests()));
}

if ($resolveDependencies && !($suite instanceof DataProviderTestSuite)) {
if ($resolveDependencies) {
$tests = $suite->tests();

/** @noinspection PhpParamsInspection */
Expand Down Expand Up @@ -314,10 +313,10 @@
*/
private function cmpSize(Test $a, Test $b): int
{
$sizeA = ($a instanceof TestCase || $a instanceof DataProviderTestSuite)
$sizeA = $a instanceof TestCase

Check warning on line 316 in src/Runner/TestSuiteSorter.php

View check run for this annotation

Codecov / codecov/patch

src/Runner/TestSuiteSorter.php#L316

Added line #L316 was not covered by tests
? $a->size()->asString()
: 'unknown';
$sizeB = ($b instanceof TestCase || $b instanceof DataProviderTestSuite)
$sizeB = $b instanceof TestCase

Check warning on line 319 in src/Runner/TestSuiteSorter.php

View check run for this annotation

Codecov / codecov/patch

src/Runner/TestSuiteSorter.php#L319

Added line #L319 was not covered by tests
? $b->size()->asString()
: 'unknown';

Expand All @@ -335,9 +334,9 @@
* 3. If the test has dependencies but none left to do: mark done, start again from the top
* 4. When we reach the end add any leftover tests to the end. These will be marked 'skipped' during execution.
*
* @param array<DataProviderTestSuite|TestCase> $tests
* @param array<TestCase> $tests
*
* @return array<DataProviderTestSuite|TestCase>
* @return array<TestCase>
*/
private function resolveDependencies(array $tests): array
{
Expand Down
14 changes: 6 additions & 8 deletions tests/end-to-end/data-provider/log-junit-isolation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ unlink($logfile);
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="PHPUnit\TestFixture\DataProviderTest" file="%sDataProviderTest.php" tests="4" assertions="4" errors="0" failures="1" skipped="0" time="%f">
<testsuite name="PHPUnit\TestFixture\DataProviderTest::testAdd" tests="4" assertions="4" errors="0" failures="1" skipped="0" time="%f">
<testcase name="testAdd with data set #0" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%f"/>
<testcase name="testAdd with data set #1" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%f"/>
<testcase name="testAdd with data set #2" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%f">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\TestFixture\DataProviderTest::testAdd with data set #2%A
<testcase name="testAdd with data set #0" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%f"/>
<testcase name="testAdd with data set #1" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%f"/>
<testcase name="testAdd with data set #2" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%f">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\TestFixture\DataProviderTest::testAdd with data set #2%A
Failed asserting that 2 matches expected 3.
%A
%s:%i</failure>
</testcase>
<testcase name="testAdd with data set #3" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%f"/>
</testsuite>
</testcase>
<testcase name="testAdd with data set #3" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%f"/>
</testsuite>
</testsuites>
28 changes: 12 additions & 16 deletions tests/end-to-end/data-provider/log-junit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,26 @@ unlink($logfile);
<testsuites>
<testsuite name="CLI Arguments" tests="10" assertions="10" errors="0" failures="3" skipped="0" time="%s">
<testsuite name="PHPUnit\TestFixture\DataProviderTest" file="%sDataProviderTest.php" tests="4" assertions="4" errors="0" failures="1" skipped="0" time="%s">
<testsuite name="PHPUnit\TestFixture\DataProviderTest::testAdd" tests="4" assertions="4" errors="0" failures="1" skipped="0" time="%s">
<testcase name="testAdd with data set #0" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%s"/>
<testcase name="testAdd with data set #1" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%s"/>
<testcase name="testAdd with data set #2" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%s">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\TestFixture\DataProviderTest::testAdd with data set #2%A
<testcase name="testAdd with data set #0" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%s"/>
<testcase name="testAdd with data set #1" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%s"/>
<testcase name="testAdd with data set #2" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%s">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\TestFixture\DataProviderTest::testAdd with data set #2%A
Failed asserting that 2 matches expected 3.
%A
%sDataProviderTest.php:%d</failure>
</testcase>
<testcase name="testAdd with data set #3" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%s"/>
</testsuite>
</testcase>
<testcase name="testAdd with data set #3" file="%sDataProviderTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderTest" classname="PHPUnit.TestFixture.DataProviderTest" assertions="1" time="%s"/>
</testsuite>
<testsuite name="PHPUnit\TestFixture\DataProviderWithStringKeysTest" file="%sDataProviderWithStringKeysTest.php" tests="4" assertions="4" errors="0" failures="1" skipped="0" time="%s">
<testsuite name="PHPUnit\TestFixture\DataProviderWithStringKeysTest::testAdd" tests="4" assertions="4" errors="0" failures="1" skipped="0" time="%s">
<testcase name="testAdd with data set &quot;0 + 0 = 0&quot;" file="%sDataProviderWithStringKeysTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderWithStringKeysTest" classname="PHPUnit.TestFixture.DataProviderWithStringKeysTest" assertions="1" time="%s"/>
<testcase name="testAdd with data set &quot;0 + 1 = 1&quot;" file="%sDataProviderWithStringKeysTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderWithStringKeysTest" classname="PHPUnit.TestFixture.DataProviderWithStringKeysTest" assertions="1" time="%s"/>
<testcase name="testAdd with data set &quot;1 + 1 = 3&quot;" file="%sDataProviderWithStringKeysTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderWithStringKeysTest" classname="PHPUnit.TestFixture.DataProviderWithStringKeysTest" assertions="1" time="%s">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\TestFixture\DataProviderWithStringKeysTest::testAdd with data set "1 + 1 = 3"%A
<testcase name="testAdd with data set &quot;0 + 0 = 0&quot;" file="%sDataProviderWithStringKeysTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderWithStringKeysTest" classname="PHPUnit.TestFixture.DataProviderWithStringKeysTest" assertions="1" time="%s"/>
<testcase name="testAdd with data set &quot;0 + 1 = 1&quot;" file="%sDataProviderWithStringKeysTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderWithStringKeysTest" classname="PHPUnit.TestFixture.DataProviderWithStringKeysTest" assertions="1" time="%s"/>
<testcase name="testAdd with data set &quot;1 + 1 = 3&quot;" file="%sDataProviderWithStringKeysTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderWithStringKeysTest" classname="PHPUnit.TestFixture.DataProviderWithStringKeysTest" assertions="1" time="%s">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\TestFixture\DataProviderWithStringKeysTest::testAdd with data set "1 + 1 = 3"%A
Failed asserting that 2 matches expected 3.
%A
%sDataProviderWithStringKeysTest.php:%d</failure>
</testcase>
<testcase name="testAdd with data set &quot;1 + 0 = 1&quot;" file="%sDataProviderWithStringKeysTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderWithStringKeysTest" classname="PHPUnit.TestFixture.DataProviderWithStringKeysTest" assertions="1" time="%s"/>
</testsuite>
</testcase>
<testcase name="testAdd with data set &quot;1 + 0 = 1&quot;" file="%sDataProviderWithStringKeysTest.php" line="%d" class="PHPUnit\TestFixture\DataProviderWithStringKeysTest" classname="PHPUnit.TestFixture.DataProviderWithStringKeysTest" assertions="1" time="%s"/>
</testsuite>
<testcase name="success.phpt" file="%ssuccess.phpt" assertions="1" time="%s"/>
<testcase name="failure.phpt" file="%sfailure.phpt" assertions="1" time="%s">
Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/event/data-provider-external.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Test Runner Started
Test Suite Sorted
Test Runner Execution Started (2 tests)
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderExternalTest, 2 tests)
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderExternalTest::testSuccess, 2 tests)
Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderExternalTest::testSuccess#0)
Test Prepared (PHPUnit\TestFixture\Event\DataProviderExternalTest::testSuccess#0)
Test Passed (PHPUnit\TestFixture\Event\DataProviderExternalTest::testSuccess#0)
Expand All @@ -34,7 +33,6 @@ Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderExternalTest::te
Test Prepared (PHPUnit\TestFixture\Event\DataProviderExternalTest::testSuccess#1)
Test Passed (PHPUnit\TestFixture\Event\DataProviderExternalTest::testSuccess#1)
Test Finished (PHPUnit\TestFixture\Event\DataProviderExternalTest::testSuccess#1)
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderExternalTest::testSuccess, 2 tests)
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderExternalTest, 2 tests)
Test Runner Execution Finished
Test Runner Finished
Expand Down
Loading