Skip to content

Commit 66ab0b6

Browse files
staabmsebastianbergmann
authored andcommitted
reference previous #[TestWith] dataprovider by label
1 parent 1b6503b commit 66ab0b6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Metadata/Api/DataProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,19 @@ private function dataProvidedByMetadata(MetadataCollection $testWith): array
231231
{
232232
$result = [];
233233

234-
$providerLabel = 'TestWith attribute';
235-
236-
foreach ($testWith as $_testWith) {
234+
foreach ($testWith as $i => $_testWith) {
237235
assert($_testWith instanceof TestWith);
236+
$providerLabel = sprintf('TestWith#%s attribute', $i);
238237

239238
if ($_testWith->hasName()) {
240239
$key = $_testWith->name();
241240

242241
if (array_key_exists($key, $result)) {
243242
throw new InvalidDataProviderException(
244243
sprintf(
245-
'The key "%s" has already been defined by a previous TestWith attribute',
244+
'The key "%s" has already been defined by %s',
246245
$key,
246+
$result[$key]->getProviderLabel(),
247247
),
248248
);
249249
}

tests/unit/Metadata/Api/DataProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function testTestWithAttribute(): void
195195
public function testTestWithAttributeWithDuplicateKey(): void
196196
{
197197
$this->expectException(InvalidDataProviderException::class);
198-
$this->expectExceptionMessage('The key "foo" has already been defined by a previous TestWith attribute');
198+
$this->expectExceptionMessage('The key "foo" has already been defined by TestWith#0 attribute');
199199

200200
/* @noinspection UnusedFunctionResultInspection */
201201
(new DataProvider)->providedData(TestWithAttributeDataProviderTest::class, 'testWithDuplicateName');

0 commit comments

Comments
 (0)