/**
  * Test execute exception
  *
  * @return void
  */
 public function testExecuteException()
 {
     $response = ['error' => true, 'message' => 'Cannot add new comment.'];
     $e = new \Exception('test');
     $this->requestMock->expects($this->once())->method('getParam')->will($this->throwException($e));
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultJsonMock));
     $this->resultJsonMock->expects($this->once())->method('setData')->with($response);
     $this->assertSame($this->resultJsonMock, $this->controller->execute());
 }
Beispiel #2
0
 public function testExecuteException()
 {
     $response = ['error' => true, 'message' => 'Cannot add new comment.'];
     $e = new \Exception('test');
     $this->requestMock->expects($this->once())->method('getParam')->will($this->throwException($e));
     $helperMock = $this->getMockBuilder('Magento\\Core\\Helper\\Data')->disableOriginalConstructor()->setMethods([])->getMock();
     $helperMock->expects($this->once())->method('jsonEncode')->with($response)->will($this->returnValue(json_encode($response)));
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Core\\Helper\\Data')->will($this->returnValue($helperMock));
     $this->responseMock->expects($this->once())->method('representJson')->with(json_encode($response));
     $this->assertNull($this->controller->execute());
 }