Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BaseService.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Framework\Webapi\Exception as WebapiException;
10 
15 {
22  protected function assertUnauthorizedException($serviceInfo, $requestData = null)
23  {
24  if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
25  $this->_assertSoapException(
26  $serviceInfo,
28  "The consumer isn't authorized to access %resources."
29  );
30  } elseif (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) {
31  $this->_assertRestUnauthorizedException($serviceInfo, $requestData);
32  }
33  }
34 
41  protected function _assertRestUnauthorizedException($serviceInfo, $requestData = null)
42  {
43  try {
44  $this->_webApiCall($serviceInfo, $requestData);
45  } catch (\Exception $e) {
46  $this->assertContains(
47  '{"message":"The consumer isn\'t authorized to access %resources.',
48  $e->getMessage(),
49  sprintf(
50  'REST routing did not fail as expected for the method "%s" of service "%s"',
51  $serviceInfo['rest']['httpMethod'],
52  $serviceInfo['rest']['resourcePath']
53  )
54  );
55  $this->assertEquals(WebapiException::HTTP_UNAUTHORIZED, $e->getCode());
56  }
57  }
58 
65  protected function _assertNoRouteOrOperationException($serviceInfo, $requestData = null)
66  {
67  if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
68  $this->_assertSoapException($serviceInfo, $requestData);
69  } elseif (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) {
70  $this->_assertNoRestRouteException($serviceInfo, $requestData);
71  }
72  }
73 
80  protected function _assertNoRestRouteException($serviceInfo, $requestData = null)
81  {
82  try {
83  $this->_webApiCall($serviceInfo, $requestData);
84  } catch (\Exception $e) {
85  $error = json_decode($e->getMessage(), true);
86  $this->assertEquals('Request does not match any route.', $error['message']);
87  $this->assertEquals(WebapiException::HTTP_NOT_FOUND, $e->getCode());
88  }
89  }
90 
98  protected function _assertSoapException($serviceInfo, $requestData = null, $expectedMessage = '')
99  {
100  try {
101  $this->_webApiCall($serviceInfo, $requestData);
102  } catch (\Exception $e) {
103  if (get_class($e) !== 'SoapFault') {
104  $this->fail(
105  sprintf(
106  'Expected SoapFault exception not generated for Service - "%s" and Operation - "%s"',
107  $serviceInfo['soap']['service'],
108  $serviceInfo['soap']['operation']
109  )
110  );
111  }
112 
113  if ($expectedMessage) {
114  $this->assertContains($expectedMessage, $e->getMessage());
115  }
116  }
117  }
118 }
_assertRestUnauthorizedException($serviceInfo, $requestData=null)
Definition: BaseService.php:41
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_assertNoRouteOrOperationException($serviceInfo, $requestData=null)
Definition: BaseService.php:65
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
_assertSoapException($serviceInfo, $requestData=null, $expectedMessage='')
Definition: BaseService.php:98
assertUnauthorizedException($serviceInfo, $requestData=null)
Definition: BaseService.php:22
_assertNoRestRouteException($serviceInfo, $requestData=null)
Definition: BaseService.php:80