diff --git a/src/Shmock/StaticSpec.php b/src/Shmock/StaticSpec.php index ac5f0f9..3e71ff4 100644 --- a/src/Shmock/StaticSpec.php +++ b/src/Shmock/StaticSpec.php @@ -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; diff --git a/test/Shmock/Policy_Test.php b/test/Shmock/Policy_Test.php index a9defce..f6da219 100644 --- a/test/Shmock/Policy_Test.php +++ b/test/Shmock/Policy_Test.php @@ -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 @@ -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(); } diff --git a/test/Shmock/ShmockTest.php b/test/Shmock/ShmockTest.php index 0672c85..38ebeb4 100644 --- a/test/Shmock/ShmockTest.php +++ b/test/Shmock/ShmockTest.php @@ -217,6 +217,7 @@ function ($mock) { $this->assertEquals($foo::sFoo(), 2); } + public function tearDown() { Shmock::verify();