Skip to content

Commit

Permalink
TestCase:prepareTestData(): check that every data provider item is ar…
Browse files Browse the repository at this point in the history
…ray [Closes #431]
  • Loading branch information
milo authored and dg committed Aug 24, 2021
1 parent 6c4c3bd commit a496e85
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Framework/TestCase.php
Expand Up @@ -245,6 +245,11 @@ private function prepareTestData(\ReflectionMethod $method, array $dataprovider)
}

foreach ($res as $k => $set) {
if (!is_array($set)) {
$type = is_object($set) ? get_class($set) : gettype($set);
throw new TestCaseException("Data provider $provider() item '$k' must be an array, $type given.");
}

$data["$i-$k"] = is_string(key($set))
? array_merge($defaultParams, $set)
: $set;
Expand Down
17 changes: 17 additions & 0 deletions tests/Framework/TestCase.invalidProvider.phpt
Expand Up @@ -23,6 +23,18 @@ class InvalidProviderTest extends Tester\TestCase
public function testMissingDataProvider($a)
{
}


public function invalidDataProviderItem()
{
return ['non-array-item'];
}


/** @dataProvider invalidDataProviderItem */
public function testInvalidDataProviderItem()
{
}
}


Expand All @@ -35,3 +47,8 @@ Assert::exception(function () {
$test = new InvalidProviderTest;
$test->runTest('testMissingDataProvider');
}, Tester\TestCaseException::class, 'Method testMissingDataProvider() has arguments, but @dataProvider is missing.');

Assert::exception(function () {
$test = new InvalidProviderTest;
$test->runTest('testInvalidDataProviderItem');
}, Tester\TestCaseException::class, "Data provider invalidDataProviderItem() item '0' must be an array, string given.");

0 comments on commit a496e85

Please sign in to comment.