public function testMultipleAttempt() { $this->soapClientMock->expects($this->at(0))->method('__getLastResponseHeaders')->will($this->returnValue("HTTP/1.1 502 Bad gateway\n\r")); $this->soapClientMock->expects($this->at(0))->method('__soapCall')->will($this->throwException(new \Exception('error', 502))); $this->soapClientMock->expects($this->at(1))->method('__getLastResponseHeaders')->will($this->returnValue("HTTP/1.1 503 Service unavailable Explained\n\r")); $this->soapClientMock->expects($this->at(1))->method('__soapCall')->will($this->throwException(new \Exception('error', 503))); $this->soapClientMock->expects($this->at(2))->method('__getLastResponseHeaders')->will($this->returnValue("HTTP/1.1 504 Gateway timeout Explained\n\r")); $this->soapClientMock->expects($this->at(2))->method('__soapCall')->will($this->throwException(new \Exception('error', 504))); $this->soapClientMock->expects($this->at(4))->method('__getLastResponseHeaders')->will($this->returnValue("HTTP/1.1 200 OK\n\r")); $this->soapClientMock->expects($this->at(4))->method('__soapCall'); $this->transport->expects($this->once())->method('getSoapClient')->will($this->returnValue($this->soapClientMock)); $this->settings->set('wsdl_url', 'http://localhost.not.exists/?wsdl'); $this->transport->init($this->transportEntity); $this->transport->call('test'); }
/** * {@inheritdoc} */ public function init(Transport $transportEntity) { parent::init($transportEntity); $wsiMode = $this->settings->get('wsi_mode', false); $apiUser = $this->settings->get('api_user', false); $apiKey = $this->settings->get('api_key', false); $apiKey = $this->encoder->decryptData($apiKey); if (!$apiUser || !$apiKey) { throw new InvalidConfigurationException("Magento SOAP transport require 'api_key' and 'api_user' settings to be defined."); } // revert initial state $this->isExtensionInstalled = null; $this->isWsiMode = $wsiMode; /** @var string sessionId returned by Magento API login method */ $this->sessionId = $this->call('login', ['username' => $apiUser, 'apiKey' => $apiKey]); }
/** * {@inheritdoc} */ public function init(Transport $transportEntity) { /** * Cache WSDL and force transport entity to use it instead of original URL. * This should be done before parent::init as settings will be cached there. */ if ($transportEntity instanceof MagentoSoapTransport) { $wsdlUrl = $transportEntity->getWsdlUrl(); // Save auth information to be able to perform requests. $urlParts = parse_url($wsdlUrl); if (isset($urlParts['user'], $urlParts['pass'])) { $this->auth['login'] = $urlParts['user']; $this->auth['password'] = $urlParts['pass']; } // Load WSDL to local cache. if (!$this->wsdlManager->isCacheLoaded($wsdlUrl)) { $this->wsdlManager->loadWsdl($wsdlUrl); } // Set cached WSDL path to transport entity. $transportEntity->setWsdlCachePath($this->wsdlManager->getCachedWsdlPath($wsdlUrl)); } parent::init($transportEntity); $wsiMode = $this->settings->get('wsi_mode', false); $apiUser = $this->settings->get('api_user', false); $apiKey = $this->settings->get('api_key', false); $apiKey = $this->encoder->decryptData($apiKey); if (!$apiUser || !$apiKey) { throw new InvalidConfigurationException("Magento SOAP transport require 'api_key' and 'api_user' settings to be defined."); } // revert initial state $this->isExtensionInstalled = null; $this->adminUrl = null; $this->isWsiMode = $wsiMode; /** @var string sessionId returned by Magento API login method */ $this->sessionId = null; $this->sessionId = $this->call('login', ['username' => $apiUser, 'apiKey' => $apiKey]); $this->checkExtensionFunctions(); }