From 717d7fc5ef6c9c8e2b32cae475f267f177d8d506 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 15 Sep 2021 20:47:12 -0400 Subject: [PATCH 1/3] Add failing tests Signed-off-by: Nathanael Esayeas --- tests/Mockery/ExpectationTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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(); From 1ace7b2e271e83129cc468346702a9ebaa6e037e Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 15 Sep 2021 20:47:26 -0400 Subject: [PATCH 2/3] Implement the bug fix Signed-off-by: Nathanael Esayeas --- library/Mockery/Expectation.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/Mockery/Expectation.php b/library/Mockery/Expectation.php index eb0284513..ddcc185fc 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; } From ae18b1abe4220cc0026647872c1ffab3a9610601 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 15 Sep 2021 20:58:40 -0400 Subject: [PATCH 3/3] Appease the ci gods Signed-off-by: Nathanael Esayeas --- library/Mockery/Expectation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Mockery/Expectation.php b/library/Mockery/Expectation.php index ddcc185fc..ed87a5a67 100644 --- a/library/Mockery/Expectation.php +++ b/library/Mockery/Expectation.php @@ -729,7 +729,7 @@ public function times($limit = null) } $this->_countValidators[$this->_countValidatorClass] = new $this->_countValidatorClass($this, $limit); - if('Mockery\CountValidator\Exact' !== $this->_countValidatorClass){ + if ('Mockery\CountValidator\Exact' !== $this->_countValidatorClass) { $this->_countValidatorClass = 'Mockery\CountValidator\Exact'; unset($this->_countValidators[$this->_countValidatorClass]); }