From 68ca073f4b1b5919c3f0674fd585edd47d106677 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 28 Apr 2024 19:32:16 +0200 Subject: [PATCH 1/2] Ignore deprecated methods from code coverage --- src/Framework/TestCase.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index e11e8c7935..cc60353219 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -262,6 +262,8 @@ final public static function atMost(int $allowedInvocations): InvokedAtMostCount /** * @deprecated Use $double->willReturn() instead of $double->will($this->returnValue()) * @see https://github.com/sebastianbergmann/phpunit/issues/5423 + * + * @codeCoverageIgnore */ final public static function returnValue(mixed $value): ReturnStub { @@ -271,6 +273,8 @@ final public static function returnValue(mixed $value): ReturnStub /** * @deprecated Use $double->willReturnMap() instead of $double->will($this->returnValueMap()) * @see https://github.com/sebastianbergmann/phpunit/issues/5423 + * + * @codeCoverageIgnore */ final public static function returnValueMap(array $valueMap): ReturnValueMapStub { @@ -280,6 +284,8 @@ final public static function returnValueMap(array $valueMap): ReturnValueMapStub /** * @deprecated Use $double->willReturnArgument() instead of $double->will($this->returnArgument()) * @see https://github.com/sebastianbergmann/phpunit/issues/5423 + * + * @codeCoverageIgnore */ final public static function returnArgument(int $argumentIndex): ReturnArgumentStub { @@ -289,6 +295,8 @@ final public static function returnArgument(int $argumentIndex): ReturnArgumentS /** * @deprecated Use $double->willReturnCallback() instead of $double->will($this->returnCallback()) * @see https://github.com/sebastianbergmann/phpunit/issues/5423 + * + * @codeCoverageIgnore */ final public static function returnCallback(callable $callback): ReturnCallbackStub { @@ -298,6 +306,8 @@ final public static function returnCallback(callable $callback): ReturnCallbackS /** * @deprecated Use $double->willReturnSelf() instead of $double->will($this->returnSelf()) * @see https://github.com/sebastianbergmann/phpunit/issues/5423 + * + * @codeCoverageIgnore */ final public static function returnSelf(): ReturnSelfStub { @@ -313,6 +323,8 @@ final public static function throwException(Throwable $exception): ExceptionStub * @deprecated Use $double->willReturn() instead of $double->will($this->onConsecutiveCalls()) * @see https://github.com/sebastianbergmann/phpunit/issues/5423 * @see https://github.com/sebastianbergmann/phpunit/issues/5425 + * + * @codeCoverageIgnore */ final public static function onConsecutiveCalls(mixed ...$arguments): ConsecutiveCallsStub { @@ -619,6 +631,8 @@ final public function expectsOutput(): bool * @internal This method is not covered by the backward compatibility promise for PHPUnit * * @deprecated + * + * @codeCoverageIgnore */ final public function registerMockObjectsFromTestArgumentsRecursively(): void { @@ -1189,6 +1203,8 @@ protected function runTest(): mixed * @throws Exception * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5214 + * + * @codeCoverageIgnore */ protected function iniSet(string $varName, string $newValue): void { @@ -1214,6 +1230,8 @@ protected function iniSet(string $varName, string $newValue): void * @throws Exception * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5216 + * + * @codeCoverageIgnore */ protected function setLocale(mixed ...$arguments): void { From 4e25805e2b37f27680b02249bc2c415299fe6b36 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 28 Apr 2024 19:32:33 +0200 Subject: [PATCH 2/2] Ignore methods from code coverage that are only called when code coverage information cannot be collected --- src/Framework/TestCase.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index cc60353219..67905a84d6 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -666,7 +666,9 @@ final public function runBare(): void $hasMetRequirements = true; if ($this->inIsolation) { + // @codeCoverageIgnoreStart $this->invokeBeforeClassHookMethods($hookMethods, $emitter); + // @codeCoverageIgnoreEnd } if (method_exists(static::class, $this->name) && @@ -780,7 +782,9 @@ final public function runBare(): void $this->invokeAfterTestHookMethods($hookMethods, $emitter); if ($this->inIsolation) { + // @codeCoverageIgnoreStart $this->invokeAfterClassHookMethods($hookMethods, $emitter); + // @codeCoverageIgnoreEnd } } } catch (AssertionError|AssertionFailedError $e) { @@ -852,6 +856,8 @@ final public function setDependencies(array $dependencies): void /** * @internal This method is not covered by the backward compatibility promise for PHPUnit + * + * @codeCoverageIgnore */ final public function setDependencyInput(array $dependencyInput): void { @@ -2065,6 +2071,8 @@ private function performAssertionsOnOutput(): void /** * @throws Throwable + * + * @codeCoverageIgnore */ private function invokeBeforeClassHookMethods(array $hookMethods, Event\Emitter $emitter): void { @@ -2130,6 +2138,8 @@ private function invokeAfterTestHookMethods(array $hookMethods, Event\Emitter $e /** * @throws Throwable + * + * @codeCoverageIgnore */ private function invokeAfterClassHookMethods(array $hookMethods, Event\Emitter $emitter): void {