Skip to content

Commit e356166

Browse files
Merge branch '11.3'
2 parents a2a82e9 + dcf95a9 commit e356166

File tree

6 files changed

+114
-18
lines changed

6 files changed

+114
-18
lines changed

src/Framework/TestBuilder.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function assert;
1414
use PHPUnit\Metadata\Api\DataProvider;
1515
use PHPUnit\Metadata\Api\Groups;
16+
use PHPUnit\Metadata\Api\Requirements;
1617
use PHPUnit\Metadata\BackupGlobals;
1718
use PHPUnit\Metadata\BackupStaticProperties;
1819
use PHPUnit\Metadata\ExcludeGlobalVariableFromBackup;
@@ -40,10 +41,11 @@ public function build(ReflectionClass $theClass, string $methodName, array $grou
4041
{
4142
$className = $theClass->getName();
4243

43-
$data = (new DataProvider)->providedData(
44-
$className,
45-
$methodName,
46-
);
44+
$data = null;
45+
46+
if ((new Requirements)->requirementsNotSatisfiedFor($className, $methodName) === []) {
47+
$data = (new DataProvider)->providedData($className, $methodName);
48+
}
4749

4850
if ($data !== null) {
4951
return $this->buildDataProviderTestSuite(
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
use Exception;
13+
use PHPUnit\Framework\Attributes\DataProvider;
14+
use PHPUnit\Framework\Attributes\DataProviderExternal;
15+
use PHPUnit\Framework\Attributes\RequiresPhpunit;
16+
use PHPUnit\Framework\TestCase;
17+
18+
final class DataProviderRequiresPhpUnitTest extends TestCase
19+
{
20+
public static function providerThatThrows(): array
21+
{
22+
throw new Exception('Should have been skipped.');
23+
}
24+
25+
public static function validProvider(): array
26+
{
27+
return [[true], [true]];
28+
}
29+
30+
public function invalidProvider(): array
31+
{
32+
return [[true], [true]];
33+
}
34+
35+
#[RequiresPhpunit('< 10')]
36+
#[DataProvider('invalidProvider')]
37+
public function testWithInvalidDataProvider(bool $param): void
38+
{
39+
$this->assertTrue($param);
40+
}
41+
42+
#[RequiresPhpunit('>= 10')]
43+
#[DataProvider('validProvider')]
44+
public function testWithValidDataProvider(bool $param): void
45+
{
46+
$this->assertTrue($param);
47+
}
48+
49+
#[RequiresPhpunit('< 10')]
50+
#[DataProvider('providerThatThrows')]
51+
public function testWithDataProviderThatThrows(): void
52+
{
53+
}
54+
55+
#[RequiresPhpunit('< 10')]
56+
#[DataProviderExternal(self::class, 'providerThatThrows')]
57+
public function testWithDataProviderExternalThatThrows(): void
58+
{
59+
}
60+
}

tests/end-to-end/cli/group/size-groups-csv.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ There were 7 PHPUnit test runner warnings:
2020

2121
1) Using comma-separated values with --group is deprecated and will no longer work in PHPUnit 12. You can use --group multiple times instead.
2222

23-
2) Group name "small" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
23+
2) Group name "small" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
2424

25-
3) Group name "medium" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
25+
3) Group name "medium" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
2626

27-
4) Group name "large" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
27+
4) Group name "large" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
2828

29-
5) Group name "small" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
29+
5) Group name "small" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
3030

31-
6) Group name "medium" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
31+
6) Group name "medium" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
3232

33-
7) Group name "large" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
33+
7) Group name "large" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
3434

3535
No tests executed!

tests/end-to-end/cli/group/size-groups.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ Runtime: %s
2222

2323
There were 6 PHPUnit test runner warnings:
2424

25-
1) Group name "small" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
25+
1) Group name "small" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
2626

27-
2) Group name "medium" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
27+
2) Group name "medium" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
2828

29-
3) Group name "large" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
29+
3) Group name "large" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
3030

31-
4) Group name "small" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
31+
4) Group name "small" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
3232

33-
5) Group name "medium" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
33+
5) Group name "medium" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
3434

35-
6) Group name "large" is not allowed for class PHPUnit\TestFixture\SizeGroups\SizeGroupsTest
35+
6) Group name "large" is not allowed for method PHPUnit\TestFixture\SizeGroups\SizeGroupsTest::testOne
3636

3737
No tests executed!
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
phpunit ../../_files/DataProviderRequiresPhpUnitTest.php
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--display-skipped';
8+
$_SERVER['argv'][] = __DIR__ . '/../../_files/DataProviderRequiresPhpUnitTest.php';
9+
10+
require_once __DIR__ . '/../../bootstrap.php';
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
17+
S..SS 5 / 5 (100%)
18+
19+
Time: %s, Memory: %s
20+
21+
There were 3 skipped tests:
22+
23+
1) PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithInvalidDataProvider
24+
PHPUnit < 10 is required.
25+
26+
2) PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithDataProviderThatThrows
27+
PHPUnit < 10 is required.
28+
29+
3) PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithDataProviderExternalThatThrows
30+
PHPUnit < 10 is required.
31+
32+
OK, but some tests were skipped!
33+
Tests: 5, Assertions: 2, Skipped: 3.
34+

tests/end-to-end/generic/invalid-requirements.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Time: %s, Memory: %s
2020

2121
There were 2 PHPUnit test runner warnings:
2222

23-
1) Method PHPUnit\TestFixture\InvalidRequirementsTest::testInvalidVersionConstraint is annotated using an invalid version requirement: Version constraint ~~9.0 is not supported.
23+
1) Class PHPUnit\TestFixture\InvalidRequirementsTest is annotated using an invalid version requirement: Version constraint ~~9.0 is not supported.
2424

25-
2) Class PHPUnit\TestFixture\InvalidRequirementsTest is annotated using an invalid version requirement: Version constraint ~~9.0 is not supported.
25+
2) Method PHPUnit\TestFixture\InvalidRequirementsTest::testInvalidVersionConstraint is annotated using an invalid version requirement: Version constraint ~~9.0 is not supported.
2626

2727
WARNINGS!
2828
Tests: 1, Assertions: 1, Warnings: 2.

0 commit comments

Comments
 (0)