Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ExceptionTest Class Reference
Inheritance diagram for ExceptionTest:

Public Member Functions

 testConstruct ()
 
 testConstructInvalidHttpCode ($httpCode)
 
 testGetOriginatorSender ()
 
 testGetOriginatorReceiver ()
 
 providerForTestConstructInvalidHttpCode ()
 

Detailed Description

Definition at line 10 of file ExceptionTest.php.

Member Function Documentation

◆ providerForTestConstructInvalidHttpCode()

providerForTestConstructInvalidHttpCode ( )

Data provider for testConstructInvalidCode.

Returns
array

Definition at line 88 of file ExceptionTest.php.

89  {
90  //Each array contains invalid \Exception code.
91  return [[300], [600]];
92  }

◆ testConstruct()

testConstruct ( )

Test Webapi exception construct.

Definition at line 15 of file ExceptionTest.php.

16  {
17  $code = 1111;
18  $details = ['key1' => 'value1', 'key2' => 'value2'];
19  $apiException = new \Magento\Framework\Webapi\Exception(
20  __('Message'),
21  $code,
22  \Magento\Framework\Webapi\Exception::HTTP_UNAUTHORIZED,
23  $details
24  );
25  $this->assertEquals(
26  $apiException->getHttpCode(),
28  'Exception code is set incorrectly in construct.'
29  );
30  $this->assertEquals(
31  $apiException->getMessage(),
32  'Message',
33  'Exception message is set incorrectly in construct.'
34  );
35  $this->assertEquals($apiException->getCode(), $code, 'Exception code is set incorrectly in construct.');
36  $this->assertEquals($apiException->getDetails(), $details, 'Details are set incorrectly in construct.');
37  }
$details
Definition: vault.phtml:10
__()
Definition: __.php:13
$code
Definition: info.phtml:12

◆ testConstructInvalidHttpCode()

testConstructInvalidHttpCode (   $httpCode)

Test Webapi exception construct with invalid data.

@dataProvider providerForTestConstructInvalidHttpCode

Create \Magento\Framework\Webapi\Exception object with invalid code.

Valid codes range is from 400 to 599.

Definition at line 44 of file ExceptionTest.php.

45  {
46  $this->expectException('InvalidArgumentException');
47  $this->expectExceptionMessage("The specified HTTP code \"{$httpCode}\" is invalid.");
50  new \Magento\Framework\Webapi\Exception(__('Message'), 0, $httpCode);
51  }
__()
Definition: __.php:13

◆ testGetOriginatorReceiver()

testGetOriginatorReceiver ( )

Check that Webapi \Exception object with code 500 matches Receiver originator.

Definition at line 68 of file ExceptionTest.php.

69  {
70  $apiException = new \Magento\Framework\Webapi\Exception(
71  __('Message'),
72  0,
73  \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR
74  );
76  $this->assertEquals(
77  \Magento\Webapi\Model\Soap\Fault::FAULT_CODE_RECEIVER,
78  $apiException->getOriginator(),
79  'Wrong Receiver originator detecting.'
80  );
81  }
__()
Definition: __.php:13

◆ testGetOriginatorSender()

testGetOriginatorSender ( )

Check that Webapi \Exception object with code 401 matches Sender originator.

Definition at line 53 of file ExceptionTest.php.

54  {
55  $apiException = new \Magento\Framework\Webapi\Exception(
56  __('Message'),
57  0,
58  \Magento\Framework\Webapi\Exception::HTTP_UNAUTHORIZED
59  );
61  $this->assertEquals(
62  \Magento\Webapi\Model\Soap\Fault::FAULT_CODE_SENDER,
63  $apiException->getOriginator(),
64  'Wrong Sender originator detecting.'
65  );
66  }
__()
Definition: __.php:13

The documentation for this class was generated from the following file: