diff --git a/src/Api/KktMonitor.php b/src/Api/KktMonitor.php index d61ddbe..f1fb41e 100644 --- a/src/Api/KktMonitor.php +++ b/src/Api/KktMonitor.php @@ -11,9 +11,11 @@ declare(strict_types = 1); namespace AtolOnline\Api; +use AtolOnline\Entities\Kkt; +use AtolOnline\Exceptions\EmptyMonitorDataException; +use AtolOnline\Exceptions\NotEnoughMonitorDataException; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Support\Collection; -use stdClass; /** * Класс для мониторинга ККТ @@ -85,7 +87,8 @@ class KktMonitor extends AtolClient */ public function getAll(?int $limit = null, ?int $offset = null): Collection { - return collect($this->fetchAll($limit, $offset)->getContent()); + $collection = collect($this->fetchAll($limit, $offset)->getContent()); + return $collection->map(fn($data) => new Kkt($data)); } /** @@ -114,12 +117,14 @@ class KktMonitor extends AtolClient * * @todo кастовать к отдельному классу со своими геттерами * @param string $serial_number - * @return stdClass + * @return Kkt * @throws GuzzleException + * @throws EmptyMonitorDataException + * @throws NotEnoughMonitorDataException * @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 11 */ - public function getOne(string $serial_number): stdClass + public function getOne(string $serial_number): Kkt { - return $this->fetchOne($serial_number)->getContent()->data; + return new Kkt($this->fetchOne($serial_number)->getContent()->data); } } diff --git a/src/Entities/Company.php b/src/Entities/Company.php index f37f955..d5876d9 100644 --- a/src/Entities/Company.php +++ b/src/Entities/Company.php @@ -13,7 +13,7 @@ namespace AtolOnline\Entities; use AtolOnline\{ Constants\Constraints, - Constants\SnoTypes, + Enums\SnoTypes, Exceptions\InvalidEmailException, Exceptions\InvalidInnLengthException, Exceptions\InvalidPaymentAddressException, diff --git a/src/Entities/Entity.php b/src/Entities/Entity.php index 0b47b2d..490fdc8 100644 --- a/src/Entities/Entity.php +++ b/src/Entities/Entity.php @@ -28,4 +28,4 @@ abstract class Entity implements JsonSerializable, Stringable { return json_encode($this->jsonSerialize(), JSON_UNESCAPED_UNICODE); } -} \ No newline at end of file +} diff --git a/src/Entities/Kkt.php b/src/Entities/Kkt.php new file mode 100644 index 0000000..f379d44 --- /dev/null +++ b/src/Entities/Kkt.php @@ -0,0 +1,149 @@ + 'Нет ошибок', + 1 => 'Отсутствует физический канал связи', + 2 => 'Ошибка сетевых настроек или нет соединения с сервером ОФД', + 3 => 'Разрыв соединения при передаче документа на сервер', + 4 => 'Некорректный заголовок сессионного пакета', + 5 => 'Превышен таймаут ожидания квитанции', + 6 => 'Разрыв соединения при приеме квитанции', + 7 => 'Превышен таймаут передачи документа на сервер', + 8 => 'ОФД-процесс не иницилизирован', + ]; + + /** + * @var string[] Список обязательных атрибутов + */ + private array $properties = [ + 'serialNumber', + 'registrationNumber', + 'deviceNumber', + 'fiscalizationDate', + 'fiscalStorageExpiration', + 'signedDocuments', + 'fiscalStoragePercentageUse', + 'fiscalStorageINN', + 'fiscalStorageSerialNumber', + 'fiscalStoragePaymentAddress', + 'groupCode', + 'timestamp', + 'isShiftOpened', + 'shiftNumber', + 'shiftReceipt', + //'unsentDocs', + //'firstUnsetDocTimestamp', + 'networkErrorCode', + ]; + + /** + * @var string[] Массив атрибутов, которые кастуются к DateTime + */ + private array $timestamps = [ + 'fiscalizationDate', + 'fiscalStorageExpiration', + 'firstUnsetDocTimestamp', + 'timestamp', + ]; + + /** + * Конструктор + * + * @throws EmptyMonitorDataException + * @throws NotEnoughMonitorDataException + */ + public function __construct(protected \stdClass $data) + { + if (empty((array)$data)) { + throw new EmptyMonitorDataException(); + } + $diff = array_diff($this->properties, array_keys((array)$data)); + if (count($diff) !== 0) { + throw new NotEnoughMonitorDataException($diff); + } + } + + /** + * Эмулирует обращение к атрибутам + * + * @param string $name + * @return null + * @throws Exception + */ + public function __get(string $name) + { + if (empty($this->data?->$name)) { + return null; + } + if (in_array($name, $this->timestamps)) { + return new DateTime($this->data->$name); + } + return $this->data->$name; + } + + /** + * Возвращает объект с информацией о сетевой ошибке + * + * @return object + */ + public function getNetworkError(): object + { + return (object)[ + 'code' => $this->data->networkErrorCode, + 'text' => self::ERROR_CODES[$this->data->networkErrorCode], + ]; + } + + /** + * @inheritDoc + */ + public function jsonSerialize() + { + return $this->data; + } +} diff --git a/src/Entities/Payment.php b/src/Entities/Payment.php index 0a3d356..bc8fd99 100644 --- a/src/Entities/Payment.php +++ b/src/Entities/Payment.php @@ -11,7 +11,7 @@ declare(strict_types = 1); namespace AtolOnline\Entities; -use AtolOnline\Constants\PaymentTypes; +use AtolOnline\Enums\PaymentTypes; /** * Класс, описывающий оплату. Тег ФФД - 1031, 1081, 1215, 1216, 1217. diff --git a/src/Entities/Vat.php b/src/Entities/Vat.php index 98dd642..9e85402 100644 --- a/src/Entities/Vat.php +++ b/src/Entities/Vat.php @@ -11,7 +11,7 @@ declare(strict_types = 1); namespace AtolOnline\Entities; -use AtolOnline\Constants\VatTypes; +use AtolOnline\Enums\VatTypes; /** * Класс, описывающий ставку НДС diff --git a/src/Constants/CorrectionTypes.php b/src/Enums/CorrectionTypes.php similarity index 96% rename from src/Constants/CorrectionTypes.php rename to src/Enums/CorrectionTypes.php index e0c1c9c..7cd82d9 100644 --- a/src/Constants/CorrectionTypes.php +++ b/src/Enums/CorrectionTypes.php @@ -9,7 +9,7 @@ declare(strict_types = 1); -namespace AtolOnline\Constants; +namespace AtolOnline\Enums; use MyCLabs\Enum\Enum; diff --git a/src/Constants/DocumentTypes.php b/src/Enums/DocumentTypes.php similarity index 95% rename from src/Constants/DocumentTypes.php rename to src/Enums/DocumentTypes.php index d4573a6..2f93622 100644 --- a/src/Constants/DocumentTypes.php +++ b/src/Enums/DocumentTypes.php @@ -9,7 +9,7 @@ declare(strict_types = 1); -namespace AtolOnline\Constants; +namespace AtolOnline\Enums; use MyCLabs\Enum\Enum; diff --git a/src/Constants/PaymentMethods.php b/src/Enums/PaymentMethods.php similarity index 98% rename from src/Constants/PaymentMethods.php rename to src/Enums/PaymentMethods.php index 498131a..b82db22 100644 --- a/src/Constants/PaymentMethods.php +++ b/src/Enums/PaymentMethods.php @@ -9,7 +9,7 @@ declare(strict_types = 1); -namespace AtolOnline\Constants; +namespace AtolOnline\Enums; use MyCLabs\Enum\Enum; diff --git a/src/Constants/PaymentObjects.php b/src/Enums/PaymentObjects.php similarity index 99% rename from src/Constants/PaymentObjects.php rename to src/Enums/PaymentObjects.php index 313e552..741084d 100644 --- a/src/Constants/PaymentObjects.php +++ b/src/Enums/PaymentObjects.php @@ -9,7 +9,7 @@ declare(strict_types = 1); -namespace AtolOnline\Constants; +namespace AtolOnline\Enums; use MyCLabs\Enum\Enum; diff --git a/src/Constants/PaymentTypes.php b/src/Enums/PaymentTypes.php similarity index 98% rename from src/Constants/PaymentTypes.php rename to src/Enums/PaymentTypes.php index 54a93a2..68ad635 100644 --- a/src/Constants/PaymentTypes.php +++ b/src/Enums/PaymentTypes.php @@ -9,7 +9,7 @@ declare(strict_types = 1); -namespace AtolOnline\Constants; +namespace AtolOnline\Enums; use MyCLabs\Enum\Enum; diff --git a/src/Constants/ReceiptOperationTypes.php b/src/Enums/ReceiptOperationTypes.php similarity index 97% rename from src/Constants/ReceiptOperationTypes.php rename to src/Enums/ReceiptOperationTypes.php index 83ed9f0..2e55820 100644 --- a/src/Constants/ReceiptOperationTypes.php +++ b/src/Enums/ReceiptOperationTypes.php @@ -9,7 +9,7 @@ declare(strict_types = 1); -namespace AtolOnline\Constants; +namespace AtolOnline\Enums; use MyCLabs\Enum\Enum; diff --git a/src/Constants/SnoTypes.php b/src/Enums/SnoTypes.php similarity index 97% rename from src/Constants/SnoTypes.php rename to src/Enums/SnoTypes.php index 4aca641..0892fc6 100644 --- a/src/Constants/SnoTypes.php +++ b/src/Enums/SnoTypes.php @@ -9,7 +9,7 @@ declare(strict_types = 1); -namespace AtolOnline\Constants; +namespace AtolOnline\Enums; use MyCLabs\Enum\Enum; diff --git a/src/Constants/VatTypes.php b/src/Enums/VatTypes.php similarity index 96% rename from src/Constants/VatTypes.php rename to src/Enums/VatTypes.php index d78e0ad..f8e377e 100644 --- a/src/Constants/VatTypes.php +++ b/src/Enums/VatTypes.php @@ -9,7 +9,7 @@ declare(strict_types = 1); -namespace AtolOnline\Constants; +namespace AtolOnline\Enums; use MyCLabs\Enum\Enum; diff --git a/src/Exceptions/EmptyMonitorDataException.php b/src/Exceptions/EmptyMonitorDataException.php new file mode 100644 index 0000000..7aad529 --- /dev/null +++ b/src/Exceptions/EmptyMonitorDataException.php @@ -0,0 +1,23 @@ +message . implode(', ', $props_diff), $code, $previous); + } +} \ No newline at end of file diff --git a/tests/BasicTestCase.php b/tests/BasicTestCase.php index f20ff62..4bd5c23 100644 --- a/tests/BasicTestCase.php +++ b/tests/BasicTestCase.php @@ -46,7 +46,6 @@ class BasicTestCase extends TestCase * Проверяет доступность API мониторинга * * @return bool - * @throws GuzzleException */ protected function isMonitoringOnline(): bool { @@ -54,9 +53,7 @@ class BasicTestCase extends TestCase } /** - * Пропускает текущий тест если API мониторинга недоступно - * - * @throws GuzzleException + * Пропускает текущий тест если API мониторинга недоступен */ protected function skipIfMonitoringIsOffline(): void { @@ -90,7 +87,7 @@ class BasicTestCase extends TestCase * @param object|string $expected * @param object|string $actual */ - public function assertIsSameClass(object|string $expected, object|string $actual) + public function assertIsSameClass(object|string $expected, object|string $actual): void { $this->assertEquals( is_object($expected) ? $expected::class : $expected, @@ -104,7 +101,7 @@ class BasicTestCase extends TestCase * @param string[] $parents * @param object|string $actual */ - public function assertExtendsClasses(array $parents, object|string $actual) + public function assertExtendsClasses(array $parents, object|string $actual): void { $this->checkClassesIntersection($parents, $actual, 'class_parents'); } @@ -115,7 +112,7 @@ class BasicTestCase extends TestCase * @param string[] $parents * @param object|string $actual */ - public function assertImplementsInterfaces(array $parents, object|string $actual) + public function assertImplementsInterfaces(array $parents, object|string $actual): void { $this->checkClassesIntersection($parents, $actual, 'class_implements'); } @@ -126,7 +123,7 @@ class BasicTestCase extends TestCase * @param string[] $parents * @param object|string $actual */ - public function assertUsesTraits(array $parents, object|string $actual) + public function assertUsesTraits(array $parents, object|string $actual): void { $this->checkClassesIntersection($parents, $actual, 'class_uses'); } diff --git a/tests/CompanyTest.php b/tests/CompanyTest.php index 7b8e20c..82961af 100644 --- a/tests/CompanyTest.php +++ b/tests/CompanyTest.php @@ -10,8 +10,8 @@ namespace AtolOnlineTests; use AtolOnline\{ - Constants\SnoTypes, Entities\Company, + Enums\SnoTypes, Exceptions\InvalidEmailException, Exceptions\InvalidInnLengthException, Exceptions\InvalidPaymentAddressException, diff --git a/tests/ItemTest_todo.php b/tests/ItemTest_todo.php index 88a4088..2e3b492 100644 --- a/tests/ItemTest_todo.php +++ b/tests/ItemTest_todo.php @@ -10,10 +10,10 @@ namespace AtolOnlineTests; use AtolOnline\{ - Constants\PaymentMethods, - Constants\PaymentObjects, - Constants\VatTypes, Entities\Item, + Enums\PaymentMethods, + Enums\PaymentObjects, + Enums\VatTypes, Exceptions\BasicTooManyException, Exceptions\TooHighPriceException, Exceptions\TooLongNameException, diff --git a/tests/KktEntityTest.php b/tests/KktEntityTest.php new file mode 100644 index 0000000..b1a2a9c --- /dev/null +++ b/tests/KktEntityTest.php @@ -0,0 +1,153 @@ + '00107703864827', + 'registrationNumber' => '0000000003027865', + 'deviceNumber' => 'KKT024219', + 'fiscalizationDate' => '2019-07-22T14:03:00+00:00', + 'fiscalStorageExpiration' => '2020-11-02T21:00:00+00:00', + 'signedDocuments' => 213350, + 'fiscalStoragePercentageUse' => 85.34, + 'fiscalStorageINN' => '3026455760', + 'fiscalStorageSerialNumber' => '9999078902004339', + 'fiscalStoragePaymentAddress' => 'test.qa.ru', + 'groupCode' => 'test-qa-ru_14605', + 'timestamp' => '2019-12-05T10:45:30+00:00', + 'isShiftOpened' => true, + 'shiftNumber' => 126, + 'shiftReceipt' => 2278, + //'unsentDocs' => 123, + 'firstUnsetDocTimestamp' => 'there must be timestamp, but we want to get exception here to get string', + 'networkErrorCode' => 2, + ]; + + /** + * Тестирует создание объекта ККТ с валидными данными + * + * @covers \AtolOnline\Entities\Kkt::__construct + * @covers \AtolOnline\Entities\Kkt::__get + * @covers \AtolOnline\Entities\Kkt::jsonSerialize + * @covers \AtolOnline\Entities\Kkt::__toString + * @throws Exception + */ + public function testConstructor(): void + { + $kkt = new Kkt((object)$this->sample_data); + $this->assertIsSameClass(Kkt::class, $kkt); + $this->assertAtolable($kkt); + } + + /** + * Тестирует исключение при попытке создать объект ККТ без данных от монитора + * + * @covers \AtolOnline\Entities\Kkt::__construct + * @covers \AtolOnline\Exceptions\EmptyMonitorDataException + * @throws EmptyMonitorDataException + * @throws NotEnoughMonitorDataException + */ + public function testEmptyMonitorDataException(): void + { + $this->expectException(EmptyMonitorDataException::class); + new Kkt((object)[]); + } + + /** + * Тестирует исключение при попытке создать объект ККТ без данных от монитора + * + * @covers \AtolOnline\Entities\Kkt::__construct + * @covers \AtolOnline\Exceptions\NotEnoughMonitorDataException + * @throws EmptyMonitorDataException + * @throws NotEnoughMonitorDataException + */ + public function testNotEnoughMonitorDataException(): void + { + $this->expectException(NotEnoughMonitorDataException::class); + new Kkt((object)[ + 'fiscalizationDate' => '2021-11-20T10:21:00+00:00', + ]); + } + + /** + * Тестирует получение атрибутов через магический геттер + * + * @covers \AtolOnline\Entities\Kkt::__get + * @throws EmptyMonitorDataException + * @throws NotEnoughMonitorDataException + */ + public function testMagicGetter(): void + { + $kkt = new Kkt((object)$this->sample_data); + + // string + $this->assertNotNull($kkt->serialNumber); + $this->assertIsString($kkt->serialNumber); + $this->assertEquals($this->sample_data['serialNumber'], $kkt->serialNumber); + + // int + $this->assertNotNull($kkt->signedDocuments); + $this->assertIsInt($kkt->signedDocuments); + + // float + $this->assertNotNull($kkt->signedDocuments); + $this->assertIsFloat($kkt->fiscalStoragePercentageUse); + + // null + $this->assertNull($kkt->unsentDocs); + + // DateTime + $this->assertNotNull($kkt->fiscalizationDate); + $this->assertIsSameClass(DateTime::class, $kkt->fiscalizationDate); + } + + /** + * Тестирует исключение при попытке получить некорректный DateTime через магический геттер + * + * @covers \AtolOnline\Entities\Kkt::__get + * @throws EmptyMonitorDataException + * @throws NotEnoughMonitorDataException + */ + public function testDateTimeException(): void + { + $this->expectException(Exception::class); + (new Kkt((object)$this->sample_data))->firstUnsetDocTimestamp; + } + + /** + * Тестирует получение данных о сетевой ошибке + * + * @covers \AtolOnline\Entities\Kkt::getNetworkError + * @throws EmptyMonitorDataException + * @throws NotEnoughMonitorDataException + */ + public function testGetNetworkError(): void + { + $kkt = new Kkt((object)$this->sample_data); + $this->assertIsObject($kkt->getNetworkError()); + $this->assertEquals((object)[ + 'code' => $kkt->networkErrorCode, + 'text' => $kkt::ERROR_CODES[$kkt->networkErrorCode], + ], $kkt->getNetworkError()); + } +} diff --git a/tests/KktMonitorTest.php b/tests/KktMonitorTest.php index a6ebde6..b1ca4d6 100644 --- a/tests/KktMonitorTest.php +++ b/tests/KktMonitorTest.php @@ -5,9 +5,12 @@ namespace AtolOnlineTests; use AtolOnline\Api\AtolClient; use AtolOnline\Api\KktMonitor; use AtolOnline\Api\KktResponse; +use AtolOnline\Entities\Kkt; use AtolOnline\Exceptions\AuthFailedException; use AtolOnline\Exceptions\EmptyLoginException; +use AtolOnline\Exceptions\EmptyMonitorDataException; use AtolOnline\Exceptions\EmptyPasswordException; +use AtolOnline\Exceptions\NotEnoughMonitorDataException; use AtolOnline\Exceptions\TooLongLoginException; use AtolOnline\Exceptions\TooLongPasswordException; use AtolOnline\Helpers; @@ -19,12 +22,29 @@ use GuzzleHttp\Exception\GuzzleException; */ class KktMonitorTest extends BasicTestCase { + /** + * Возвращает объект клиента для тестирования с тестовым API АТОЛ + * + * @return AtolClient + * @throws EmptyLoginException + * @throws EmptyPasswordException + * @throws TooLongLoginException + * @throws TooLongPasswordException + */ + private function newTestClient(): KktMonitor + { + $credentials = TestEnvParams::FFD105(); + return (new KktMonitor(true)) + ->setLogin($credentials['login']) + ->setPassword($credentials['password']); + } + /** * Тестирует успешное создание объекта монитора без аргументов конструктора * * @covers \AtolOnline\Api\KktMonitor::__construct */ - public function testConstructorWithoutArgs() + public function testConstructorWithoutArgs(): void { $client = new KktMonitor(); $this->assertIsObject($client); @@ -45,7 +65,7 @@ class KktMonitorTest extends BasicTestCase * @throws TooLongLoginException * @throws TooLongPasswordException */ - public function testConstructorWithArgs() + public function testConstructorWithArgs(): void { $client = new KktMonitor(false, 'login', 'password', []); $this->assertIsObject($client); @@ -62,7 +82,7 @@ class KktMonitorTest extends BasicTestCase * @throws EmptyLoginException * @throws TooLongLoginException */ - public function testLogin() + public function testLogin(): void { $client = new KktMonitor(login: 'login'); $this->assertEquals('login', $client->getLogin()); @@ -81,7 +101,7 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\KktMonitor::setLogin * @covers \AtolOnline\Exceptions\EmptyLoginException */ - public function testEmptyLoginException() + public function testEmptyLoginException(): void { $this->expectException(EmptyLoginException::class); new KktMonitor(login: ''); @@ -98,7 +118,7 @@ class KktMonitorTest extends BasicTestCase * @throws TooLongLoginException * @throws TooLongPasswordException */ - public function testTooLongLoginException() + public function testTooLongLoginException(): void { $this->expectException(TooLongLoginException::class); new KktMonitor(login: Helpers::randomStr(101)); @@ -113,7 +133,7 @@ class KktMonitorTest extends BasicTestCase * @throws EmptyPasswordException * @throws TooLongPasswordException */ - public function testPassword() + public function testPassword(): void { $client = new KktMonitor(password: 'password'); $this->assertEquals('password', $client->getPassword()); @@ -132,7 +152,7 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\KktMonitor::setPassword * @covers \AtolOnline\Exceptions\EmptyPasswordException */ - public function testEmptyPasswordException() + public function testEmptyPasswordException(): void { $this->expectException(EmptyPasswordException::class); new KktMonitor(password: ''); @@ -148,7 +168,7 @@ class KktMonitorTest extends BasicTestCase * @throws TooLongLoginException * @throws TooLongPasswordException */ - public function testConstructorWithLongPassword() + public function testConstructorWithLongPassword(): void { $this->expectException(TooLongPasswordException::class); new KktMonitor(password: Helpers::randomStr(101)); @@ -161,7 +181,7 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\KktMonitor::isTestMode * @covers \AtolOnline\Api\KktMonitor::setTestMode */ - public function testTestMode() + public function testTestMode(): void { $client = new KktMonitor(); $this->assertTrue($client->isTestMode()); @@ -182,23 +202,6 @@ class KktMonitorTest extends BasicTestCase $this->assertFalse($client->isTestMode()); } - /** - * Возвращает объект клиента для тестирования с тестовым API АТОЛ - * - * @return AtolClient - * @throws EmptyLoginException - * @throws EmptyPasswordException - * @throws TooLongLoginException - * @throws TooLongPasswordException - */ - private function newTestClient(): KktMonitor - { - $credentials = TestEnvParams::FFD105(); - return (new KktMonitor(true)) - ->setLogin($credentials['login']) - ->setPassword($credentials['password']); - } - /** * Тестирует авторизацию * @@ -207,6 +210,7 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\KktMonitor::getAuthEndpoint * @covers \AtolOnline\Api\KktMonitor::doAuth * @covers \AtolOnline\Api\KktMonitor::auth + * @covers \AtolOnline\Exceptions\AuthFailedException * @throws EmptyLoginException * @throws EmptyPasswordException * @throws TooLongLoginException @@ -214,7 +218,7 @@ class KktMonitorTest extends BasicTestCase * @throws AuthFailedException * @throws GuzzleException */ - public function testAuth() + public function testAuth(): void { $this->skipIfMonitoringIsOffline(); $result = $this->newTestClient()->auth(); @@ -227,6 +231,7 @@ class KktMonitorTest extends BasicTestCase * @depends testAuth * @covers \AtolOnline\Api\KktMonitor::setToken * @covers \AtolOnline\Api\KktMonitor::getToken + * @covers \AtolOnline\Exceptions\AuthFailedException * @throws AuthFailedException * @throws EmptyLoginException * @throws EmptyPasswordException @@ -234,7 +239,7 @@ class KktMonitorTest extends BasicTestCase * @throws TooLongLoginException * @throws TooLongPasswordException */ - public function testGetToken() + public function testGetToken(): void { $client = new KktMonitor(); $this->assertNull($client->getToken()); @@ -250,6 +255,7 @@ class KktMonitorTest extends BasicTestCase * * @depends testAuth * @covers \AtolOnline\Api\KktMonitor::getResponse + * @covers \AtolOnline\Exceptions\AuthFailedException * @throws AuthFailedException * @throws EmptyLoginException * @throws EmptyPasswordException @@ -257,7 +263,7 @@ class KktMonitorTest extends BasicTestCase * @throws TooLongLoginException * @throws TooLongPasswordException */ - public function testGetResponse() + public function testGetResponse(): void { $this->skipIfMonitoringIsOffline(); $client = $this->newTestClient(); @@ -273,6 +279,7 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\AtolClient::getUrlToMethod * @covers \AtolOnline\Api\KktMonitor::fetchAll * @covers \AtolOnline\Api\KktMonitor::getAll + * @covers \AtolOnline\Exceptions\AuthFailedException * @throws AuthFailedException * @throws EmptyLoginException * @throws EmptyPasswordException @@ -280,7 +287,7 @@ class KktMonitorTest extends BasicTestCase * @throws TooLongLoginException * @throws TooLongPasswordException */ - public function testMonitorGetAll() + public function testMonitorGetAll(): void { $this->skipIfMonitoringIsOffline(); $client = $this->newTestClient(); @@ -289,6 +296,7 @@ class KktMonitorTest extends BasicTestCase $this->assertNotEmpty($client->getResponse()->getContent()); $this->assertIsCollection($kkts); $this->assertTrue($kkts->count() > 0); + $this->assertIsSameClass(Kkt::class, $kkts->random()); } /** @@ -299,24 +307,30 @@ class KktMonitorTest extends BasicTestCase * @covers \AtolOnline\Api\AtolClient::getUrlToMethod * @covers \AtolOnline\Api\KktMonitor::fetchOne * @covers \AtolOnline\Api\KktMonitor::getOne + * @covers \AtolOnline\Entities\Kkt::__construct + * @covers \AtolOnline\Entities\Kkt::__get + * @covers \AtolOnline\Entities\Kkt::jsonSerialize + * @covers \AtolOnline\Entities\Kkt::__toString * @throws AuthFailedException * @throws EmptyLoginException * @throws EmptyPasswordException * @throws GuzzleException * @throws TooLongLoginException * @throws TooLongPasswordException + * @throws EmptyMonitorDataException + * @throws NotEnoughMonitorDataException */ - public function testGetOne() + public function testMOnitorGetOne(): void { $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()); + $serial_number = $client->getAll()->random()->serialNumber; + $kkt = $client->getOne($serial_number); $this->assertNotEmpty($client->getResponse()); - $this->assertNotNull($client->getResponse()->data->serialNumber); - $this->assertEquals($serial_number, $client->getResponse()->data->serialNumber); + $this->assertIsSameClass(Kkt::class, $kkt); + $this->assertAtolable($kkt); + $this->assertNotNull($kkt->serialNumber); + $this->assertEquals($serial_number, $kkt->serialNumber); } } diff --git a/tests/VatTest_todo.php b/tests/VatTest_todo.php index b65fee9..17eaa01 100644 --- a/tests/VatTest_todo.php +++ b/tests/VatTest_todo.php @@ -10,9 +10,8 @@ namespace AtolOnlineTests; use AtolOnline\{ - Constants\VatTypes, - Entities\Vat -}; + Entities\Vat, + Enums\VatTypes}; /** * Class VatTest