Skip to content

Commit

Permalink
feat(Testing): Add assertCalled method for asserting if expectations …
Browse files Browse the repository at this point in the history
…were called
  • Loading branch information
pionl committed Dec 19, 2022
1 parent 550ac67 commit 44d355e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Testing/AbstractExpectationCallsMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public function addExpectation(object $expectation): self

/**
* @template TExpectation
*
* @param class-string<TExpectation> $class
* @param array<TExpectation> $expectations
* @param array<TExpectation> $expectations
*/
public function setExpectations(string $class, array $expectations): self
{
Expand All @@ -42,6 +43,21 @@ public function setExpectations(string $class, array $expectations): self
return $this;
}

public function assertCalled(): void
{
foreach ($this->_expectationMap as $class => $expectations) {
$called = $this->_callStep[$class] ?? 0;
$expected = count($expectations);
if ($expected === $called) {
continue;
}

throw new LogicException(
sprintf('[%s] expected %d call/s but was called <%d> time/s', $class, $expected, $called)
);
}
}

/**
* @template TExpectation of object
*
Expand Down

0 comments on commit 44d355e

Please sign in to comment.