diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 0d30afc49ae..ce229c0c40e 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -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; } @@ -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. */ diff --git a/tests/_files/DependencyFailureTest.php b/tests/_files/DependencyFailureTest.php index 4695305d73d..cec0ddf118d 100644 --- a/tests/_files/DependencyFailureTest.php +++ b/tests/_files/DependencyFailureTest.php @@ -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); + } } diff --git a/tests/end-to-end/dependencies-isolation.phpt b/tests/end-to-end/dependencies-isolation.phpt index 88c0808b03c..fc451a02782 100644 --- a/tests/end-to-end/dependencies-isolation.phpt +++ b/tests/end-to-end/dependencies-isolation.phpt @@ -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 @@ -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. diff --git a/tests/end-to-end/dependencies.phpt b/tests/end-to-end/dependencies.phpt index 8fab9884d24..e05fdda1dcb 100644 --- a/tests/end-to-end/dependencies.phpt +++ b/tests/end-to-end/dependencies.phpt @@ -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 @@ -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.