public function postRun(Scenario $scenario, ValueBag $values, ValueBag $extra) { if ($extra->has('blackfire_build')) { $build = $extra->get('blackfire_build'); // did we profiled anything? if (!$build->getJobCount()) { // don't finish the build as it won't work with 0 profiles $this->logger->error(sprintf('Report "%s" aborted as it has no profiles', $scenario->getTitle())); $extra->remove('blackfire_build'); return; } $extra->set('blackfire_report', $report = $this->blackfire->endBuild($build)); $extra->remove('blackfire_build'); } // avoid getting the report if not needed if (!$this->logger) { return; } try { if ($report->isErrored()) { $this->logger->critical(sprintf('Report "%s" errored', $scenario->getTitle())); } else { if ($report->isSuccessful()) { $this->logger->debug(sprintf('Report "%s" pass', $scenario->getTitle())); } else { $this->logger->error(sprintf('Report "%s" failed', $scenario->getTitle())); } } } catch (BlackfireException $e) { $this->logger->critical(sprintf('Report "%s" is not available (%s)', $scenario->getTitle(), $e->getMessage())); } $this->logger->info(sprintf('Report "%s" URL: %s', $scenario->getTitle(), $report->getUrl())); }
private function extractVariables($extractions, ValueBag $values = null, Crawler $crawler = null, RequestInterface $request, ResponseInterface $response) { if (null === $values) { throw new LogicException('Unable to extract variables if no ValueBag is registered.'); } $variables = $this->createVariables($response, $crawler); foreach ($extractions as $name => $extract) { list($expression, $attributes) = $extract; if (!is_array($attributes)) { $attributes = [$attributes]; } try { $data = $this->language->evaluate($expression, $variables + $values->all(true)); if ($data instanceof Crawler) { $value = $data->extract($attributes); if (count($attributes) == 1) { $data = count($data) > 1 ? $value : $value[0]; } else { $data = $value; } } $values->set($name, $data); } catch (ExpressionSyntaxError $e) { $msg = sprintf('Syntax Error in "%s": %s', $expression, $e->getMessage()); $this->logger and $this->logger->critical($msg, ['request' => $request->getHeaderLine('X-Request-Id')]); throw new ExpectationErrorException($msg); } } }
private function extractVariables($extractions, ValueBag $values = null, Crawler $crawler = null, RequestInterface $request, ResponseInterface $response) { if (null === $values) { throw new LogicException('Unable to extract variables if no ValueBag is registered.'); } $variables = $this->createVariables($response, $crawler); foreach ($extractions as $name => $expression) { try { $data = $this->language->evaluate($expression, $variables + $values->all(true)); if ($data instanceof Crawler) { $data = $data->extract('_text'); $data = count($data) > 1 ? $data : $data[0]; } $msg = sprintf('Extracting value form "%s": %s', $name, is_scalar($data) ? $data : '[Non-scalar-data]'); $this->logger and $this->logger->debug($msg, ['request' => $request->getHeaderLine('X-Request-Id')]); $values->set($name, $data); } catch (ExpressionSyntaxError $e) { $msg = sprintf('Syntax Error in "%s": %s', $expression, $e->getMessage()); $this->logger and $this->logger->critical($msg, ['request' => $request->getHeaderLine('X-Request-Id')]); throw new ExpectationErrorException($msg); } } }