Example #1
0
 public function testDeserializeInvalidEncodedBodyExceptionDeveloperModeOn()
 {
     /** Prepare mocks for SUT constructor. */
     $this->decoderMock->expects($this->once())->method('decode')->will($this->throwException(new \Zend_Json_Exception('Decoding error:' . PHP_EOL . 'Decoding failed: Syntax error')));
     $this->_appStateMock->expects($this->once())->method('getMode')->will($this->returnValue('developer'));
     /** Initialize SUT. */
     $inputInvalidJson = '{"key1":"test1"."key2":"test2"}';
     try {
         $this->_jsonDeserializer->deserialize($inputInvalidJson);
         $this->fail("Exception is expected to be raised");
     } catch (\Magento\Framework\Webapi\Exception $e) {
         $this->assertInstanceOf('Magento\\Framework\\Webapi\\Exception', $e, 'Exception type is invalid');
         $this->assertContains('Decoding error:', $e->getMessage(), 'Exception message is invalid');
         $this->assertEquals(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST, $e->getHttpCode(), 'HTTP code is invalid');
     }
 }