public function testJsonMarshalling()
 {
     $errorResponse = new ErrorResponse();
     $errorResponse->errorId = '123';
     $apiError = new APIError();
     $apiError->code = '1';
     $apiError->message = 'Test message';
     $apiError->propertyName = 'test';
     $errorResponse->errors = array($apiError);
     $jsonErrorResponse = $errorResponse->toJson();
     $this->assertEquals($jsonErrorResponse, json_encode($errorResponse));
     $actualErrorResponse = new ErrorResponse();
     $actualErrorResponse->fromJson($jsonErrorResponse);
     $this->assertEquals($errorResponse, $actualErrorResponse);
 }
    public function testExceptionStringRepresentation()
    {
        $httpStatusCode = 400;
        $errorResponseJsonString = <<<'EOD'
{
    "errorId": "8a41a5dd-7366-4026-a41b-e98c56808edd",
    "errors": [
        {
            "code": "20000000",
            "httpStatusCode": 400,
            "message": "PARAMETER_NOT_FOUND_IN_REQUEST",
            "propertyName": "bin",
            "requestId": ""
        }
    ]
}
EOD;
        $errorResponse = new ErrorResponse();
        $errorResponse->fromJson($errorResponseJsonString);
        $responseException = new ResponseException($httpStatusCode, $errorResponse);
        $expectedResponseExceptionString = sprintf("exception '%s' with message '%s'. in %s:%d\nHTTP status code: %s\nResponse:\n%s\nStack trace:\n%s", 'Ingenico\\Connect\\Sdk\\ResponseException', $responseException->getMessage(), $responseException->getFile(), $responseException->getLine(), $httpStatusCode, $errorResponseJsonString, $responseException->getTraceAsString());
        // replace Windows \r\n with Unix \n before comparing
        $this->assertEquals(str_replace("\r\n", "\n", $expectedResponseExceptionString), str_replace("\r\n", "\n", (string) $responseException));
    }