diff --git a/ChangeLog-10.5.md b/ChangeLog-10.5.md index 9b1fd6fce2..87827b0c60 100644 --- a/ChangeLog-10.5.md +++ b/ChangeLog-10.5.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 10.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [10.5.41] - 2025-MM-DD + +### Fixed + +* [#6095](https://github.com/sebastianbergmann/phpunit/issues/6095): Expectation is not counted correctly when a doubled method is called more often than is expected + ## [10.5.40] - 2024-12-21 ### Fixed @@ -363,6 +369,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi * [#5563](https://github.com/sebastianbergmann/phpunit/issues/5563): `createMockForIntersectionOfInterfaces()` does not automatically register mock object for expectation verification +[10.5.41]: https://github.com/sebastianbergmann/phpunit/compare/10.5.40...10.5 [10.5.40]: https://github.com/sebastianbergmann/phpunit/compare/10.5.39...10.5.40 [10.5.39]: https://github.com/sebastianbergmann/phpunit/compare/10.5.38...10.5.39 [10.5.38]: https://github.com/sebastianbergmann/phpunit/compare/10.5.37...10.5.38 diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 8d32c6a48f..99506e7a8d 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -73,6 +73,7 @@ use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount as InvokedAtLeastCountMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce as InvokedAtLeastOnceMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount as InvokedAtMostCountMatcher; +use PHPUnit\Framework\MockObject\Rule\InvokedCount; use PHPUnit\Framework\MockObject\Rule\InvokedCount as InvokedCountMatcher; use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls as ConsecutiveCallsStub; @@ -703,6 +704,8 @@ final public function runBare(): void $e->getMessage(), ); } catch (AssertionError|AssertionFailedError $e) { + $this->handleExceptionFromInvokedCountMockObjectRule($e); + if (!$this->wasPrepared) { $this->wasPrepared = true; @@ -2313,6 +2316,22 @@ private function requirementsNotSatisfied(): bool return (new Requirements)->requirementsNotSatisfiedFor(static::class, $this->name) !== []; } + /** + * @see https://github.com/sebastianbergmann/phpunit/issues/6095 + */ + private function handleExceptionFromInvokedCountMockObjectRule(Throwable $t): void + { + if (!$t instanceof ExpectationFailedException) { + return; + } + + $trace = $t->getTrace(); + + if (isset($trace[0]['class']) && $trace[0]['class'] === InvokedCount::class) { + $this->numberOfAssertionsPerformed++; + } + } + /** * Creates a test stub for the specified interface or class. * diff --git a/tests/end-to-end/regression/6095.phpt b/tests/end-to-end/regression/6095.phpt index f59f5cb4a9..bdd67033e4 100644 --- a/tests/end-to-end/regression/6095.phpt +++ b/tests/end-to-end/regression/6095.phpt @@ -1,7 +1,5 @@ --TEST-- https://github.com/sebastianbergmann/phpunit/issues/6095 ---XFAIL-- -https://github.com/sebastianbergmann/phpunit/issues/6095 --FILE--