File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 14
14
use PHPUnit \Framework \Attributes \Small ;
15
15
use PHPUnit \Framework \InvalidDataProviderException ;
16
16
use PHPUnit \Framework \TestCase ;
17
+ use PHPUnit \TestFixture \DuplicateKeyDataProvidersTest ;
17
18
use PHPUnit \TestFixture \DuplicateKeyDataProviderTest ;
18
19
use PHPUnit \TestFixture \MultipleDataProviderTest ;
19
20
use PHPUnit \TestFixture \VariousIterableDataProviderTest ;
@@ -156,12 +157,24 @@ public function testWithVariousIterableNonStaticDataProviders(): void
156
157
], $ dataSets );
157
158
}
158
159
159
- public function testWithDuplicateKeyDataProviders (): void
160
+ public function testWithDuplicateKeyDataProvider (): void
160
161
{
161
162
$ this ->expectException (InvalidDataProviderException::class);
162
163
$ this ->expectExceptionMessage ('The key "foo" has already been defined by a previous data provider ' );
163
164
164
165
/* @noinspection UnusedFunctionResultInspection */
165
166
(new DataProvider )->providedData (DuplicateKeyDataProviderTest::class, 'test ' );
166
167
}
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
+ }
167
180
}
You can’t perform that action at this time.
0 commit comments