public function testCall() { $requestedServices = ['requestedServices']; $this->_requestMock->expects($this->once())->method('getRequestedServices')->will($this->returnValue($requestedServices)); $this->_dataObjectConverter->expects($this->once())->method('convertStdObjectToArray')->will($this->returnValue(['field' => 1])); $operationName = 'soapOperation'; $className = 'Magento\\Framework\\DataObject'; $methodName = 'testMethod'; $isSecure = false; $aclResources = [['Magento_TestModule::resourceA']]; $this->_apiConfigMock->expects($this->once())->method('getServiceMethodInfo')->with($operationName, $requestedServices)->will($this->returnValue([ServiceMetadata::KEY_CLASS => $className, ServiceMetadata::KEY_METHOD => $methodName, ServiceMetadata::KEY_IS_SECURE => $isSecure, ServiceMetadata::KEY_ACL_RESOURCES => $aclResources])); $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $serviceMock = $this->getMockBuilder($className)->disableOriginalConstructor()->setMethods([$methodName])->getMock(); $serviceResponse = ['foo' => 'bar']; $serviceMock->expects($this->once())->method($methodName)->will($this->returnValue($serviceResponse)); $this->_objectManagerMock->expects($this->once())->method('get')->with($className)->will($this->returnValue($serviceMock)); $this->_serviceInputProcessorMock->expects($this->once())->method('process')->will($this->returnArgument(2)); /** Execute SUT. */ $this->assertEquals(['result' => $serviceResponse], $this->_handler->__call($operationName, [(object) ['field' => 1]])); }
/** * Test Secure Request and Secure route combinations * * @dataProvider dataProviderSecureRequestSecureRoute */ public function testSecureRouteAndRequest($isSecureRoute, $isSecureRequest) { $this->_serviceMock->expects($this->any())->method(self::SERVICE_METHOD)->will($this->returnValue([])); $this->_routeMock->expects($this->any())->method('isSecure')->will($this->returnValue($isSecureRoute)); $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue([])); $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1'])); $this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue([])); $this->_requestMock->expects($this->any())->method('isSecure')->will($this->returnValue($isSecureRequest)); $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $this->serviceInputProcessorMock->expects($this->any())->method('process')->will($this->returnValue([])); $this->_restController->dispatch($this->_requestMock); $this->assertFalse($this->_responseMock->isException()); }