2021-11-20 15:38:19 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-11-20 15:38:19 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-14 16:19:55 +00:00
|
|
|
|
declare(strict_types=1);
|
2021-11-20 15:38:19 +00:00
|
|
|
|
|
2021-11-23 17:30:54 +00:00
|
|
|
|
namespace AtolOnline\Tests\Entities;
|
2021-11-20 15:38:19 +00:00
|
|
|
|
|
|
|
|
|
use AtolOnline\Entities\Kkt;
|
|
|
|
|
use AtolOnline\Exceptions\EmptyMonitorDataException;
|
|
|
|
|
use AtolOnline\Exceptions\NotEnoughMonitorDataException;
|
2021-11-23 17:30:54 +00:00
|
|
|
|
use AtolOnline\Tests\BasicTestCase;
|
2021-11-20 15:38:19 +00:00
|
|
|
|
use DateTime;
|
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
|
|
class KktEntityTest extends BasicTestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var array Данные для создания объекта ККТ
|
|
|
|
|
*/
|
|
|
|
|
private array $sample_data = [
|
|
|
|
|
'serialNumber' => '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);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable($kkt);
|
2021-11-20 15:38:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при попытке создать объект ККТ без данных от монитора
|
|
|
|
|
*
|
|
|
|
|
* @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);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new Kkt(
|
|
|
|
|
(object)[
|
|
|
|
|
'fiscalizationDate' => '2021-11-20T10:21:00+00:00',
|
|
|
|
|
]
|
|
|
|
|
);
|
2021-11-20 15:38:19 +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);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($this->sample_data['serialNumber'], $kkt->serialNumber);
|
2021-11-20 15:38:19 +00:00
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
}
|