Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override default call count expectations via expects() #1146

Merged
merged 3 commits into from Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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