Skip to content

Commit 03c5064

Browse files
committed
TestCase:prepareTestData(): check that every data provider item is array [Closes #431]
1 parent 2971d06 commit 03c5064

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Framework/TestCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ private function prepareTestData(\ReflectionMethod $method, array $dataprovider)
245245
}
246246

247247
foreach ($res as $k => $set) {
248+
if (!is_array($set)) {
249+
$type = is_object($set) ? get_class($set) : gettype($set);
250+
throw new TestCaseException("Data provider $provider() item '$k' must be an array, $type given.");
251+
}
252+
248253
$data["$i-$k"] = is_string(key($set))
249254
? array_merge($defaultParams, $set)
250255
: $set;

tests/Framework/TestCase.invalidProvider.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ class InvalidProviderTest extends Tester\TestCase
2323
public function testMissingDataProvider($a)
2424
{
2525
}
26+
27+
28+
public function invalidDataProviderItem()
29+
{
30+
return ['non-array-item'];
31+
}
32+
33+
34+
/** @dataProvider invalidDataProviderItem */
35+
public function testInvalidDataProviderItem()
36+
{
37+
}
2638
}
2739

2840

@@ -35,3 +47,8 @@ Assert::exception(function () {
3547
$test = new InvalidProviderTest;
3648
$test->runTest('testMissingDataProvider');
3749
}, Tester\TestCaseException::class, 'Method testMissingDataProvider() has arguments, but @dataProvider is missing.');
50+
51+
Assert::exception(function () {
52+
$test = new InvalidProviderTest;
53+
$test->runTest('testInvalidDataProviderItem');
54+
}, Tester\TestCaseException::class, "Data provider invalidDataProviderItem() item '0' must be an array, string given.");

0 commit comments

Comments
 (0)