Skip to content

Commit

Permalink
Merge pull request #750 from robertbasic/fix/issue208
Browse files Browse the repository at this point in the history
Fix/issue208
  • Loading branch information
davedevelopment committed Jun 22, 2017
2 parents d0ff5d3 + de1b4fb commit 08cbaaa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* BC BREAK - Remove implicit regex matching when trying to match string arguments, introduce `\Mockery::pattern()` when regex matching is needed
* Fix Mockery not getting closed in cases of failing test cases
* Fix Mockery not setting properties on overloaded instance mocks
* BC BREAK - Fix Mockery not trying default expectations if there is any concrete expectation


## 0.9.4 (XXXX-XX-XX)
Expand Down
12 changes: 9 additions & 3 deletions library/Mockery/ExpectationDirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,17 @@ public function verify()
*/
public function findExpectation(array $args)
{
$expectation = null;

if (!empty($this->_expectations)) {
return $this->_findExpectationIn($this->_expectations, $args);
} else {
return $this->_findExpectationIn($this->_defaults, $args);
$expectation = $this->_findExpectationIn($this->_expectations, $args);
}

if ($expectation === null && !empty($this->_defaults)) {
$expectation = $this->_findExpectationIn($this->_defaults, $args);
}

return $expectation;
}

/**
Expand Down
16 changes: 6 additions & 10 deletions tests/Mockery/ExpectationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,22 +997,18 @@ public function testDefaultExpectationsValidatedInCorrectOrder()
public function testDefaultExpectationsAreReplacedByLaterConcreteExpectations()
{
$this->mock->shouldReceive('foo')->andReturn('bar')->once()->byDefault();
$this->mock->shouldReceive('foo')->andReturn('bar')->twice();
$this->mock->foo();
$this->mock->foo();
$this->mock->shouldReceive('foo')->andReturn('baz')->twice();
$this->assertEquals('baz', $this->mock->foo());
$this->assertEquals('baz', $this->mock->foo());
$this->container->mockery_verify();
}

public function testDefaultExpectationsCanBeChangedByLaterExpectations()
public function testExpectationFallsBackToDefaultExpectationWhenConcreteExpectationsAreUsedUp()
{
$this->mock->shouldReceive('foo')->with(1)->andReturn('bar')->once()->byDefault();
$this->mock->shouldReceive('foo')->with(2)->andReturn('baz')->once();
try {
$this->mock->foo(1);
$this->fail('Expected exception not thrown');
} catch (\Mockery\Exception $e) {
}
$this->mock->foo(2);
$this->assertEquals('baz', $this->mock->foo(2));
$this->assertEquals('bar', $this->mock->foo(1));
$this->container->mockery_verify();
}

Expand Down

0 comments on commit 08cbaaa

Please sign in to comment.