Skip to content

Commit 1f07698

Browse files
authored
Test data providers key types (#712)
1 parent dc17012 commit 1f07698

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

phpunit.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
cacheResult='false'
66
colors='true'
77
executionOrder='default'
8+
failOnEmptyTestSuite='true'
9+
failOnIncomplete='true'
810
failOnRisky='true'
911
failOnWarning='true'
1012
forceCoversAnnotation='true'

tests/AutoReview/TestsCodeTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ public function testDataProvidersKeys(string $className): void
8787
$dataSet = $dataProvider->invoke(null);
8888
\assert($dataSet instanceof \Iterator);
8989

90+
$keyType = null;
9091
foreach (\array_keys(\iterator_to_array($dataSet)) as $key) {
91-
if (!\is_string($key)) {
92-
self::markTestIncomplete(\sprintf(
93-
'Data provider "%s" in class "%s" has non-string keys.',
94-
$dataProvider->getName(),
95-
$className
96-
));
92+
// based on the type of first key determine what type should be for all keys
93+
if ($keyType === null) {
94+
$keyType = \is_int($key) ? 'int' : 'string';
9795
}
96+
97+
if (\is_int($key)) {
98+
self::assertSame('int', $keyType);
99+
continue;
100+
}
101+
102+
self::assertSame('string', $keyType);
98103
self::assertIsString($key);
99104
self::assertSame(\trim($key), $key);
100105
self::assertStringNotContainsString(' ', $key);

0 commit comments

Comments
 (0)