From a7775b1aa95aa49dedc250ba141a18ca4a0513bd Mon Sep 17 00:00:00 2001 From: Furkan Yilmaz Date: Fri, 29 Jul 2016 17:09:15 +0100 Subject: [PATCH] added test --- src/Test/API/ClientTest.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Test/API/ClientTest.php b/src/Test/API/ClientTest.php index 3451538..2bb7904 100644 --- a/src/Test/API/ClientTest.php +++ b/src/Test/API/ClientTest.php @@ -80,4 +80,37 @@ public function testResponseOkReturnsTrueForValidResponse() $this->assertTrue($this->mockClientAPI->responseOk($v4APIResponse)); } + + public function testGetErrorMessageSuccess() + { + $errorMessage = 'I am an error message'; + + $error = $this->getMockBuilder('GuzzleHttp\Exception\RequestException') + ->disableOriginalConstructor() + ->setMethods(array('getResponse', 'getBody', 'getMessage')) + ->getMock(); + + $errorJSON = json_encode( + array( + 'success' => false, + 'errors' => array( + array( + 'message' => $errorMessage, + ), + ), + ) + ); + + $error->expects($this->any()) + ->method('getMessage') + ->will($this->returnValue('Not this message')); + $error->expects($this->any()) + ->method('getResponse') + ->will($this->returnSelf()); + $error->expects($this->any()) + ->method('getBody') + ->will($this->returnValue($errorJSON)); + + $this->assertEquals($errorMessage, $this->mockClientAPI->getErrorMessage($error)); + } }