private function searchForMatchingExpectation(ServerRequestInterface $request) { $lastFound = null; foreach ($this->storage->listExpectations() as $expectation) { $lastFound = $this->getNextMatchingExpectation($lastFound, $request, $expectation); } return $lastFound; }
public function loadExpectationFromFile($fileName) { $this->logger->debug("Loading expectation file {$fileName}"); $content = file_get_contents($fileName); $data = @json_decode($content, true); if (json_last_error() != JSON_ERROR_NONE) { throw new \Exception(json_last_error_msg()); } $expectation = $this->requestBuilder->parseRequest($data, Expectation::class, RequestBuilder::RETURN_ALL_ERRORS_IN_EXCEPTION); $this->validateExpectationOrThrowException($expectation, $this->logger); $this->logger->debug('Parsed expectation: ' . var_export($expectation, true)); $this->storage->addExpectation($expectation); }
/** * * {@inheritDoc} * * @see \Mcustiel\PowerRoute\Actions\ActionInterface::execute() */ public function execute(TransactionData $transactionData, $argument = null) { $list = json_encode($this->storage->listExpectations()); $transactionData->setResponse($transactionData->getResponse()->withBody(new StringStream($list))->withHeader('Content-type', 'application/json')); }