13 class SoapTest extends \PHPUnit\Framework\TestCase
64 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
66 $this->_soapServerMock = $this->getMockBuilder(\
Magento\Webapi\Model\Soap\Server::class)
67 ->disableOriginalConstructor()
68 ->setMethods([
'getApiCharset',
'generateUri',
'handle',
'setWSDL',
'setEncoding',
'setReturnResponse'])
70 $this->_wsdlGeneratorMock = $this->getMockBuilder(\
Magento\Webapi\Model\Soap\Wsdl\Generator::class)
71 ->disableOriginalConstructor()
72 ->setMethods([
'generate'])
74 $this->_requestMock = $this->getMockBuilder(\
Magento\Framework\Webapi\Request::class)
75 ->disableOriginalConstructor()
76 ->setMethods([
'getParams',
'getParam',
'getRequestedServices',
'getHttpHost'])
78 $this->_requestMock->expects($this->any())
79 ->method(
'getHttpHost')
80 ->willReturn(
'testHostName.com');
81 $this->_responseMock = $this->getMockBuilder(\
Magento\Framework\Webapi\Response::class)
82 ->disableOriginalConstructor()
83 ->setMethods([
'clearHeaders',
'setHeader',
'sendResponse',
'getHeaders'])
85 $this->_errorProcessorMock = $this->getMockBuilder(\
Magento\Framework\Webapi\ErrorProcessor::class)
86 ->disableOriginalConstructor()
87 ->setMethods([
'maskException'])
90 $this->_appStateMock = $this->createMock(\
Magento\Framework\
App\State::class);
92 $localeResolverMock = $this->getMockBuilder(
93 \
Magento\Framework\Locale\Resolver::class
94 )->disableOriginalConstructor()->setMethods(
97 $localeResolverMock->expects($this->any())->method(
'getLocale')->will($this->returnValue(
'en'));
99 $this->_responseMock->expects($this->any())->method(
'clearHeaders')->will($this->returnSelf());
101 ->expects($this->any())
102 ->method(
'getHeaders')
103 ->will($this->returnValue(
new \
Zend\Http\Headers()));
105 $appconfig = $this->createMock(\
Magento\Framework\
App\Config::class);
106 $objectManagerHelper->setBackwardCompatibleProperty(
112 $this->_soapServerMock->expects($this->any())->method(
'setWSDL')->will($this->returnSelf());
113 $this->_soapServerMock->expects($this->any())->method(
'setEncoding')->will($this->returnSelf());
114 $this->_soapServerMock->expects($this->any())->method(
'setReturnResponse')->will($this->returnSelf());
115 $pathProcessorMock = $this->createMock(\
Magento\Webapi\Controller\PathProcessor::class);
116 $areaListMock = $this->createMock(\
Magento\Framework\
App\AreaList::class);
117 $areaMock = $this->createMock(\
Magento\Framework\
App\AreaInterface::class);
118 $areaListMock->expects($this->any())->method(
'getArea')->will($this->returnValue($areaMock));
120 $rendererMock = $this->getMockBuilder(\
Magento\Framework\Webapi\Rest\
Response\RendererFactory::class)
121 ->disableOriginalConstructor()
123 $this->_soapController = new \Magento\Webapi\Controller\Soap(
125 $this->_responseMock,
126 $this->_wsdlGeneratorMock,
127 $this->_soapServerMock,
128 $this->_errorProcessorMock,
129 $this->_appStateMock,
147 $this->_requestMock->expects($this->once())
148 ->method(
'getParams')
149 ->will($this->returnValue(
$params));
150 $wsdl =
'Some WSDL content';
151 $this->_wsdlGeneratorMock->expects($this->any())->method(
'generate')->will($this->returnValue($wsdl));
153 $this->_soapController->dispatch($this->_requestMock);
154 $this->assertEquals($wsdl, $this->_responseMock->getBody());
165 $this->_requestMock->expects($this->once())
166 ->method(
'getParams')
167 ->will($this->returnValue(
$params));
168 $this->_errorProcessorMock->expects(
173 $this->returnValue(
new \
Magento\Framework\Webapi\Exception(
__(
'message')))
175 $wsdl =
'Some WSDL content';
176 $this->_wsdlGeneratorMock->expects($this->any())->method(
'generate')->will($this->returnValue($wsdl));
178 $this->_soapServerMock->expects($this->any())->method(
'getApiCharset')->will($this->returnValue($encoding));
179 $this->_soapController->dispatch($this->_requestMock);
181 $expectedMessage = <<<EXPECTED_MESSAGE
182 <?xml version=
"1.0" encoding=
"{$encoding}"?>
183 <env:Envelope xmlns:env=
"http://www.w3.org/2003/05/soap-envelope" >
187 <env:Value>env:Sender</env:Value>
190 <env:Text xml:lang=
"en">message</env:Text>
196 $this->assertXmlStringEqualsXmlString($expectedMessage, $this->_responseMock->getBody());
204 $this->_soapServerMock->expects($this->once())->method(
'handle');
205 $response = $this->_soapController->dispatch($this->_requestMock);
206 $this->assertEquals(200,
$response->getHttpResponseCode());
214 $exceptionMessage =
'some error message';
215 $exception = new \Magento\Framework\Webapi\Exception(
__($exceptionMessage));
216 $this->_soapServerMock->expects($this->any())->method(
'handle')->will($this->throwException($exception));
217 $this->_errorProcessorMock->expects(
222 $this->returnValue($exception)
225 $this->_soapServerMock->expects($this->any())->method(
'getApiCharset')->will($this->returnValue($encoding));
227 $this->_soapController->dispatch($this->_requestMock);
229 $expectedMessage = <<<EXPECTED_MESSAGE
230 <?xml version=
"1.0" encoding=
"{$encoding}"?>
231 <env:Envelope xmlns:env=
"http://www.w3.org/2003/05/soap-envelope" >
235 <env:Value>env:Sender</env:Value>
238 <env:Text xml:lang=
"en">some error message</env:Text>
244 $this->assertXmlStringEqualsXmlString($expectedMessage, $this->_responseMock->getBody());
255 $this->_requestMock->expects(
262 $this->returnValue(
$value)
testDispatchSoapRequest()
_mockGetParam($param, $value)
testDispatchInvalidWsdlRequest()
testDispatchWithException()
const REQUEST_PARAM_SERVICES
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]