Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExceptionTest.php
Go to the documentation of this file.
1 <?php
9 
10 class ExceptionTest extends \PHPUnit\Framework\TestCase
11 {
15  public function testConstruct()
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  }
38 
44  public function testConstructInvalidHttpCode($httpCode)
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  }
52 
53  public function testGetOriginatorSender()
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  }
67 
68  public function testGetOriginatorReceiver()
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  }
82 
89  {
90  //Each array contains invalid \Exception code.
91  return [[300], [600]];
92  }
93 }
$details
Definition: vault.phtml:10
__()
Definition: __.php:13
$code
Definition: info.phtml:12