From dd6d3290d84741e8248316d37ec973448e3c254d Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 19 Jun 2023 13:56:49 +0200 Subject: [PATCH] Revert "Revert "Treat InvokedCount like any other mock object expectation and only verify it after the test method has finished"" This reverts commit 14303e37714ff16c92c95f7a04185c495d151335. --- .../MockObject/Rule/InvocationOrder.php | 6 --- .../MockObject/Rule/InvokedCount.php | 23 -------- .../MockObject/OldTestDoubleTestsTest.php | 52 ------------------- 3 files changed, 81 deletions(-) diff --git a/src/Framework/MockObject/Rule/InvocationOrder.php b/src/Framework/MockObject/Rule/InvocationOrder.php index 622922889a2..7209433af86 100644 --- a/src/Framework/MockObject/Rule/InvocationOrder.php +++ b/src/Framework/MockObject/Rule/InvocationOrder.php @@ -37,13 +37,7 @@ public function hasBeenInvoked(): bool final public function invoked(BaseInvocation $invocation): void { $this->invocations[] = $invocation; - - $this->invokedDo($invocation); } abstract public function matches(BaseInvocation $invocation): bool; - - protected function invokedDo(BaseInvocation $invocation): void - { - } } diff --git a/src/Framework/MockObject/Rule/InvokedCount.php b/src/Framework/MockObject/Rule/InvokedCount.php index 7ccc5105cda..c307518c0fd 100644 --- a/src/Framework/MockObject/Rule/InvokedCount.php +++ b/src/Framework/MockObject/Rule/InvokedCount.php @@ -61,27 +61,4 @@ public function verify(): void ); } } - - /** - * @throws ExpectationFailedException - */ - protected function invokedDo(BaseInvocation $invocation): void - { - $count = $this->numberOfInvocations(); - - if ($count > $this->expectedCount) { - $message = $invocation->toString() . ' '; - - $message .= match ($this->expectedCount) { - 0 => 'was not expected to be called.', - 1 => 'was not expected to be called more than once.', - default => sprintf( - 'was not expected to be called more than %d times.', - $this->expectedCount, - ), - }; - - throw new ExpectationFailedException($message); - } - } } diff --git a/tests/unit/Framework/MockObject/OldTestDoubleTestsTest.php b/tests/unit/Framework/MockObject/OldTestDoubleTestsTest.php index 915a17591ef..1e3e365062e 100644 --- a/tests/unit/Framework/MockObject/OldTestDoubleTestsTest.php +++ b/tests/unit/Framework/MockObject/OldTestDoubleTestsTest.php @@ -759,58 +759,6 @@ public function testVerificationOfMethodNameFailsWithWrongParameters(): void $this->resetMockObjects(); } - public function testVerificationOfNeverFailsWithEmptyParameters(): void - { - $mock = $this->getMockBuilder(SomeClass::class) - ->addMethods(['right', 'wrong']) - ->getMock(); - - $mock->expects($this->never()) - ->method('right') - ->with(); - - try { - $mock->right(); - $this->fail('Expected exception'); - } catch (ExpectationFailedException $e) { - $this->assertSame( - sprintf( - '%s::right() was not expected to be called.', - SomeClass::class, - ), - $e->getMessage(), - ); - } - - $this->resetMockObjects(); - } - - public function testVerificationOfNeverFailsWithAnyParameters(): void - { - $mock = $this->getMockBuilder(SomeClass::class) - ->addMethods(['right', 'wrong']) - ->getMock(); - - $mock->expects($this->never()) - ->method('right') - ->withAnyParameters(); - - try { - $mock->right(); - $this->fail('Expected exception'); - } catch (ExpectationFailedException $e) { - $this->assertSame( - sprintf( - '%s::right() was not expected to be called.', - SomeClass::class, - ), - $e->getMessage(), - ); - } - - $this->resetMockObjects(); - } - public function testWithAnythingInsteadOfWithAnyParameters(): void { $mock = $this->getMockBuilder(SomeClass::class)