Skip to content

Commit de0c82c

Browse files
Closes #6095
1 parent 973a49f commit de0c82c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

ChangeLog-10.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 10.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [10.5.41] - 2025-MM-DD
6+
7+
### Fixed
8+
9+
* [#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+
511
## [10.5.40] - 2024-12-21
612

713
### Fixed
@@ -363,6 +369,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
363369

364370
* [#5563](https://github.com/sebastianbergmann/phpunit/issues/5563): `createMockForIntersectionOfInterfaces()` does not automatically register mock object for expectation verification
365371

372+
[10.5.41]: https://github.com/sebastianbergmann/phpunit/compare/10.5.40...10.5
366373
[10.5.40]: https://github.com/sebastianbergmann/phpunit/compare/10.5.39...10.5.40
367374
[10.5.39]: https://github.com/sebastianbergmann/phpunit/compare/10.5.38...10.5.39
368375
[10.5.38]: https://github.com/sebastianbergmann/phpunit/compare/10.5.37...10.5.38

src/Framework/TestCase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount as InvokedAtLeastCountMatcher;
7474
use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce as InvokedAtLeastOnceMatcher;
7575
use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount as InvokedAtMostCountMatcher;
76+
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
7677
use PHPUnit\Framework\MockObject\Rule\InvokedCount as InvokedCountMatcher;
7778
use PHPUnit\Framework\MockObject\Stub;
7879
use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls as ConsecutiveCallsStub;
@@ -703,6 +704,8 @@ final public function runBare(): void
703704
$e->getMessage(),
704705
);
705706
} catch (AssertionError|AssertionFailedError $e) {
707+
$this->handleExceptionFromInvokedCountMockObjectRule($e);
708+
706709
if (!$this->wasPrepared) {
707710
$this->wasPrepared = true;
708711

@@ -2313,6 +2316,22 @@ private function requirementsNotSatisfied(): bool
23132316
return (new Requirements)->requirementsNotSatisfiedFor(static::class, $this->name) !== [];
23142317
}
23152318

2319+
/**
2320+
* @see https://github.com/sebastianbergmann/phpunit/issues/6095
2321+
*/
2322+
private function handleExceptionFromInvokedCountMockObjectRule(Throwable $t): void
2323+
{
2324+
if (!$t instanceof ExpectationFailedException) {
2325+
return;
2326+
}
2327+
2328+
$trace = $t->getTrace();
2329+
2330+
if (isset($trace[0]['class']) && $trace[0]['class'] === InvokedCount::class) {
2331+
$this->numberOfAssertionsPerformed++;
2332+
}
2333+
}
2334+
23162335
/**
23172336
* Creates a test stub for the specified interface or class.
23182337
*

tests/end-to-end/regression/6095.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
https://github.com/sebastianbergmann/phpunit/issues/6095
3-
--XFAIL--
4-
https://github.com/sebastianbergmann/phpunit/issues/6095
53
--FILE--
64
<?php declare(strict_types=1);
75
$_SERVER['argv'][] = '--do-not-cache-result';

0 commit comments

Comments
 (0)