Skip to content

Commit 0e03860

Browse files
kubawerlossebastianbergmann
authored andcommitted
Add test to show incorrect behaviour
1 parent a66d142 commit 0e03860

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
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 DuplicateKeyDataProvidersTest extends TestCase
16+
{
17+
public static function dataProvider1(): iterable
18+
{
19+
return [
20+
'bar' => [1],
21+
];
22+
}
23+
24+
public static function dataProvider2(): iterable
25+
{
26+
return [
27+
'bar' => [2],
28+
];
29+
}
30+
31+
#[DataProvider('dataProvider1')]
32+
#[DataProvider('dataProvider2')]
33+
public function test($value): void
34+
{
35+
$this->assertSame(2, $value);
36+
}
37+
}

tests/unit/Metadata/Api/DataProviderTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\Attributes\Small;
1515
use PHPUnit\Framework\InvalidDataProviderException;
1616
use PHPUnit\Framework\TestCase;
17+
use PHPUnit\TestFixture\DuplicateKeyDataProvidersTest;
1718
use PHPUnit\TestFixture\DuplicateKeyDataProviderTest;
1819
use PHPUnit\TestFixture\MultipleDataProviderTest;
1920
use PHPUnit\TestFixture\VariousIterableDataProviderTest;
@@ -156,12 +157,24 @@ public function testWithVariousIterableNonStaticDataProviders(): void
156157
], $dataSets);
157158
}
158159

159-
public function testWithDuplicateKeyDataProviders(): void
160+
public function testWithDuplicateKeyDataProvider(): void
160161
{
161162
$this->expectException(InvalidDataProviderException::class);
162163
$this->expectExceptionMessage('The key "foo" has already been defined by a previous data provider');
163164

164165
/* @noinspection UnusedFunctionResultInspection */
165166
(new DataProvider)->providedData(DuplicateKeyDataProviderTest::class, 'test');
166167
}
168+
169+
public function testWithDuplicateKeyDataProviders(): void
170+
{
171+
$dataSets = (new DataProvider)->providedData(DuplicateKeyDataProvidersTest::class, 'test');
172+
173+
$this->assertSame(
174+
[
175+
'bar' => [2],
176+
],
177+
$dataSets,
178+
);
179+
}
167180
}

0 commit comments

Comments
 (0)