Skip to content

Commit

Permalink
TestHandler: mark tests with empty data provider as failed/skipped
Browse files Browse the repository at this point in the history
Related to 1f4bce2
  • Loading branch information
milo committed Apr 27, 2021
1 parent 4eb4665 commit 617683b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Runner/TestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ private function initiateDataProvider(Test $test, string $provider)
try {
[$dataFile, $query, $optional] = Tester\DataProvider::parseAnnotation($provider, $test->getFile());
$data = Tester\DataProvider::load($dataFile, $query);
if (count($data) < 1) {
throw new \Exception("No records in data provider file '{$test->getFile()}'" . ($query ? " for query '$query'" : '') . '.');
}

} catch (\Exception $e) {
return $test->withResult(empty($optional) ? Test::FAILED : Test::SKIPPED, $e->getMessage());
}
Expand Down
9 changes: 8 additions & 1 deletion tests/Runner/Runner.multiple-fails.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ $runner->paths[] = __DIR__ . '/multiple-fails/*.phptx';
$runner->outputHandlers[] = $logger = new Logger;
$runner->run();

Assert::match(
"No records in data provider file '%a%dataprovider-empty.phptx' for query 'non-existent'.",
$logger->results['dataprovider-empty.phptx'][1]
);
Assert::same(Test::FAILED, $logger->results['dataprovider-empty.phptx'][0]);


Assert::match(
"Class MyTest in file '%a%testcase-no-methods.phptx' does not contain test methods.",
$logger->results['testcase-no-methods.phptx'][1]
Expand Down Expand Up @@ -93,4 +100,4 @@ Assert::match(
Assert::same(Test::SKIPPED, $logger->results['testcase-skip.phptx'][0]);


Assert::same(6, count($logger->results));
Assert::same(7, count($logger->results));
5 changes: 5 additions & 0 deletions tests/Runner/multiple-fails/dataprovider-empty.phptx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

/**
* @dataProvider ../../Framework/fixtures/dataprovider.query.ini, non-existent
*/

0 comments on commit 617683b

Please sign in to comment.