![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-webapi/Test/Unit/ |
<?php /** * Test Webapi module exception. * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Webapi\Test\Unit; use Magento\Framework\Webapi\Exception; use Magento\Webapi\Model\Soap\Fault; use PHPUnit\Framework\TestCase; class ExceptionTest extends TestCase { /** * Test Webapi exception construct. */ public function testConstruct() { $code = 1111; $details = ['key1' => 'value1', 'key2' => 'value2']; $apiException = new Exception( __('Message'), $code, Exception::HTTP_UNAUTHORIZED, $details ); $this->assertEquals( $apiException->getHttpCode(), Exception::HTTP_UNAUTHORIZED, 'Exception code is set incorrectly in construct.' ); $this->assertEquals( $apiException->getMessage(), 'Message', 'Exception message is set incorrectly in construct.' ); $this->assertEquals($apiException->getCode(), $code, 'Exception code is set incorrectly in construct.'); $this->assertEquals($apiException->getDetails(), $details, 'Details are set incorrectly in construct.'); } /** * Test Webapi exception construct with invalid data. * * @dataProvider providerForTestConstructInvalidHttpCode */ public function testConstructInvalidHttpCode($httpCode) { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("The specified HTTP code \"{$httpCode}\" is invalid."); /** Create \Magento\Framework\Webapi\Exception object with invalid code. */ /** Valid codes range is from 400 to 599. */ new Exception(__('Message'), 0, $httpCode); } public function testGetOriginatorSender() { $apiException = new Exception( __('Message'), 0, Exception::HTTP_UNAUTHORIZED ); /** Check that Webapi \Exception object with code 401 matches Sender originator.*/ $this->assertEquals( Fault::FAULT_CODE_SENDER, $apiException->getOriginator(), 'Wrong Sender originator detecting.' ); } public function testGetOriginatorReceiver() { $apiException = new Exception( __('Message'), 0, Exception::HTTP_INTERNAL_ERROR ); /** Check that Webapi \Exception object with code 500 matches Receiver originator.*/ $this->assertEquals( Fault::FAULT_CODE_RECEIVER, $apiException->getOriginator(), 'Wrong Receiver originator detecting.' ); } /** * Data provider for testConstructInvalidCode. * * @return array */ public function providerForTestConstructInvalidHttpCode() { //Each array contains invalid \Exception code. return [[300], [600]]; } }