-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Warn on mix of different data providers #6273
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,25 @@ public function providedData(string $className, string $methodName): ?array | |
} | ||
|
||
if ($dataProvider->isNotEmpty()) { | ||
if ($testWith->isNotEmpty()) { | ||
$method = new ReflectionMethod($className, $methodName); | ||
|
||
Event\Facade::emitter()->testTriggeredPhpunitWarning( | ||
new TestMethod( | ||
$className, | ||
$methodName, | ||
$method->getFileName(), | ||
$method->getStartLine(), | ||
Event\Code\TestDoxBuilder::fromClassNameAndMethodName( | ||
$className, | ||
$methodName, | ||
), | ||
MetadataCollection::fromArray([]), | ||
Event\TestData\TestDataCollection::fromArray([]), | ||
), | ||
'Mixing #[DataProvider] and #[TestWith] attributes is not supported, only the data provided by #[DataProvider] will be used', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will be confusing when using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, didn't think about all these other types of providers. will adjust the wording. |
||
); | ||
} | ||
$data = $this->dataProvidedByMethods($className, $methodName, $dataProvider); | ||
} else { | ||
$data = $this->dataProvidedByMetadata($testWith); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\TestWith; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class TestWithAttributeAndDataProviderTest extends TestCase | ||
{ | ||
public static function provider(): iterable | ||
{ | ||
yield 'foo' => ['bar', 'baz']; | ||
} | ||
|
||
#[TestWith(['a', 'b'], 'foo')] | ||
#[DataProvider('provider')] | ||
public function testWithDifferentProviderTypes($one, $two): void | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
phpunit ../_files/TestWithAttributeAndDataProviderTest.php | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/../_files/TestWithAttributeAndDataProviderTest.php'; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: %s | ||
|
||
W 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
1 test triggered 1 PHPUnit warning: | ||
|
||
1) PHPUnit\TestFixture\TestWithAttributeAndDataProviderTest::testWithDifferentProviderTypes | ||
Mixing #[DataProvider] and #[TestWith] attributes is not supported, only the data provided by #[DataProvider] will be used | ||
|
||
%sTestWithAttributeAndDataProviderTest.php:%d | ||
|
||
OK, but there were issues! | ||
Tests: 1, Assertions: 1, PHPUnit Warnings: 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the right type of warning?