Skip to content

Commit 16fa0ad

Browse files
Merge branch '10.5' into 11.3
2 parents c64cc82 + 778e7d1 commit 16fa0ad

File tree

5 files changed

+109
-6
lines changed

5 files changed

+109
-6
lines changed

ChangeLog-11.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

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

5+
## [11.3.7] - 2024-MM-DD
6+
7+
### Changed
8+
9+
* [#5957](https://github.com/sebastianbergmann/phpunit/pull/5957): Skip data provider build when requirements are not satisfied
10+
511
## [11.3.6] - 2024-09-19
612

713
### Changed
@@ -75,6 +81,7 @@ All notable changes of the PHPUnit 11.3 release series are documented in this fi
7581
* [#5856](https://github.com/sebastianbergmann/phpunit/issues/5856): When the test runner is configured to fail on deprecations, notices, warnings, incomplete tests, or skipped tests then details for tests that triggered deprecations, notices, or warnings as well as tests that were marked as incomplete or skipped are always shown, respectively
7682
* [#5869](https://github.com/sebastianbergmann/phpunit/pull/5869): The configuration file generated using `--generate-configuration` now limits the export of arrays to 10 elements in order to improve performance
7783

84+
[11.3.7]: https://github.com/sebastianbergmann/phpunit/compare/11.3.6...11.3
7885
[11.3.6]: https://github.com/sebastianbergmann/phpunit/compare/11.3.5...11.3.6
7986
[11.3.5]: https://github.com/sebastianbergmann/phpunit/compare/11.3.4...11.3.5
8087
[11.3.4]: https://github.com/sebastianbergmann/phpunit/compare/11.3.3...11.3.4

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+
}
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)