Skip to content

Commit

Permalink
Merge pull request #1180 from jmauerhan/assertion-count
Browse files Browse the repository at this point in the history
feat: only count assertions on expectations which can fail a test
  • Loading branch information
davedevelopment committed May 27, 2022
2 parents c72ff6f + 72cf17b commit 33cb226
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
10 changes: 9 additions & 1 deletion library/Mockery/ExpectationDirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
28 changes: 26 additions & 2 deletions tests/Mockery/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 33cb226

Please sign in to comment.