moduleDirectory = $moduleDirectory; $this->fileIo = $fileIo; $this->arrayManager = $arrayManager; } /** * Loads mock json response for a given request * * @param array $request * @return string * @throws NotFoundException */ public function loadForRestRequest(array $request): string { $moduleDir = $this->moduleDirectory->getDir('Magento_TestModuleFedex'); $type = strtolower($this->arrayManager->get(static::REST_PATH_SERVICE_TYPE, $request) ?? 'general'); $country = strtolower($this->arrayManager->get(static::REST_PATH_COUNTRY, $request) ?? ''); $responsePath = sprintf(static::REST_RESPONSE_FILE_PATTERN, $moduleDir, $type, $country); if (!$this->fileIo->fileExists($responsePath)) { throw new NotFoundException( __('"%1" is not a valid mock response type for country "%2".', $type, $country) ); } return $this->fileIo->read($responsePath); } /** * Load mock json response for a given request */ public function loadForAuthRequest() { $moduleDir = $this->moduleDirectory->getDir('Magento_TestModuleFedex'); $responsePath = sprintf(static::REST_AUTH_RESPONSE_FILE, $moduleDir); if (!$this->fileIo->fileExists($responsePath)) { throw new NotFoundException( __('No valid mock response found for Authentication.') ); } return $this->fileIo->read($responsePath); } }