From e6aea87d1ee9800af2aca2f28f50633b5bf5c05f Mon Sep 17 00:00:00 2001 From: Alexey Chelnakov Date: Fri, 22 Jun 2018 09:21:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap.php | 13 ++++++++ phpunit.xml.dist | 2 +- src/AtolOnlineClient/AtolOnline.php | 12 +++++++ .../Response/OperationResponse.php | 3 +- .../AtolOnlineClient/Tests/AtolOnlineTest.php | 31 ++++++++++++++++++- .../Tests/data/sell_error_response_v3.json | 11 +++++++ .../Tests/data/sell_error_response_v4.json | 10 ++++++ 7 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 bootstrap.php create mode 100644 tests/AtolOnlineClient/Tests/data/sell_error_response_v3.json create mode 100644 tests/AtolOnlineClient/Tests/data/sell_error_response_v4.json diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000..8c24c52 --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,13 @@ + + bootstrap = "bootstrap.php" > diff --git a/src/AtolOnlineClient/AtolOnline.php b/src/AtolOnlineClient/AtolOnline.php index 852b7b4..cc2d642 100644 --- a/src/AtolOnlineClient/AtolOnline.php +++ b/src/AtolOnlineClient/AtolOnline.php @@ -27,6 +27,10 @@ class AtolOnline return new Configuration(); } + /** + * @param $response + * @return OperationResponse + */ public function deserializeOperationResponse($response) { return $this->serializer->deserialize( @@ -37,6 +41,10 @@ class AtolOnline ); } + /** + * @param $response + * @return OperationResponse + */ public function deserializeCheckStatusResponse($response) { return $this->serializer->deserialize( @@ -47,6 +55,10 @@ class AtolOnline ); } + /** + * @param $request + * @return mixed|string + */ public function serializeOperationRequest($request) { return $this->serializer->serialize( diff --git a/src/AtolOnlineClient/Response/OperationResponse.php b/src/AtolOnlineClient/Response/OperationResponse.php index 0383623..300ebd4 100644 --- a/src/AtolOnlineClient/Response/OperationResponse.php +++ b/src/AtolOnlineClient/Response/OperationResponse.php @@ -8,6 +8,7 @@ class OperationResponse { /** + * Поле отсутсвует в ответе а операцию sell с ошибкой начиная с 4й версии * @var string * * @Serializer\Groups({"post", "get"}) @@ -91,8 +92,6 @@ class OperationResponse */ private $callbackUrl; - - /** * @return string */ diff --git a/tests/AtolOnlineClient/Tests/AtolOnlineTest.php b/tests/AtolOnlineClient/Tests/AtolOnlineTest.php index 96edf72..ad5249d 100644 --- a/tests/AtolOnlineClient/Tests/AtolOnlineTest.php +++ b/tests/AtolOnlineClient/Tests/AtolOnlineTest.php @@ -4,6 +4,7 @@ namespace AtolOnlineClient\Tests; use AtolOnlineClient\AtolOnline; use AtolOnlineClient\Configuration; +use AtolOnlineClient\Response\OperationResponse; use PHPUnit\Framework\TestCase; class AtolOnlineTest extends TestCase @@ -14,4 +15,32 @@ class AtolOnlineTest extends TestCase $atol = new AtolOnline(); $this->assertInstanceOf(Configuration::class, $atol->createConfiguration()); } -} \ No newline at end of file + + + /** + * @dataProvider dataSellErrorResponse + */ + public function testDeserializeOperationResponse($file) + { + $response = file_get_contents(__DIR__ . '/data/'. $file); + $atol = new AtolOnline(); + $operationResponse = $atol->deserializeOperationResponse($response); + $this->assertInstanceOf(OperationResponse::class, $operationResponse); + $this->assertEquals('12.04.2017 06:15:06', $operationResponse->getTimestamp()); + $this->assertEquals('fail', $operationResponse->getStatus()); + $this->assertEquals(30, $operationResponse->getError()->getCode()); + $this->assertEquals('system', $operationResponse->getError()->getType()); + $this->assertEquals( + ' Передан некорректный UUID : "{0}". Необходимо повторить запрос с корректными данными ', + $operationResponse->getError()->getText() + ); + } + + public function dataSellErrorResponse() + { + return [ + ['sell_error_response_v3.json'], + ['sell_error_response_v3.json'] + ]; + } +} diff --git a/tests/AtolOnlineClient/Tests/data/sell_error_response_v3.json b/tests/AtolOnlineClient/Tests/data/sell_error_response_v3.json new file mode 100644 index 0000000..cf0148b --- /dev/null +++ b/tests/AtolOnlineClient/Tests/data/sell_error_response_v3.json @@ -0,0 +1,11 @@ +{ + "uuid": "4355", + "timestamp": "12.04.2017 06:15:06", + "status": "fail", + "error": { + "error_id": "475d6d8d-844d-4d05-aa8b-e3dbdf4defd6", + "code": 30, + "text": " Передан некорректный UUID : \"{0}\". Необходимо повторить запрос с корректными данными ", + "type": "system" + } +} \ No newline at end of file diff --git a/tests/AtolOnlineClient/Tests/data/sell_error_response_v4.json b/tests/AtolOnlineClient/Tests/data/sell_error_response_v4.json new file mode 100644 index 0000000..3a8e123 --- /dev/null +++ b/tests/AtolOnlineClient/Tests/data/sell_error_response_v4.json @@ -0,0 +1,10 @@ +{ + "timestamp": "12.04.2017 06:15:06", + "status": "fail", + "error": { + "error_id": "475d6d8d-844d-4d05-aa8b-e3dbdf4defd6", + "code": 30, + "text": " Передан некорректный UUID : \"{0}\". Необходимо повторить запрос с корректными данными ", + "type": "system" + } +} \ No newline at end of file