validate(); $itemRef = $this->hasRequestParameter('itemDefinition') ? $this->getItemRef($this->getRequestParameter('itemDefinition')) : null; $traceData = json_decode(html_entity_decode($this->getRequestParameter('traceData')), true); try { $serviceContext = $this->getServiceContext(); $stored = 0; $size = count($traceData); foreach ($traceData as $variableIdentifier => $variableValue) { if ( $this ->getRunnerService() ->storeTraceVariable($serviceContext, $itemRef, $variableIdentifier, $variableValue) ) { $stored++; } } $response = [ 'success' => $stored == $size ]; common_Logger::d('Stored "' . $stored . '/' . $size . '" trace variables'); /** @var EventManager $eventManager */ $eventManager = $this->getServiceLocator()->get(EventManager::SERVICE_ID); $event = new TraceVariableStored($serviceContext->getTestSession()->getSessionId(), $traceData); $eventManager->trigger($event); } catch (Exception $e) { $response = $this->getErrorResponse($e); } return $response; } /** * traceData field is required. * * @return array */ protected function getRequiredFields() { return array_merge(parent::getRequiredFields(), ['traceData']); } }