Skip to content

Commit

Permalink
Merge branch '11.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 9, 2025
2 parents 90d23c7 + 6093ee5 commit 787af79
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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\Exception as ExceptionStub;
Expand Down Expand Up @@ -503,6 +504,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 @@ -2137,6 +2140,22 @@ private function requirementsNotSatisfied(): bool
return (new Requirements)->requirementsNotSatisfiedFor(static::class, $this->methodName) !== [];
}

/**
* @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
4 changes: 1 addition & 3 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 All @@ -23,7 +21,7 @@ Time: %s, Memory: %s
There was 1 failure:

1) PHPUnit\TestFixture\Issue6095\Issue6095Test::testOne
PHPUnit\TestFixture\MockObject\AnInterface::doSomething() was not expected to be called more than once.
PHPUnit\TestFixture\MockObject\AnInterface::doSomething(): bool was not expected to be called more than once.

%sIssue6095Test.php:26

Expand Down

0 comments on commit 787af79

Please sign in to comment.