Skip to content

Commit

Permalink
Revert "Revert "Treat InvokedCount like any other mock object expecta…
Browse files Browse the repository at this point in the history
…tion and only verify it after the test method has finished""

This reverts commit 14303e3.
  • Loading branch information
sebastianbergmann committed Jun 19, 2023
1 parent 9e74ca5 commit dd6d329
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 81 deletions.
6 changes: 0 additions & 6 deletions src/Framework/MockObject/Rule/InvocationOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
}
23 changes: 0 additions & 23 deletions src/Framework/MockObject/Rule/InvokedCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
52 changes: 0 additions & 52 deletions tests/unit/Framework/MockObject/OldTestDoubleTestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dd6d329

Please sign in to comment.