/** * 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->getArgumentMatcher()); $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(); try { $matcher->assertMatches($call->getMethod(), $args); $matchedCalls[] = $this->recorder->getCallInfo($call); $this->recorder->markCallVerified($call); } catch (Phake_Exception_MethodMatcherException $e) { if ($call->getMethod() == $expectation->getMethod()) { $message = $e->getMessage(); if (strlen($message)) { $message = "\n{$message}"; } $methodNonMatched[] = $call->__toString() . $message; } } } } $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===\n " . implode("\n===\n ", str_replace("\n", "\n ", $methodNonMatched)) . "\n==="; } return new Phake_CallRecorder_VerifierResult(false, array(), $expectation->__toString() . ', ' . $verifierModeResult->getFailureDescription() . '.' . $additions); } return new Phake_CallRecorder_VerifierResult(true, $matchedCalls); }
public function testMarkingCallsVerified() { $call1 = new Phake_CallRecorder_Call($this->mock, 'someMethod', array()); $call2 = new Phake_CallRecorder_Call($this->mock, 'someMethod', array()); $call3 = new Phake_CallRecorder_Call($this->mock, 'someMethod', array()); $callRecorder = new Phake_CallRecorder_Recorder(); $callRecorder->recordCall($call1); $callRecorder->recordCall($call2); $callRecorder->markCallVerified($call2); $callRecorder->recordCall($call3); $this->assertEquals(array($call1, $call3), $callRecorder->getUnverifiedCalls()); }