Skip to content

Commit 80834b0

Browse files
Idrinthsebastianbergmann
authored andcommitted
adding file and lineno to output of 0 assertion test message
1 parent c17423b commit 80834b0

File tree

7 files changed

+27
-10
lines changed

7 files changed

+27
-10
lines changed

src/Framework/TestResult.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,11 +816,24 @@ public function run(Test $test): void
816816
} elseif ($this->beStrictAboutTestsThatDoNotTestAnything &&
817817
!$test->doesNotPerformAssertions() &&
818818
$test->getNumAssertions() == 0) {
819+
try {
820+
$reflected = new \ReflectionClass($test);
821+
$name = $test->getName(false);
822+
823+
if ($name && $reflected->hasMethod($name)) {
824+
$reflected = $reflected->getMethod($name);
825+
}
826+
$message = \sprintf(
827+
"This test did not perform any assertions\n\n%s:%d",
828+
$reflected->getFileName(),
829+
$reflected->getStartLine()
830+
);
831+
} catch (\ReflectionException $exception) {
832+
$message = 'This test did not perform any assertions';
833+
}
819834
$this->addFailure(
820835
$test,
821-
new RiskyTestError(
822-
'This test did not perform any assertions'
823-
),
836+
new RiskyTestError($message),
824837
$time
825838
);
826839
} elseif ($this->beStrictAboutTestsThatDoNotTestAnything &&

src/Framework/TestSuite.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -719,13 +719,7 @@ public function run(TestResult $result = null): TestResult
719719
$result->endTestSuite($this);
720720

721721
return $result;
722-
} catch (Throwable $_t) {
723-
$t = $_t;
724-
} catch (Exception $_t) {
725-
$t = $_t;
726-
}
727-
728-
if (isset($t)) {
722+
} catch (Throwable $t) {
729723
$numTests = \count($this);
730724

731725
for ($i = 0; $i < $numTests; $i++) {

tests/Regression/GitHub/1570.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ There was 1 risky test:
2121
1) Issue1570Test::testOne
2222
This test did not perform any assertions
2323

24+
%s:14
25+
2426
OK, but incomplete, skipped, or risky tests!
2527
Tests: 1, Assertions: 0, Risky: 1.

tests/TextUI/log-junit.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,7 @@ There was 1 risky test:
8585
1) vendor\project\StatusTest::testRisky
8686
This test did not perform any assertions
8787

88+
%s:42
89+
8890
ERRORS!
8991
Tests: 7, Assertions: 2, Errors: 1, Failures: 1, Warnings: 1, Skipped: 1, Incomplete: 1, Risky: 1.

tests/TextUI/report-useless-tests-isolation.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ There was 1 risky test:
2121
1) NothingTest::testNothing
2222
This test did not perform any assertions
2323

24+
%s:14
25+
2426
OK, but incomplete, skipped, or risky tests!
2527
Tests: 1, Assertions: 0, Risky: 1.

tests/TextUI/report-useless-tests.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ There was 1 risky test:
2020
1) NothingTest::testNothing
2121
This test did not perform any assertions
2222

23+
%s:14
24+
2325
OK, but incomplete, skipped, or risky tests!
2426
Tests: 1, Assertions: 0, Risky: 1.

tests/TextUI/testdox-xml.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ There was 1 risky test:
5858
1) vendor\project\StatusTest::testRisky
5959
This test did not perform any assertions
6060

61+
%s:42
62+
6163
ERRORS!
6264
Tests: 7, Assertions: 2, Errors: 1, Failures: 1, Warnings: 1, Skipped: 1, Incomplete: 1, Risky: 1.

0 commit comments

Comments
 (0)