From 6551366d84037784c0341d154be71abda143775a Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Fri, 19 Nov 2021 18:42:14 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D0=BE=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=D0=B8=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=20AtolClient=20+=20KktMonitor=20+=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D0=BD=D1=8B=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Часть тестов завязаны на тестовый API мониторинга Атола. Иногда он закашливается и не отвечает, возможно, там рейтлимит. Да и пофиг, моки -- злейшее зло, и мне лень их писать. --- tests/BasicTestCase.php | 11 ++++-- tests/KktMonitorTest.php | 79 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 11 deletions(-) diff --git a/tests/BasicTestCase.php b/tests/BasicTestCase.php index e25adcd..f20ff62 100644 --- a/tests/BasicTestCase.php +++ b/tests/BasicTestCase.php @@ -28,12 +28,17 @@ class BasicTestCase extends TestCase * @param string $url * @param int $code * @return bool - * @throws GuzzleException */ protected function ping(string $url, int $code): bool { - $result = (new Client(['http_errors' => false]))->request('GET', $url); - //$this->assertEquals(200, $result->getStatusCode()); + try { + $result = (new Client([ + 'http_errors' => false, + 'timeout' => 3, + ]))->request('GET', $url); + } catch (GuzzleException) { + return false; + } return $result->getStatusCode() === $code; } diff --git a/tests/KktMonitorTest.php b/tests/KktMonitorTest.php index e2e4b1c..a6ebde6 100644 --- a/tests/KktMonitorTest.php +++ b/tests/KktMonitorTest.php @@ -40,6 +40,10 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\KktMonitor::getLogin * @covers \AtolOnline\Api\KktMonitor::setPassword * @covers \AtolOnline\Api\KktMonitor::getPassword + * @throws EmptyLoginException + * @throws EmptyPasswordException + * @throws TooLongLoginException + * @throws TooLongPasswordException */ public function testConstructorWithArgs() { @@ -55,6 +59,8 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\KktMonitor::getLogin * @covers \AtolOnline\Api\KktMonitor::setLogin + * @throws EmptyLoginException + * @throws TooLongLoginException */ public function testLogin() { @@ -87,6 +93,10 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\KktMonitor::setLogin * @covers \AtolOnline\Exceptions\TooLongLoginException + * @throws EmptyLoginException + * @throws EmptyPasswordException + * @throws TooLongLoginException + * @throws TooLongPasswordException */ public function testTooLongLoginException() { @@ -100,6 +110,8 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\KktMonitor::getPassword * @covers \AtolOnline\Api\KktMonitor::setPassword + * @throws EmptyPasswordException + * @throws TooLongPasswordException */ public function testPassword() { @@ -131,6 +143,10 @@ class KktMonitorTest extends BasicTestCase * * @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\KktMonitor::setPassword + * @throws EmptyLoginException + * @throws EmptyPasswordException + * @throws TooLongLoginException + * @throws TooLongPasswordException */ public function testConstructorWithLongPassword() { @@ -175,7 +191,7 @@ class KktMonitorTest extends BasicTestCase * @throws TooLongLoginException * @throws TooLongPasswordException */ - private function newTestClient(): AtolClient + private function newTestClient(): KktMonitor { $credentials = TestEnvParams::FFD105(); return (new KktMonitor(true)) @@ -208,8 +224,9 @@ class KktMonitorTest extends BasicTestCase /** * Тестирует возврат токена после авторизации * - * @covers \AtolOnline\Api\KktMonitor::setToken - * @covers \AtolOnline\Api\KktMonitor::getToken + * @depends testAuth + * @covers \AtolOnline\Api\KktMonitor::setToken + * @covers \AtolOnline\Api\KktMonitor::getToken * @throws AuthFailedException * @throws EmptyLoginException * @throws EmptyPasswordException @@ -231,7 +248,8 @@ class KktMonitorTest extends BasicTestCase /** * Тестирует возврат объекта последнего ответа от API * - * @covers \AtolOnline\Api\KktMonitor::getResponse + * @depends testAuth + * @covers \AtolOnline\Api\KktMonitor::getResponse * @throws AuthFailedException * @throws EmptyLoginException * @throws EmptyPasswordException @@ -247,13 +265,58 @@ class KktMonitorTest extends BasicTestCase $this->assertIsSameClass(KktResponse::class, $client->getResponse()); } - - public function todo_testGetAll() + /** + * [Мониторинг] Тестирует получение данных о всех ККТ + * + * @depends testAuth + * @covers \AtolOnline\Api\KktMonitor::getMainEndpoint + * @covers \AtolOnline\Api\AtolClient::getUrlToMethod + * @covers \AtolOnline\Api\KktMonitor::fetchAll + * @covers \AtolOnline\Api\KktMonitor::getAll + * @throws AuthFailedException + * @throws EmptyLoginException + * @throws EmptyPasswordException + * @throws GuzzleException + * @throws TooLongLoginException + * @throws TooLongPasswordException + */ + public function testMonitorGetAll() { + $this->skipIfMonitoringIsOffline(); + $client = $this->newTestClient(); + $client->auth(); + $kkts = $client->getAll(); + $this->assertNotEmpty($client->getResponse()->getContent()); + $this->assertIsCollection($kkts); + $this->assertTrue($kkts->count() > 0); } - public function todo_testGetOne() + /** + * [Мониторинг] Тестирует получение данных о конкретной ККТ + * + * @depends testAuth + * @covers \AtolOnline\Api\KktMonitor::getMainEndpoint + * @covers \AtolOnline\Api\AtolClient::getUrlToMethod + * @covers \AtolOnline\Api\KktMonitor::fetchOne + * @covers \AtolOnline\Api\KktMonitor::getOne + * @throws AuthFailedException + * @throws EmptyLoginException + * @throws EmptyPasswordException + * @throws GuzzleException + * @throws TooLongLoginException + * @throws TooLongPasswordException + */ + public function testGetOne() { + $this->skipIfMonitoringIsOffline(); + $client = $this->newTestClient(); + $client->auth(); + $kkts = $client->getAll(); + $serial_number = $kkts->first()->serialNumber; + $client->getOne($serial_number); + $this->assertIsSameClass(KktResponse::class, $client->getResponse()); + $this->assertNotEmpty($client->getResponse()); + $this->assertNotNull($client->getResponse()->data->serialNumber); + $this->assertEquals($serial_number, $client->getResponse()->data->serialNumber); } - }