protected function setUp() { $this->_soapConfigMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Config')->disableOriginalConstructor()->getMock(); $_wsdlMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Wsdl')->disableOriginalConstructor()->setMethods(array('addSchemaTypeSection', 'addService', 'addPortType', 'addBinding', 'addSoapBinding', 'addElement', 'addComplexType', 'addMessage', 'addPortOperation', 'addBindingOperation', 'addSoapOperation', 'toXML'))->getMock(); $this->_wsdlFactoryMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Wsdl\\Factory')->setMethods(array('create'))->disableOriginalConstructor()->getMock(); $this->_wsdlFactoryMock->expects($this->any())->method('create')->will($this->returnValue($_wsdlMock)); $this->_cacheMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Cache\\Type')->disableOriginalConstructor()->getMock(); $this->_cacheMock->expects($this->any())->method('load')->will($this->returnValue(false)); $this->_cacheMock->expects($this->any())->method('save')->will($this->returnValue(true)); $this->_typeProcessor = $this->getMock('Magento\\Webapi\\Model\\Config\\ClassReflector\\TypeProcessor', array(), array(), '', false); $this->_wsdlGenerator = new \Magento\Webapi\Model\Soap\Wsdl\Generator($this->_soapConfigMock, $this->_wsdlFactoryMock, $this->_cacheMock, $this->_typeProcessor); parent::setUp(); }
protected function setUp() { $this->_soapConfigMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Config')->disableOriginalConstructor()->getMock(); $_wsdlMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Wsdl')->disableOriginalConstructor()->setMethods(['addSchemaTypeSection', 'addService', 'addPortType', 'addBinding', 'addSoapBinding', 'addElement', 'addComplexType', 'addMessage', 'addPortOperation', 'addBindingOperation', 'addSoapOperation', 'toXML'])->getMock(); $this->_wsdlFactoryMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Wsdl\\Factory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->_wsdlFactoryMock->expects($this->any())->method('create')->will($this->returnValue($_wsdlMock)); $this->_cacheMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Cache\\Type')->disableOriginalConstructor()->getMock(); $this->_cacheMock->expects($this->any())->method('load')->will($this->returnValue(false)); $this->_cacheMock->expects($this->any())->method('save')->will($this->returnValue(true)); $this->_typeProcessor = $this->getMock('Magento\\Framework\\Reflection\\TypeProcessor', [], [], '', false); $this->storeManagerMock = $this->getMockBuilder('Magento\\Framework\\Store\\StoreManagerInterface')->setMethods(['getStore'])->disableOriginalConstructor()->getMockForAbstractClass(); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getCode', '__wakeup'])->disableOriginalConstructor()->getMock(); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $storeMock->expects($this->any())->method('getCode')->will($this->returnValue('store_code')); $helper = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_wsdlGenerator = $helper->getObject('Magento\\Webapi\\Model\\Soap\\Wsdl\\Generator', ['apiConfig' => $this->_soapConfigMock, 'wsdlFactory' => $this->_wsdlFactoryMock, 'cache' => $this->_cacheMock, 'typeProcessor' => $this->_typeProcessor, 'storeManagerMock' => $this->storeManagerMock]); parent::setUp(); }
/** * Generate WSDL file based on requested services (uses cache) * * @param array $requestedServices * @param string $endPointUrl * @return string * @throws \Exception */ public function generate($requestedServices, $endPointUrl) { /** Sort requested services by names to prevent caching of the same wsdl file more than once. */ ksort($requestedServices); $cacheId = self::WSDL_CACHE_ID . hash('md5', serialize($requestedServices)); $cachedWsdlContent = $this->_cache->load($cacheId); if ($cachedWsdlContent !== false) { return $cachedWsdlContent; } $services = array(); foreach ($requestedServices as $serviceName) { $services[$serviceName] = $this->_apiConfig->getServiceMetadata($serviceName); } $wsdlContent = $this->_generate($services, $endPointUrl); $this->_cache->save($wsdlContent, $cacheId, array(\Magento\Webapi\Model\Cache\Type::CACHE_TAG)); return $wsdlContent; }
/** * Retrieve requested service method params metadata. * * @param string $serviceClassName * @param string $serviceMethodName * @return array */ protected function getMethodParams($serviceClassName, $serviceMethodName) { $cacheId = self::CACHE_ID_PREFIX . hash('md5', $serviceClassName . $serviceMethodName); $params = $this->cache->load($cacheId); if ($params !== false) { return unserialize($params); } $serviceClass = new ClassReflection($serviceClassName); /** @var MethodReflection $serviceMethod */ $serviceMethod = $serviceClass->getMethod($serviceMethodName); $params = []; /** @var ParameterReflection $paramReflection */ foreach ($serviceMethod->getParameters() as $paramReflection) { $isDefaultValueAvailable = $paramReflection->isDefaultValueAvailable(); $params[] = ['name' => $paramReflection->getName(), 'type' => $this->typeProcessor->getParamType($paramReflection), 'isDefaultValueAvailable' => $isDefaultValueAvailable, 'defaultValue' => $isDefaultValueAvailable ? $paramReflection->getDefaultValue() : null]; } $this->cache->save(serialize($params), $cacheId, [\Magento\Webapi\Model\Cache\Type::CACHE_TAG]); return $params; }