Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncallable @depends will warn instead of just skip #3525

Merged
merged 3 commits into from Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 39 additions & 16 deletions src/Framework/TestCase.php
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
13 changes: 13 additions & 0 deletions tests/_files/DependencyFailureTest.php
Expand Up @@ -39,4 +39,17 @@ public function testFour(): void
{
$this->assertTrue(true);
}

/**
* This test has been added to check the printed warnings for the user
* when a dependency simply doesn't exist.
*
* @depends doesNotExist
*
* @see https://github.com/sebastianbergmann/phpunit/issues/3517
*/
public function testHandlesDependsAnnotationForNonexistentTests(): void
{
$this->assertTrue(true);
}
}
11 changes: 9 additions & 2 deletions tests/end-to-end/dependencies-isolation.phpt
Expand Up @@ -15,10 +15,17 @@ PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

...FSSS 7 / 7 (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 @@ -39,4 +46,4 @@ This test depends on "DependencyFailureTest::testTwo" to pass.
This test depends on "DependencyFailureTest::testOne" to pass.

FAILURES!
Tests: 7, Assertions: 4, Failures: 1, Skipped: 3.
Tests: 8, Assertions: 4, Failures: 1, Warnings: 1, Skipped: 3.
11 changes: 9 additions & 2 deletions tests/end-to-end/dependencies.phpt
Expand Up @@ -14,10 +14,17 @@ PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

...FSSS 7 / 7 (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 @@ -38,4 +45,4 @@ This test depends on "DependencyFailureTest::testTwo" to pass.
This test depends on "DependencyFailureTest::testOne" to pass.

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