Skip to content

Commit

Permalink
Merge pull request #1146 from ghostwriter/bugfix/overriding-expects-d…
Browse files Browse the repository at this point in the history
…efault-call-count

Override default call count expectations via `expects()`
  • Loading branch information
davedevelopment committed Oct 19, 2021
2 parents e01123a + ae18b1a commit 816475d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion library/Mockery/Expectation.php
Expand Up @@ -728,7 +728,12 @@ public function times($limit = null)
throw new \InvalidArgumentException('The passed Times limit should be an integer value');
}
$this->_countValidators[$this->_countValidatorClass] = new $this->_countValidatorClass($this, $limit);
$this->_countValidatorClass = 'Mockery\CountValidator\Exact';

if ('Mockery\CountValidator\Exact' !== $this->_countValidatorClass) {
$this->_countValidatorClass = 'Mockery\CountValidator\Exact';
unset($this->_countValidators[$this->_countValidatorClass]);
}

return $this;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Mockery/ExpectationTest.php
Expand Up @@ -683,6 +683,22 @@ public function testCalledAtLeastOnceAtExactlyThreeCalls()
$this->mock->foo();
}

public function testExpectsStringArgumentCalledAtLeastOnceOverridingDefaultOnceCall()
{
$this->mock->expects('foo')->atLeast()->once();
$this->mock->foo();
$this->mock->foo();
$this->mock->foo();
}

public function testExpectsNoArgumentCalledAtLeastOnceOverridingDefaultOnceCall()
{
$this->mock->expects()->foo()->atLeast()->once();
$this->mock->foo();
$this->mock->foo();
$this->mock->foo();
}

public function testCalledAtLeastThrowsExceptionOnTooFewCalls()
{
$this->mock->shouldReceive('foo')->atLeast()->twice();
Expand Down

0 comments on commit 816475d

Please sign in to comment.