Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ResponseTest.php
Go to the documentation of this file.
1 <?php
9 
10 class ResponseTest extends \PHPUnit\Framework\TestCase
11 {
17  protected $_response;
18 
19  protected function setUp()
20  {
22  $this->_response = new \Magento\Framework\Webapi\Response();
23  parent::setUp();
24  }
25 
26  protected function tearDown()
27  {
28  unset($this->_response);
29  parent::tearDown();
30  }
31 
35  public function testMessagesCrud()
36  {
38  $this->assertFalse($this->_response->hasMessages(), 'New object contains messages.');
39 
41  $this->_response->addMessage(
42  'Message text',
43  \Magento\Framework\Webapi\Response::HTTP_OK,
44  ['key' => 'value'],
45  \Magento\Framework\Webapi\Response::MESSAGE_TYPE_SUCCESS
46  );
47  $this->assertTrue($this->_response->hasMessages(), 'New message is not added correctly.');
48 
50  $expectedMessage = [
52  [
53  'key' => 'value',
54  'message' => 'Message text',
56  ],
57  ],
58  ];
59  $this->assertEquals($expectedMessage, $this->_response->getMessages(), 'Message is got incorrectly.');
60 
62  $this->_response->clearMessages();
63  $this->assertFalse($this->_response->hasMessages(), 'Message is not cleared.');
64  }
65 }