Skip to content

Commit 4b1f100

Browse files
Merge branch '10.5' into 11.5
2 parents 804ac91 + e28d9b1 commit 4b1f100

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

ChangeLog-11.5.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.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [11.5.30] - 2025-MM-DD
6+
7+
### Changed
8+
9+
* [#6300](https://github.com/sebastianbergmann/phpunit/issues/6300): Emit warning when the name of a data provider method begins with `test`
10+
511
## [11.5.29] - 2025-08-09
612

713
### Added
@@ -273,6 +279,7 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
273279
* [#6055](https://github.com/sebastianbergmann/phpunit/issues/6055): `assertNotContainsOnly()` (use `assertContainsNotOnlyArray()`, `assertContainsNotOnlyBool()`, `assertContainsNotOnlyCallable()`, `assertContainsNotOnlyFloat()`, `assertContainsNotOnlyInt()`, `assertContainsNotOnlyIterable()`, `assertContainsNotOnlyNumeric()`, `assertContainsNotOnlyObject()`, `assertContainsNotOnlyResource()`, `assertContainsNotOnlyClosedResource()`, `assertContainsNotOnlyScalar()`, or `assertContainsNotOnlyString()` instead)
274280
* [#6059](https://github.com/sebastianbergmann/phpunit/issues/6059): `containsOnly()` (use `containsOnlyArray()`, `containsOnlyBool()`, `containsOnlyCallable()`, `containsOnlyFloat()`, `containsOnlyInt()`, `containsOnlyIterable()`, `containsOnlyNumeric()`, `containsOnlyObject()`, `containsOnlyResource()`, `containsOnlyClosedResource()`, `containsOnlyScalar()`, or `containsOnlyString()` instead)
275281

282+
[11.5.30]: https://github.com/sebastianbergmann/phpunit/compare/11.5.29...11.5
276283
[11.5.29]: https://github.com/sebastianbergmann/phpunit/compare/11.5.28...11.5.29
277284
[11.5.28]: https://github.com/sebastianbergmann/phpunit/compare/11.5.27...11.5.28
278285
[11.5.27]: https://github.com/sebastianbergmann/phpunit/compare/11.5.26...11.5.27

src/Metadata/Api/DataProvider.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use function assert;
1616
use function explode;
1717
use function get_debug_type;
18+
use function is_a;
1819
use function is_array;
1920
use function is_int;
2021
use function is_string;
@@ -26,11 +27,13 @@
2627
use function rtrim;
2728
use function sprintf;
2829
use function str_replace;
30+
use function str_starts_with;
2931
use function strlen;
3032
use function substr;
3133
use function trim;
3234
use PHPUnit\Event;
3335
use PHPUnit\Framework\InvalidDataProviderException;
36+
use PHPUnit\Framework\TestCase;
3437
use PHPUnit\Metadata\DataProvider as DataProviderMetadata;
3538
use PHPUnit\Metadata\MetadataCollection;
3639
use PHPUnit\Metadata\Parser\Registry as MetadataRegistry;
@@ -107,6 +110,19 @@ private function dataProvidedByMethods(string $className, string $methodName, Me
107110
foreach ($dataProvider as $_dataProvider) {
108111
assert($_dataProvider instanceof DataProviderMetadata);
109112

113+
if (is_a($_dataProvider->className(), TestCase::class, true) &&
114+
str_starts_with($_dataProvider->methodName(), 'test')) {
115+
Event\Facade::emitter()->testRunnerTriggeredPhpunitWarning(
116+
sprintf(
117+
'The name of the data provider method %s::%s() used by test method %s::%s() begins with "test", therefore PHPUnit also treats it as a test method',
118+
$_dataProvider->className(),
119+
$_dataProvider->methodName(),
120+
$className,
121+
$methodName,
122+
),
123+
);
124+
}
125+
110126
$dataProviderMethod = new Event\Code\ClassMethod($_dataProvider->className(), $_dataProvider->methodName());
111127

112128
Event\Facade::emitter()->dataProviderMethodCalled(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class DataProviderMethodNameStartsWithTestTest extends TestCase
16+
{
17+
public static function testProvider(): array
18+
{
19+
return [[true]];
20+
}
21+
22+
#[DataProvider('testProvider')]
23+
public function testOne(bool $b): void
24+
{
25+
$this->assertTrue($b);
26+
}
27+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
phpunit ../../_files/DataProviderMethodNameStartsWithTestTest.php
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--debug';
8+
$_SERVER['argv'][] = __DIR__ . '/../../_files/DataProviderMethodNameStartsWithTestTest.php';
9+
10+
require_once __DIR__ . '/../../bootstrap.php';
11+
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit Started (PHPUnit %s using %s)
15+
Test Runner Configured
16+
Event Facade Sealed
17+
Test Runner Triggered Warning (The name of the data provider method PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testProvider() used by test method PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne() begins with "test", therefore PHPUnit also treats it as a test method)
18+
Data Provider Method Called (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testProvider for test method PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne)
19+
Data Provider Method Finished for PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne:
20+
- PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testProvider
21+
Test Suite Loaded (2 tests)
22+
Test Runner Started
23+
Test Suite Sorted
24+
Test Runner Execution Started (2 tests)
25+
Test Suite Started (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest, 2 tests)
26+
Test Preparation Started (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testProvider)
27+
Test Prepared (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testProvider)
28+
Test Passed (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testProvider)
29+
Test Considered Risky (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testProvider)
30+
This test did not perform any assertions
31+
Test Finished (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testProvider)
32+
Test Suite Started (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne, 1 test)
33+
Test Preparation Started (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne#0)
34+
Test Prepared (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne#0)
35+
Test Passed (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne#0)
36+
Test Finished (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne#0)
37+
Test Suite Finished (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest::testOne, 1 test)
38+
Test Suite Finished (PHPUnit\TestFixture\DataProviderMethodNameStartsWithTestTest, 2 tests)
39+
Test Runner Execution Finished
40+
Test Runner Finished
41+
PHPUnit Finished (Shell Exit Code: 1)

0 commit comments

Comments
 (0)