/** * Returns whether or not a call has been made in the associated call recorder. * * @todo Maybe rename this to findMatchedCalls? * * @param Phake_CallRecorder_CallExpectation $expectation * * @return Phake_CallRecorder_VerifierResult */ public function verifyCall(Phake_CallRecorder_CallExpectation $expectation) { $matcher = new Phake_Matchers_MethodMatcher($expectation->getMethod(), $expectation->getArgumentMatchers()); $calls = $this->recorder->getAllCalls(); $matchedCalls = array(); $methodNonMatched = array(); $obj_interactions = false; foreach ($calls as $call) { /* @var $call Phake_CallRecorder_Call */ if ($call->getObject() === $expectation->getObject()) { $obj_interactions = true; $args = $call->getArguments(); if ($matcher->matches($call->getMethod(), $args)) { $matchedCalls[] = $this->recorder->getCallInfo($call); } elseif ($call->getMethod() == $expectation->getMethod()) { $methodNonMatched[] = $call->__toString(); } } } $verifierModeResult = $expectation->getVerifierMode()->verify($matchedCalls); if (!$verifierModeResult->getVerified()) { $additions = ''; if (!$obj_interactions) { $additions .= ' In fact, there are no interactions with this mock.'; } if (count($methodNonMatched)) { $additions .= "\nOther Invocations:\n " . implode("\n ", $methodNonMatched); } return new Phake_CallRecorder_VerifierResult(false, array(), $expectation->__toString() . ', ' . $verifierModeResult->getFailureDescription() . '.' . $additions); } return new Phake_CallRecorder_VerifierResult(true, $matchedCalls); }
public function testNullMatcherWithArguments() { $matcher = new Phake_Matchers_MethodMatcher('method', null); $arguments = array('foo'); $this->assertFalse($matcher->matches('method', $arguments)); }
public function testSetterMatcher() { $matcher = new Phake_Matchers_MethodMatcher('method', array(new Phake_Matchers_ReferenceSetter(42))); $value = 'blah'; $arguments = array(); $arguments[0] =& $value; $matcher->matches('method', $arguments); $this->assertEquals(42, $value); }