Skip to content

Commit

Permalink
adding file and lineno to output of 0 assertion test message
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth authored and sebastianbergmann committed Jul 7, 2018
1 parent c17423b commit 80834b0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
19 changes: 16 additions & 3 deletions src/Framework/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,11 +816,24 @@ public function run(Test $test): void
} elseif ($this->beStrictAboutTestsThatDoNotTestAnything &&
!$test->doesNotPerformAssertions() &&
$test->getNumAssertions() == 0) {
try {
$reflected = new \ReflectionClass($test);
$name = $test->getName(false);

if ($name && $reflected->hasMethod($name)) {
$reflected = $reflected->getMethod($name);
}
$message = \sprintf(
"This test did not perform any assertions\n\n%s:%d",
$reflected->getFileName(),
$reflected->getStartLine()
);
} catch (\ReflectionException $exception) {
$message = 'This test did not perform any assertions';
}
$this->addFailure(
$test,
new RiskyTestError(
'This test did not perform any assertions'
),
new RiskyTestError($message),
$time
);
} elseif ($this->beStrictAboutTestsThatDoNotTestAnything &&
Expand Down
8 changes: 1 addition & 7 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,7 @@ public function run(TestResult $result = null): TestResult
$result->endTestSuite($this);

return $result;
} catch (Throwable $_t) {
$t = $_t;
} catch (Exception $_t) {
$t = $_t;
}

if (isset($t)) {
} catch (Throwable $t) {
$numTests = \count($this);

for ($i = 0; $i < $numTests; $i++) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Regression/GitHub/1570.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ There was 1 risky test:
1) Issue1570Test::testOne
This test did not perform any assertions

%s:14

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
2 changes: 2 additions & 0 deletions tests/TextUI/log-junit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@ There was 1 risky test:
1) vendor\project\StatusTest::testRisky
This test did not perform any assertions

%s:42

ERRORS!
Tests: 7, Assertions: 2, Errors: 1, Failures: 1, Warnings: 1, Skipped: 1, Incomplete: 1, Risky: 1.
2 changes: 2 additions & 0 deletions tests/TextUI/report-useless-tests-isolation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ There was 1 risky test:
1) NothingTest::testNothing
This test did not perform any assertions

%s:14

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
2 changes: 2 additions & 0 deletions tests/TextUI/report-useless-tests.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ There was 1 risky test:
1) NothingTest::testNothing
This test did not perform any assertions

%s:14

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
2 changes: 2 additions & 0 deletions tests/TextUI/testdox-xml.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ There was 1 risky test:
1) vendor\project\StatusTest::testRisky
This test did not perform any assertions

%s:42

ERRORS!
Tests: 7, Assertions: 2, Errors: 1, Failures: 1, Warnings: 1, Skipped: 1, Incomplete: 1, Risky: 1.

0 comments on commit 80834b0

Please sign in to comment.