mirror of
https://github.com/anthonyaxenov/atol-online.git
synced 2024-11-22 16:14:34 +00:00
Compare commits
2 Commits
92a2c6cc48
...
6551366d84
Author | SHA1 | Date | |
---|---|---|---|
6551366d84 | |||
2c5144caac |
@ -12,6 +12,7 @@ declare(strict_types = 1);
|
|||||||
namespace AtolOnline\Api;
|
namespace AtolOnline\Api;
|
||||||
|
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,13 +79,13 @@ class KktMonitor extends AtolClient
|
|||||||
*
|
*
|
||||||
* @param int|null $limit
|
* @param int|null $limit
|
||||||
* @param int|null $offset
|
* @param int|null $offset
|
||||||
* @return KktResponse
|
* @return Collection
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
* @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 9
|
* @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 9
|
||||||
*/
|
*/
|
||||||
public function getAll(?int $limit = null, ?int $offset = null): KktResponse
|
public function getAll(?int $limit = null, ?int $offset = null): Collection
|
||||||
{
|
{
|
||||||
return $this->fetchAll($limit, $offset);
|
return collect($this->fetchAll($limit, $offset)->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,12 +28,17 @@ class BasicTestCase extends TestCase
|
|||||||
* @param string $url
|
* @param string $url
|
||||||
* @param int $code
|
* @param int $code
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
*/
|
||||||
protected function ping(string $url, int $code): bool
|
protected function ping(string $url, int $code): bool
|
||||||
{
|
{
|
||||||
$result = (new Client(['http_errors' => false]))->request('GET', $url);
|
try {
|
||||||
//$this->assertEquals(200, $result->getStatusCode());
|
$result = (new Client([
|
||||||
|
'http_errors' => false,
|
||||||
|
'timeout' => 3,
|
||||||
|
]))->request('GET', $url);
|
||||||
|
} catch (GuzzleException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return $result->getStatusCode() === $code;
|
return $result->getStatusCode() === $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,10 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
* @covers \AtolOnline\Api\KktMonitor::getLogin
|
* @covers \AtolOnline\Api\KktMonitor::getLogin
|
||||||
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
||||||
* @covers \AtolOnline\Api\KktMonitor::getPassword
|
* @covers \AtolOnline\Api\KktMonitor::getPassword
|
||||||
|
* @throws EmptyLoginException
|
||||||
|
* @throws EmptyPasswordException
|
||||||
|
* @throws TooLongLoginException
|
||||||
|
* @throws TooLongPasswordException
|
||||||
*/
|
*/
|
||||||
public function testConstructorWithArgs()
|
public function testConstructorWithArgs()
|
||||||
{
|
{
|
||||||
@ -55,6 +59,8 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
* @covers \AtolOnline\Api\KktMonitor::__construct
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
||||||
* @covers \AtolOnline\Api\KktMonitor::getLogin
|
* @covers \AtolOnline\Api\KktMonitor::getLogin
|
||||||
* @covers \AtolOnline\Api\KktMonitor::setLogin
|
* @covers \AtolOnline\Api\KktMonitor::setLogin
|
||||||
|
* @throws EmptyLoginException
|
||||||
|
* @throws TooLongLoginException
|
||||||
*/
|
*/
|
||||||
public function testLogin()
|
public function testLogin()
|
||||||
{
|
{
|
||||||
@ -87,6 +93,10 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
* @covers \AtolOnline\Api\KktMonitor::__construct
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
||||||
* @covers \AtolOnline\Api\KktMonitor::setLogin
|
* @covers \AtolOnline\Api\KktMonitor::setLogin
|
||||||
* @covers \AtolOnline\Exceptions\TooLongLoginException
|
* @covers \AtolOnline\Exceptions\TooLongLoginException
|
||||||
|
* @throws EmptyLoginException
|
||||||
|
* @throws EmptyPasswordException
|
||||||
|
* @throws TooLongLoginException
|
||||||
|
* @throws TooLongPasswordException
|
||||||
*/
|
*/
|
||||||
public function testTooLongLoginException()
|
public function testTooLongLoginException()
|
||||||
{
|
{
|
||||||
@ -100,6 +110,8 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
* @covers \AtolOnline\Api\KktMonitor::__construct
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
||||||
* @covers \AtolOnline\Api\KktMonitor::getPassword
|
* @covers \AtolOnline\Api\KktMonitor::getPassword
|
||||||
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
||||||
|
* @throws EmptyPasswordException
|
||||||
|
* @throws TooLongPasswordException
|
||||||
*/
|
*/
|
||||||
public function testPassword()
|
public function testPassword()
|
||||||
{
|
{
|
||||||
@ -131,6 +143,10 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
*
|
*
|
||||||
* @covers \AtolOnline\Api\KktMonitor::__construct
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
||||||
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
||||||
|
* @throws EmptyLoginException
|
||||||
|
* @throws EmptyPasswordException
|
||||||
|
* @throws TooLongLoginException
|
||||||
|
* @throws TooLongPasswordException
|
||||||
*/
|
*/
|
||||||
public function testConstructorWithLongPassword()
|
public function testConstructorWithLongPassword()
|
||||||
{
|
{
|
||||||
@ -175,7 +191,7 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
* @throws TooLongLoginException
|
* @throws TooLongLoginException
|
||||||
* @throws TooLongPasswordException
|
* @throws TooLongPasswordException
|
||||||
*/
|
*/
|
||||||
private function newTestClient(): AtolClient
|
private function newTestClient(): KktMonitor
|
||||||
{
|
{
|
||||||
$credentials = TestEnvParams::FFD105();
|
$credentials = TestEnvParams::FFD105();
|
||||||
return (new KktMonitor(true))
|
return (new KktMonitor(true))
|
||||||
@ -208,6 +224,7 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует возврат токена после авторизации
|
* Тестирует возврат токена после авторизации
|
||||||
*
|
*
|
||||||
|
* @depends testAuth
|
||||||
* @covers \AtolOnline\Api\KktMonitor::setToken
|
* @covers \AtolOnline\Api\KktMonitor::setToken
|
||||||
* @covers \AtolOnline\Api\KktMonitor::getToken
|
* @covers \AtolOnline\Api\KktMonitor::getToken
|
||||||
* @throws AuthFailedException
|
* @throws AuthFailedException
|
||||||
@ -231,6 +248,7 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует возврат объекта последнего ответа от API
|
* Тестирует возврат объекта последнего ответа от API
|
||||||
*
|
*
|
||||||
|
* @depends testAuth
|
||||||
* @covers \AtolOnline\Api\KktMonitor::getResponse
|
* @covers \AtolOnline\Api\KktMonitor::getResponse
|
||||||
* @throws AuthFailedException
|
* @throws AuthFailedException
|
||||||
* @throws EmptyLoginException
|
* @throws EmptyLoginException
|
||||||
@ -247,13 +265,58 @@ class KktMonitorTest extends BasicTestCase
|
|||||||
$this->assertIsSameClass(KktResponse::class, $client->getResponse());
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user