/**
  * Return services loaded from cache if enabled or from files merged previously
  *
  * @return array
  */
 public function getServices()
 {
     if (null === $this->services) {
         $services = $this->cache->load(self::CACHE_ID);
         if ($services && is_string($services)) {
             $this->services = unserialize($services);
         } else {
             $this->services = $this->configReader->read();
             $this->cache->save(serialize($this->services), self::CACHE_ID);
         }
     }
     return $this->services;
 }
示例#2
0
 protected function setUp()
 {
     $this->serviceMetadata = $this->getMockBuilder('Magento\\Webapi\\Model\\ServiceMetadata')->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\\WsdlFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->_wsdlFactoryMock->expects($this->any())->method('create')->will($this->returnValue($_wsdlMock));
     $this->_cacheMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Cache\\Type\\Webapi')->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);
     /** @var \Magento\Framework\Webapi\Authorization|\PHPUnit_Framework_MockObject_MockObject $authorizationMock */
     $authorizationMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\Authorization')->disableOriginalConstructor()->getMock();
     $authorizationMock->expects($this->any())->method('isAllowed')->willReturn(true);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->customAttributeTypeLocator = $objectManager->getObject('Magento\\Eav\\Model\\EavCustomAttributeTypeLocator');
     $this->_wsdlGenerator = $objectManager->getObject('Magento\\Webapi\\Model\\Soap\\Wsdl\\Generator', ['wsdlFactory' => $this->_wsdlFactoryMock, 'cache' => $this->_cacheMock, 'typeProcessor' => $this->_typeProcessor, 'customAttributeTypeLocator' => $this->customAttributeTypeLocator, 'serviceMetadata' => $this->serviceMetadata, 'authorization' => $authorizationMock]);
     parent::setUp();
 }
示例#3
0
 protected function setUp()
 {
     $this->serviceMetadataMock = $this->getMockBuilder('Magento\\Webapi\\Model\\ServiceMetadata')->disableOriginalConstructor()->getMock();
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $swagger = $this->objectManager->getObject('Magento\\Webapi\\Model\\Rest\\Swagger');
     $this->swaggerFactoryMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Rest\\SwaggerFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->swaggerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($swagger));
     $this->cacheMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Cache\\Type\\Webapi')->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->typeProcessorMock = $this->getMockBuilder('Magento\\Framework\\Reflection\\TypeProcessor')->disableOriginalConstructor()->getMock();
     $this->typeProcessorMock->expects($this->any())->method('getOperationName')->will($this->returnValue(self::OPERATION_NAME));
     $this->customAttributeTypeLocatorMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\CustomAttributeTypeLocatorInterface')->disableOriginalConstructor()->getMock();
     $this->customAttributeTypeLocatorMock->expects($this->any())->method('getAllServiceDataInterfaces')->willReturn(['$customAttributeClass']);
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->any())->method('getCode')->will($this->returnValue('store_code'));
     /** @var \Magento\Framework\Webapi\Authorization|\PHPUnit_Framework_MockObject_MockObject $authorizationMock */
     $authorizationMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\Authorization')->disableOriginalConstructor()->getMock();
     $authorizationMock->expects($this->any())->method('isAllowed')->willReturn(true);
     $this->generator = $this->objectManager->getObject('Magento\\Webapi\\Model\\Rest\\Swagger\\Generator', ['swaggerFactory' => $this->swaggerFactoryMock, 'cache' => $this->cacheMock, 'typeProcessor' => $this->typeProcessorMock, 'serviceMetadata' => $this->serviceMetadataMock, 'customAttributeTypeLocator' => $this->customAttributeTypeLocatorMock, 'authorization' => $authorizationMock]);
 }
 /**
  * Generate schema based on requested services (uses cache)
  *
  * @param array $requestedServices
  * @param string $requestScheme
  * @param string $requestHost
  * @param string $endPointUrl
  * @return string
  */
 public function generate($requestedServices, $requestScheme, $requestHost, $endPointUrl)
 {
     /** Sort requested services by names to prevent caching of the same schema file more than once. */
     ksort($requestedServices);
     $cacheId = $this->cache->generateCacheIdUsingContext(get_class($this) . serialize($requestedServices));
     $cachedSchemaContent = $this->cache->load($cacheId);
     if ($cachedSchemaContent !== false) {
         return $cachedSchemaContent;
     }
     $allowedServicesMetadata = $this->getAllowedServicesMetadata($requestedServices);
     $this->collectCallInfo($allowedServicesMetadata);
     $schemaContent = $this->generateSchema($allowedServicesMetadata, $requestScheme, $requestHost, $endPointUrl);
     $this->cache->save($schemaContent, $cacheId, [Webapi::CACHE_TAG]);
     return $schemaContent;
 }
 /**
  * Return routes loaded from cache if enabled or from files merged previously
  *
  * @return array
  */
 public function getRoutesConfig()
 {
     if (null === $this->routes) {
         $routesConfig = $this->cache->load(self::ROUTES_CONFIG_CACHE_ID);
         $typesData = $this->cache->load(self::REFLECTED_TYPES_CACHE_ID);
         if ($routesConfig && is_string($routesConfig) && $typesData && is_string($typesData)) {
             $this->routes = unserialize($routesConfig);
             $this->typeProcessor->setTypesData(unserialize($typesData));
         } else {
             $this->routes = $this->initRoutesMetadata();
             $this->cache->save(serialize($this->routes), self::ROUTES_CONFIG_CACHE_ID);
             $this->cache->save(serialize($this->typeProcessor->getTypesData()), self::REFLECTED_TYPES_CACHE_ID);
         }
     }
     return $this->routes;
 }