当前位置: 首页>>代码示例>>PHP>>正文


PHP InputException::getRawMessage方法代码示例

本文整理汇总了PHP中Magento\Framework\Exception\InputException::getRawMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP InputException::getRawMessage方法的具体用法?PHP InputException::getRawMessage怎么用?PHP InputException::getRawMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Exception\InputException的用法示例。


在下文中一共展示了InputException::getRawMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAddErrorWithSameMessage

 /**
  * Verify the message and params are not used to determine the call count
  *
  * @return void
  */
 public function testAddErrorWithSameMessage()
 {
     $rawMessage = 'Foo "%var"';
     $params = ['var' => 'Bar'];
     $expectedProcessedMessage = 'Foo "Bar"';
     $inputException = new InputException(new Phrase($rawMessage, $params));
     $this->assertEquals($rawMessage, $inputException->getRawMessage());
     $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
     $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
     $this->assertFalse($inputException->wasErrorAdded());
     $this->assertCount(0, $inputException->getErrors());
     $inputException->addError(new Phrase($rawMessage, $params));
     $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
     $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
     $this->assertTrue($inputException->wasErrorAdded());
     $this->assertCount(0, $inputException->getErrors());
     $inputException->addError(new Phrase($rawMessage, $params));
     $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
     $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
     $this->assertTrue($inputException->wasErrorAdded());
     $errors = $inputException->getErrors();
     $this->assertCount(2, $errors);
     $this->assertEquals($expectedProcessedMessage, $errors[0]->getMessage());
     $this->assertEquals($expectedProcessedMessage, $errors[0]->getLogMessage());
     $this->assertEquals($expectedProcessedMessage, $errors[1]->getMessage());
     $this->assertEquals($expectedProcessedMessage, $errors[1]->getLogMessage());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:32,代码来源:InputExceptionTest.php

示例2: testCreateCustomerWithErrors

 public function testCreateCustomerWithErrors()
 {
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'CreateAccount']];
     $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray($this->customerHelper->createSampleCustomerDataObject(), '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $invalidEmail = 'invalid';
     $customerDataArray['email'] = $invalidEmail;
     $requestData = ['customer' => $customerDataArray, 'password' => CustomerHelper::PASSWORD];
     try {
         $this->_webApiCall($serviceInfo, $requestData);
         $this->fail('Expected exception did not occur.');
     } catch (\Exception $e) {
         if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
             $expectedException = new InputException();
             $expectedException->addError(__(InputException::INVALID_FIELD_VALUE, ['fieldName' => 'email', 'value' => $invalidEmail]));
             $this->assertInstanceOf('SoapFault', $e);
             $this->checkSoapFault($e, $expectedException->getRawMessage(), 'env:Sender', $expectedException->getParameters());
         } else {
             $this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
             $exceptionData = $this->processRestExceptionResult($e);
             $expectedExceptionData = ['message' => InputException::INVALID_FIELD_VALUE, 'parameters' => ['fieldName' => 'email', 'value' => $invalidEmail]];
             $this->assertEquals($expectedExceptionData, $exceptionData);
         }
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:24,代码来源:AccountManagementTest.php

示例3: testCreateCustomerWithoutAddressRequiresException

 /**
  * Test creating a customer with absent required address fields
  */
 public function testCreateCustomerWithoutAddressRequiresException()
 {
     $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray($this->customerHelper->createSampleCustomerDataObject(), '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     foreach ($customerDataArray[Customer::KEY_ADDRESSES] as &$address) {
         $address[Address::FIRSTNAME] = null;
     }
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Save']];
     $requestData = ['customer' => $customerDataArray];
     try {
         $this->_webApiCall($serviceInfo, $requestData);
         $this->fail('Expected exception did not occur.');
     } catch (\Exception $e) {
         if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
             $expectedException = new InputException();
             $expectedException->addError(__('%fieldName is a required field.', ['fieldName' => Address::FIRSTNAME]));
             $this->assertInstanceOf('SoapFault', $e);
             $this->checkSoapFault($e, $expectedException->getRawMessage(), 'env:Sender', $expectedException->getParameters());
         } else {
             $this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
             $exceptionData = $this->processRestExceptionResult($e);
             $expectedExceptionData = ['message' => '%fieldName is a required field.', 'parameters' => ['fieldName' => Address::FIRSTNAME]];
             $this->assertEquals($expectedExceptionData, $exceptionData);
         }
     }
     try {
         $this->customerRegistry->retrieveByEmail($customerDataArray[Customer::EMAIL], $customerDataArray[Customer::WEBSITE_ID]);
         $this->fail('An expected NoSuchEntityException was not thrown.');
     } catch (NoSuchEntityException $e) {
         $exception = NoSuchEntityException::doubleField('email', $customerDataArray[Customer::EMAIL], 'websiteId', $customerDataArray[Customer::WEBSITE_ID]);
         $this->assertEquals($exception->getMessage(), $e->getMessage(), 'Exception message does not match expected message.');
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:35,代码来源:CustomerRepositoryTest.php


注:本文中的Magento\Framework\Exception\InputException::getRawMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。