2021-11-17 16:01:53 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
2021-11-18 11:07:32 +00:00
|
|
|
|
namespace AtolOnlineTests;
|
2021-11-17 16:01:53 +00:00
|
|
|
|
|
2021-11-18 11:07:32 +00:00
|
|
|
|
use AtolOnline\Api\AtolClient;
|
|
|
|
|
use AtolOnline\Api\KktMonitor;
|
2021-11-19 05:42:51 +00:00
|
|
|
|
use AtolOnline\Api\KktResponse;
|
|
|
|
|
use AtolOnline\Exceptions\AuthFailedException;
|
2021-11-18 11:07:32 +00:00
|
|
|
|
use AtolOnline\Exceptions\EmptyLoginException;
|
|
|
|
|
use AtolOnline\Exceptions\EmptyPasswordException;
|
|
|
|
|
use AtolOnline\Exceptions\TooLongLoginException;
|
|
|
|
|
use AtolOnline\Exceptions\TooLongPasswordException;
|
|
|
|
|
use AtolOnline\Helpers;
|
2021-11-19 05:42:51 +00:00
|
|
|
|
use AtolOnline\TestEnvParams;
|
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
2021-11-17 16:01:53 +00:00
|
|
|
|
|
2021-11-18 11:07:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Набор тестов для проверки работы API-клиента на примере монитора ККТ
|
|
|
|
|
*/
|
|
|
|
|
class KktMonitorTest extends BasicTestCase
|
2021-11-17 16:01:53 +00:00
|
|
|
|
{
|
2021-11-18 11:07:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует успешное создание объекта монитора без аргументов конструктора
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithoutArgs()
|
|
|
|
|
{
|
|
|
|
|
$client = new KktMonitor();
|
|
|
|
|
$this->assertIsObject($client);
|
|
|
|
|
$this->assertIsSameClass(KktMonitor::class, $client);
|
|
|
|
|
$this->assertExtendsClasses([AtolClient::class], $client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует успешное создание объекта монитора с аргументами конструктора
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setLogin
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::getLogin
|
2021-11-19 05:42:51 +00:00
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
2021-11-18 11:07:32 +00:00
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::getPassword
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithArgs()
|
|
|
|
|
{
|
|
|
|
|
$client = new KktMonitor(false, 'login', 'password', []);
|
|
|
|
|
$this->assertIsObject($client);
|
|
|
|
|
$this->assertIsSameClass(KktMonitor::class, $client);
|
|
|
|
|
$this->assertExtendsClasses([AtolClient::class], $client);
|
2021-11-19 05:42:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку и возврат логина
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::getLogin
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setLogin
|
|
|
|
|
*/
|
|
|
|
|
public function testLogin()
|
|
|
|
|
{
|
|
|
|
|
$client = new KktMonitor(login: 'login');
|
|
|
|
|
$this->assertEquals('login', $client->getLogin());
|
|
|
|
|
|
|
|
|
|
$client = new KktMonitor();
|
|
|
|
|
$this->assertNull($client->getLogin());
|
|
|
|
|
|
|
|
|
|
$client->setLogin('login');
|
|
|
|
|
$this->assertEquals('login', $client->getLogin());
|
2021-11-18 11:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при попытке передать пустой логин в конструктор
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setLogin
|
2021-11-19 05:42:51 +00:00
|
|
|
|
* @covers \AtolOnline\Exceptions\EmptyLoginException
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
2021-11-19 05:42:51 +00:00
|
|
|
|
public function testEmptyLoginException()
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
|
|
|
|
$this->expectException(EmptyLoginException::class);
|
|
|
|
|
new KktMonitor(login: '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при попытке передать слишком длинный логин в конструктор
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setLogin
|
2021-11-19 05:42:51 +00:00
|
|
|
|
* @covers \AtolOnline\Exceptions\TooLongLoginException
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
2021-11-19 05:42:51 +00:00
|
|
|
|
public function testTooLongLoginException()
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooLongLoginException::class);
|
|
|
|
|
new KktMonitor(login: Helpers::randomStr(101));
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 05:42:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку и возврат пароля
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::getPassword
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
|
|
|
|
*/
|
|
|
|
|
public function testPassword()
|
|
|
|
|
{
|
|
|
|
|
$client = new KktMonitor(password: 'password');
|
|
|
|
|
$this->assertEquals('password', $client->getPassword());
|
|
|
|
|
|
|
|
|
|
$client = new KktMonitor();
|
|
|
|
|
$this->assertNull($client->getPassword());
|
|
|
|
|
|
|
|
|
|
$client->setPassword('password');
|
|
|
|
|
$this->assertEquals('password', $client->getPassword());
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 11:07:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при попытке передать пустой пароль в конструктор
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
2021-11-19 05:42:51 +00:00
|
|
|
|
* @covers \AtolOnline\Exceptions\EmptyPasswordException
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
2021-11-19 05:42:51 +00:00
|
|
|
|
public function testEmptyPasswordException()
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
|
|
|
|
$this->expectException(EmptyPasswordException::class);
|
|
|
|
|
new KktMonitor(password: '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при попытке передать слишком длинный пароль в конструктор
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setPassword
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithLongPassword()
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooLongPasswordException::class);
|
|
|
|
|
new KktMonitor(password: Helpers::randomStr(101));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку тестового режима
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::__construct
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::isTestMode
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setTestMode
|
|
|
|
|
*/
|
|
|
|
|
public function testTestMode()
|
|
|
|
|
{
|
|
|
|
|
$client = new KktMonitor();
|
|
|
|
|
$this->assertTrue($client->isTestMode());
|
|
|
|
|
|
|
|
|
|
$client = new KktMonitor(true);
|
|
|
|
|
$this->assertTrue($client->isTestMode());
|
|
|
|
|
|
|
|
|
|
$client = new KktMonitor(false);
|
|
|
|
|
$this->assertFalse($client->isTestMode());
|
|
|
|
|
|
|
|
|
|
$client = (new KktMonitor())->setTestMode();
|
|
|
|
|
$this->assertTrue($client->isTestMode());
|
|
|
|
|
|
|
|
|
|
$client = (new KktMonitor())->setTestMode(true);
|
|
|
|
|
$this->assertTrue($client->isTestMode());
|
|
|
|
|
|
|
|
|
|
$client = (new KktMonitor())->setTestMode(false);
|
|
|
|
|
$this->assertFalse($client->isTestMode());
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 05:42:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает объект клиента для тестирования с тестовым API АТОЛ
|
|
|
|
|
*
|
|
|
|
|
* @return AtolClient
|
|
|
|
|
* @throws EmptyLoginException
|
|
|
|
|
* @throws EmptyPasswordException
|
|
|
|
|
* @throws TooLongLoginException
|
|
|
|
|
* @throws TooLongPasswordException
|
|
|
|
|
*/
|
|
|
|
|
private function newTestClient(): AtolClient
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
2021-11-19 05:42:51 +00:00
|
|
|
|
$credentials = TestEnvParams::FFD105();
|
|
|
|
|
return (new KktMonitor(true))
|
|
|
|
|
->setLogin($credentials['login'])
|
|
|
|
|
->setPassword($credentials['password']);
|
2021-11-18 11:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 05:42:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует авторизацию
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\AtolClient::getHeaders
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::sendRequest
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::getAuthEndpoint
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::doAuth
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::auth
|
|
|
|
|
* @throws EmptyLoginException
|
|
|
|
|
* @throws EmptyPasswordException
|
|
|
|
|
* @throws TooLongLoginException
|
|
|
|
|
* @throws TooLongPasswordException
|
|
|
|
|
* @throws AuthFailedException
|
|
|
|
|
* @throws GuzzleException
|
|
|
|
|
*/
|
|
|
|
|
public function testAuth()
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
2021-11-19 05:42:51 +00:00
|
|
|
|
$this->skipIfMonitoringIsOffline();
|
|
|
|
|
$result = $this->newTestClient()->auth();
|
|
|
|
|
$this->assertTrue($result);
|
2021-11-18 11:07:32 +00:00
|
|
|
|
}
|
2021-11-17 16:01:53 +00:00
|
|
|
|
|
2021-11-19 05:42:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует возврат токена после авторизации
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::setToken
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::getToken
|
|
|
|
|
* @throws AuthFailedException
|
|
|
|
|
* @throws EmptyLoginException
|
|
|
|
|
* @throws EmptyPasswordException
|
|
|
|
|
* @throws GuzzleException
|
|
|
|
|
* @throws TooLongLoginException
|
|
|
|
|
* @throws TooLongPasswordException
|
|
|
|
|
*/
|
|
|
|
|
public function testGetToken()
|
2021-11-17 16:01:53 +00:00
|
|
|
|
{
|
2021-11-19 05:42:51 +00:00
|
|
|
|
$client = new KktMonitor();
|
|
|
|
|
$this->assertNull($client->getToken());
|
2021-11-17 16:01:53 +00:00
|
|
|
|
|
2021-11-19 05:42:51 +00:00
|
|
|
|
$this->skipIfMonitoringIsOffline();
|
|
|
|
|
$client = $this->newTestClient();
|
|
|
|
|
$client->auth();
|
|
|
|
|
$this->assertIsString($client->getToken());
|
2021-11-17 16:01:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 05:42:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует возврат объекта последнего ответа от API
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Api\KktMonitor::getResponse
|
|
|
|
|
* @throws AuthFailedException
|
|
|
|
|
* @throws EmptyLoginException
|
|
|
|
|
* @throws EmptyPasswordException
|
|
|
|
|
* @throws GuzzleException
|
|
|
|
|
* @throws TooLongLoginException
|
|
|
|
|
* @throws TooLongPasswordException
|
|
|
|
|
*/
|
|
|
|
|
public function testGetResponse()
|
2021-11-17 16:01:53 +00:00
|
|
|
|
{
|
2021-11-19 05:42:51 +00:00
|
|
|
|
$this->skipIfMonitoringIsOffline();
|
|
|
|
|
$client = $this->newTestClient();
|
|
|
|
|
$client->auth();
|
|
|
|
|
$this->assertIsSameClass(KktResponse::class, $client->getResponse());
|
2021-11-17 16:01:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 05:42:51 +00:00
|
|
|
|
|
|
|
|
|
public function todo_testGetAll()
|
2021-11-17 16:01:53 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 11:07:32 +00:00
|
|
|
|
public function todo_testGetOne()
|
2021-11-17 16:01:53 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|