Skip to content

Commit

Permalink
Closes #6095
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 9, 2025
1 parent 973a49f commit de0c82c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-10.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -703,6 +704,8 @@ final public function runBare(): void
$e->getMessage(),
);
} catch (AssertionError|AssertionFailedError $e) {
$this->handleExceptionFromInvokedCountMockObjectRule($e);

if (!$this->wasPrepared) {
$this->wasPrepared = true;

Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/regression/6095.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6095
--XFAIL--
https://github.com/sebastianbergmann/phpunit/issues/6095
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
Expand Down

0 comments on commit de0c82c

Please sign in to comment.