/** * @param \Kodova\Poser\Invocation\Invocation $wanted * @param \Kodova\Poser\Invocation\InvocationContainer $invocationContainer * @throws TimesException */ public function verify(Invocation $wanted, InvocationContainer $invocationContainer) { $invocations = $invocationContainer->getInvocations(function (Invocation $invocation) use($wanted) { if ($invocation->wasStubbed()) { return false; } return $wanted->matches($invocation); }); $actual = sizeof($invocations); if ($this->wantedCount == 0 && $actual > 0) { throw new TimesException($this->wantedCount, $invocations); } elseif ($this->wantedCount < $actual) { throw new TimesException($this->wantedCount, $invocations); } elseif ($this->wantedCount > $actual) { throw new TimesException($this->wantedCount, $invocations); } }
/** * @param $method * @param $args * @return mixed */ public function handle($method, $args) { $matchers = $this->mockingMonitor->getArgumentMatcherMonitor()->pullMatchers(); $stackTrace = debug_backtrace(); $invocation = new Invocation($this->mock, $method, $args, $matchers, $stackTrace); $verifcation = $this->mockingMonitor->currentVerification($this->mock); if ($verifcation != null) { $verifcation->getType()->verify($invocation, $this->invocationContainer); return null; } $this->invocationContainer->reportInvocataion($invocation, $matchers); $stub = new Stub($invocation); $this->mockingMonitor->reportStubbing(new OngoingStubbing($this->invocationContainer, $stub, $invocation)); $stubbedInvocation = $this->invocationContainer->findAnswerFor($invocation); if ($stubbedInvocation == null) { return $this->options->getDefaultAnswer()->answer($invocation); } else { $this->mockingMonitor->reset(); return $stubbedInvocation->answer($invocation); } }
/** * @param \Kodova\Poser\Invocation\Answer $answer * @return Stubbable|void */ public function thenAnswer(Answer $answer) { $this->invocation->markStubbed(); $this->stub->addAnswer($answer); $this->invocationContainer->addStub($this->stub); }