diff --git a/library/Mockery/ExpectationDirector.php b/library/Mockery/ExpectationDirector.php index 1310c1b38..efb0b70ba 100644 --- a/library/Mockery/ExpectationDirector.php +++ b/library/Mockery/ExpectationDirector.php @@ -213,6 +213,14 @@ public function getDefaultExpectations() */ public function getExpectationCount() { - return count($this->getExpectations()) ?: count($this->getDefaultExpectations()); + $count = 0; + /** @var Expectation $expectations */ + $expectations = $this->getExpectations() ?: $this->getDefaultExpectations(); + foreach ($expectations as $expectation) { + if ($expectation->isCallCountConstrained()) { + $count++; + } + } + return $count; } } diff --git a/tests/Mockery/ContainerTest.php b/tests/Mockery/ContainerTest.php index c0bd1af1c..6897a07df 100644 --- a/tests/Mockery/ContainerTest.php +++ b/tests/Mockery/ContainerTest.php @@ -992,10 +992,34 @@ public function testGetExpectationCount_freshContainer() $this->assertEquals(0, Mockery::getContainer()->mockery_getExpectationCount()); } - public function testGetExpectationCount_simplestMock() + public function testGetExpectationCount_stub() { $m = mock(); - $m->shouldReceive('foo')->andReturn('bar'); + $m->shouldReceive('foo'); + $this->assertEquals(0, Mockery::getContainer()->mockery_getExpectationCount()); + } + + public function testGetExpectationCount_mockWithOnce() + { + $m = mock(); + $m->shouldReceive('foo')->once(); + $this->assertEquals(1, Mockery::getContainer()->mockery_getExpectationCount()); + $m->foo(); + } + + public function testGetExpectationCount_mockWithAtLeast() + { + $m = mock(); + $m->shouldReceive('foo')->atLeast()->once(); + $this->assertEquals(1, Mockery::getContainer()->mockery_getExpectationCount()); + $m->foo(); + $m->foo(); + } + + public function testGetExpectationCount_mockWithNever() + { + $m = mock(); + $m->shouldReceive('foo')->never(); $this->assertEquals(1, Mockery::getContainer()->mockery_getExpectationCount()); }