Skip to content

Commit

Permalink
Fix completely broken policy checking of return_this() on shmocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrama committed Sep 24, 2015
1 parent 4202dac commit e9a2050
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Shmock/StaticSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public function doInvocation(Invocation $invocation)
// as implemented, returnThis can only be verified by policies at
// calltime.
foreach ($this->policies as $policy) {
$this->check_method_return_value($this->className, $this->methodName, $target, true);
$policy->check_method_return_value($this->className, $this->methodName, $target, true);
}

return $target;
Expand Down
14 changes: 14 additions & 0 deletions test/Shmock/Policy_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ public function test_arg_policy_does_not_throw_when_no_args_passed_and_escape_fl
Shmock::$check_args_for_policy_on_instance_method_when_no_args_passed = true;
$this->assertEquals($calc->raise_to_even(13), 6);
}

/**
* @expectedException \UnexpectedValueException
*/
public function test_return_this_works_with_policies()
{
$calc = $this->shmock('Shmock\Even_Calculator', function ($calculator) {
$calculator->raise_to_even(7)->return_this();
});
$calc->raise_to_even(7);
}
}

class Even_Calculator
Expand Down Expand Up @@ -137,6 +148,9 @@ public function check_method_parameters($class, $method, $parameters, $static)

public function check_method_return_value($class, $method, $return_value, $static)
{
if (is_object($return_value)) {
throw new \UnexpectedValueException("object returned?!?");
}
if ($return_value % 2 === 1) {
throw new Shmock_Exception();
}
Expand Down
1 change: 1 addition & 0 deletions test/Shmock/ShmockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ function ($mock) {

$this->assertEquals($foo::sFoo(), 2);
}

public function tearDown()
{
Shmock::verify();
Expand Down

0 comments on commit e9a2050

Please sign in to comment.