diff --git a/library/Mockery/Expectation.php b/library/Mockery/Expectation.php index eb0284513..ed87a5a67 100644 --- a/library/Mockery/Expectation.php +++ b/library/Mockery/Expectation.php @@ -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; } diff --git a/tests/Mockery/ExpectationTest.php b/tests/Mockery/ExpectationTest.php index 326707c5b..1430701a1 100644 --- a/tests/Mockery/ExpectationTest.php +++ b/tests/Mockery/ExpectationTest.php @@ -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();