Definition at line 8 of file XmlTest.php.
◆ setUp()
Prepare mocks for SUT constructor.
Initialize SUT.
Definition at line 19 of file XmlTest.php.
22 $this->_xmlParserMock = $this->createPartialMock(
23 \
Magento\Framework\Xml\Parser::class,
24 [
'xmlToArray',
'loadXML']
26 $this->_appStateMock = $this->createMock(\
Magento\Framework\
App\State::class);
28 $this->_xmlDeserializer = new \Magento\Framework\Webapi\Rest\Request\Deserializer\Xml(
29 $this->_xmlParserMock,
◆ tearDown()
Definition at line 35 of file XmlTest.php.
37 unset($this->_xmlDeserializer);
38 unset($this->_xmlParserMock);
39 unset($this->_appStateMock);
◆ testDeserialize()
Prepare mocks for SUT constructor.
Initialize SUT.
Definition at line 50 of file XmlTest.php.
53 $this->_xmlParserMock->expects($this->once())->method(
'loadXML');
54 $validInputXml =
'<?xml version="1.0"?><xml><key1>test1</key1><key2>test2</key2></xml>';
55 $returnArray = [
'xml' => [
'key1' =>
'test1',
'key2' =>
'test2']];
56 $this->_xmlParserMock->expects($this->once())->method(
'xmlToArray')->will($this->returnValue($returnArray));
57 $expectedArray = [
'key1' =>
'test1',
'key2' =>
'test2'];
61 $this->_xmlDeserializer->deserialize($validInputXml),
62 'Request XML body was parsed incorrectly into array of params.'
◆ testDeserializeInvalidArgumentException()
testDeserializeInvalidArgumentException |
( |
| ) |
|
Definition at line 43 of file XmlTest.php.
45 $this->expectException(
'InvalidArgumentException');
46 $this->expectExceptionMessage(
'"boolean" data type is invalid. String is expected.');
47 $this->_xmlDeserializer->deserialize(
false);
◆ testDeserializeMagentoWebapiExceptionDeveloperModeOff()
testDeserializeMagentoWebapiExceptionDeveloperModeOff |
( |
| ) |
|
Prepare mocks for SUT constructor.
Initialize SUT.
Definition at line 117 of file XmlTest.php.
120 $this->_appStateMock->expects($this->once())
122 ->will($this->returnValue(
'production'));
123 $errorMessage =
'End tag for "key1" was omitted.';
124 $this->_xmlDeserializer->handleErrors(
null, $errorMessage,
null,
null);
125 $this->_xmlParserMock->expects($this->once())->method(
'loadXML');
126 $invalidXml =
'<?xml version="1.0"?><xml><key1>test1</xml>';
129 $this->_xmlDeserializer->deserialize($invalidXml);
130 $this->fail(
"Exception is expected to be raised");
131 }
catch (\
Magento\Framework\Webapi\Exception $e) {
132 $this->assertInstanceOf(\
Magento\Framework\Webapi\Exception::class, $e,
'Exception type is invalid');
133 $this->assertEquals(
'Decoding error.', $e->getMessage(),
'Exception message is invalid');
137 'HTTP code is invalid'
◆ testDeserializeMagentoWebapiExceptionDeveloperModeOn()
testDeserializeMagentoWebapiExceptionDeveloperModeOn |
( |
| ) |
|
Prepare mocks for SUT constructor.
Initialize SUT.
Definition at line 91 of file XmlTest.php.
94 $this->_appStateMock->expects($this->once())
96 ->will($this->returnValue(
'developer'));
97 $errorMessage =
'End tag for "key1" was omitted.';
98 $this->_xmlDeserializer->handleErrors(
null, $errorMessage,
null,
null);
99 $this->_xmlParserMock->expects($this->once())->method(
'loadXML');
100 $invalidXml =
'<?xml version="1.0"?><xml><key1>test1</xml>';
103 $this->_xmlDeserializer->deserialize($invalidXml);
104 $this->fail(
"Exception is expected to be raised");
105 }
catch (\
Magento\Framework\Webapi\Exception $e) {
106 $exceptionMessage =
'Decoding Error: End tag for "key1" was omitted.';
107 $this->assertInstanceOf(\
Magento\Framework\Webapi\Exception::class, $e,
'Exception type is invalid');
108 $this->assertEquals($exceptionMessage, $e->getMessage(),
'Exception message is invalid');
112 'HTTP code is invalid'
◆ testHandleErrors()
Add error message
Assert that first error message was added
Add error message
Assert that both error messages were added
Definition at line 66 of file XmlTest.php.
69 $firstErrorMessage =
"No document type declaration. ";
70 $this->_xmlDeserializer->handleErrors(
null, $firstErrorMessage,
null,
null);
72 $this->assertAttributeEquals(
75 $this->_xmlDeserializer,
76 'Error message was not set to xml deserializer.' 79 $secondErrorMessage =
"Strings should be wrapped in double quotes.";
80 $expectedMessages = $firstErrorMessage . $secondErrorMessage;
81 $this->_xmlDeserializer->handleErrors(
null, $secondErrorMessage,
null,
null);
83 $this->assertAttributeEquals(
86 $this->_xmlDeserializer,
87 'Error messages were not set to xml deserializer.'
◆ $_appStateMock
◆ $_xmlDeserializer
◆ $_xmlParserMock
The documentation for this class was generated from the following file:
- vendor/magento/framework/Webapi/Test/Unit/Rest/Request/Deserializer/XmlTest.php