Skip to content

Commit

Permalink
Uncallable @Depends will result in a warning instead of a skipped test
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden authored and sebastianbergmann committed Feb 8, 2019
1 parent 76ae30b commit 84f7f0d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
55 changes: 39 additions & 16 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1723,22 +1723,11 @@ private function handleDependencies(): bool
}

if (!isset($passedKeys[$dependency])) {
$this->status = BaseTestRunner::STATUS_SKIPPED;

$this->result->startTest($this);

$this->result->addError(
$this,
new SkippedTestError(
\sprintf(
'This test depends on "%s" to pass.',
$dependency
)
),
0
);

$this->result->endTest($this, 0);
if (!is_callable($dependency, false, $callableName) || $dependency !== $callableName) {
$this->markWarningForUncallableDependency($dependency);
} else {
$this->markSkippedForMissingDependecy($dependency);
}

return false;
}
Expand Down Expand Up @@ -1777,6 +1766,40 @@ private function handleDependencies(): bool
return true;
}

private function markSkippedForMissingDependecy(string $dependency): void
{
$this->status = BaseTestRunner::STATUS_SKIPPED;
$this->result->startTest($this);
$this->result->addError(
$this,
new SkippedTestError(
\sprintf(
'This test depends on "%s" to pass.',
$dependency
)
),
0
);
$this->result->endTest($this, 0);
}

private function markWarningForUncallableDependency(string $dependency): void
{
$this->status = BaseTestRunner::STATUS_WARNING;
$this->result->startTest($this);
$this->result->addWarning(
$this,
new Warning(
\sprintf(
'This test depends on "%s" which does not exist.',
$dependency
)
),
0
);
$this->result->endTest($this, 0);
}

/**
* Get the mock object generator, creating it if it doesn't exist.
*/
Expand Down
16 changes: 10 additions & 6 deletions tests/end-to-end/dependencies-isolation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

...FSSSS 8 / 8 (100%)
...FSSSW 8 / 8 (100%)

Time: %s, Memory: %s

There was 1 warning:

1) DependencyFailureTest::testHandlesDependsAnnotationForNonexistentTests
This test depends on "DependencyFailureTest::doesNotExist" which does not exist.

--

There was 1 failure:

1) DependencyFailureTest::testOne
Expand All @@ -27,7 +34,7 @@ There was 1 failure:

--

There were 4 skipped tests:
There were 3 skipped tests:

1) DependencyFailureTest::testTwo
This test depends on "DependencyFailureTest::testOne" to pass.
Expand All @@ -38,8 +45,5 @@ This test depends on "DependencyFailureTest::testTwo" to pass.
3) DependencyFailureTest::testFour
This test depends on "DependencyFailureTest::testOne" to pass.

4) DependencyFailureTest::testHandlesDependsAnnotationForNonexistentTests
This test depends on "DependencyFailureTest::doesNotExist" which does not exist

FAILURES!
Tests: 8, Assertions: 4, Failures: 1, Skipped: 4.
Tests: 8, Assertions: 4, Failures: 1, Warnings: 1, Skipped: 3.
16 changes: 10 additions & 6 deletions tests/end-to-end/dependencies.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

...FSSSS 8 / 8 (100%)
...FSSSW 8 / 8 (100%)

Time: %s, Memory: %s

There was 1 warning:

1) DependencyFailureTest::testHandlesDependsAnnotationForNonexistentTests
This test depends on "DependencyFailureTest::doesNotExist" which does not exist.

--

There was 1 failure:

1) DependencyFailureTest::testOne
Expand All @@ -26,7 +33,7 @@ There was 1 failure:

--

There were 4 skipped tests:
There were 3 skipped tests:

1) DependencyFailureTest::testTwo
This test depends on "DependencyFailureTest::testOne" to pass.
Expand All @@ -37,8 +44,5 @@ This test depends on "DependencyFailureTest::testTwo" to pass.
3) DependencyFailureTest::testFour
This test depends on "DependencyFailureTest::testOne" to pass.

4) DependencyFailureTest::testHandlesDependsAnnotationForNonexistentTests
This test depends on "DependencyFailureTest::doesNotExist" which does not exist

FAILURES!
Tests: 8, Assertions: 4, Failures: 1, Skipped: 4.
Tests: 8, Assertions: 4, Failures: 1, Warnings: 1, Skipped: 3.

0 comments on commit 84f7f0d

Please sign in to comment.