2021-12-03 12:09:14 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-12-03 12:09:14 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace AtolOnline\Tests\Entities;
|
|
|
|
|
|
|
|
|
|
use AtolOnline\{
|
|
|
|
|
Entities\CorrectionInfo,
|
2022-12-14 16:19:55 +00:00
|
|
|
|
Enums\CorrectionType,
|
2021-12-03 12:09:14 +00:00
|
|
|
|
Exceptions\EmptyCorrectionNumberException,
|
|
|
|
|
Exceptions\InvalidCorrectionDateException,
|
|
|
|
|
Helpers,
|
2021-12-06 08:14:19 +00:00
|
|
|
|
Tests\BasicTestCase};
|
2022-12-14 16:19:55 +00:00
|
|
|
|
use DateTime;
|
|
|
|
|
use DateTimeImmutable;
|
2021-12-06 08:14:19 +00:00
|
|
|
|
use Exception;
|
2021-12-03 12:09:14 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Набор тестов для проверки работы класса данных коррекции
|
|
|
|
|
*/
|
|
|
|
|
class CorrectionInfoTest extends BasicTestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует конструктор
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::setType
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::getType
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::setDate
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::getDate
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::setNumber
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::getNumber
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::jsonSerialize
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws InvalidCorrectionDateException
|
|
|
|
|
* @throws EmptyCorrectionNumberException
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @throws Exception
|
2021-12-03 12:09:14 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructor(): void
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable(
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new CorrectionInfo(CorrectionType::SELF, '01.01.2021', $number = Helpers::randomStr()),
|
2021-12-03 12:09:14 +00:00
|
|
|
|
[
|
2022-12-14 16:19:55 +00:00
|
|
|
|
'type' => CorrectionType::SELF,
|
2021-12-03 12:09:14 +00:00
|
|
|
|
'base_date' => '01.01.2021',
|
|
|
|
|
'base_number' => $number,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertIsAtolable(
|
|
|
|
|
new CorrectionInfo(CorrectionType::SELF, new DateTime('02.02.2022'), $number = Helpers::randomStr()),
|
|
|
|
|
[
|
|
|
|
|
'type' => CorrectionType::SELF,
|
|
|
|
|
'base_date' => '02.02.2022',
|
|
|
|
|
'base_number' => $number,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertIsAtolable(
|
|
|
|
|
new CorrectionInfo(
|
|
|
|
|
CorrectionType::SELF,
|
|
|
|
|
new DateTimeImmutable('03.03.2023'),
|
|
|
|
|
$number = Helpers::randomStr()
|
|
|
|
|
),
|
|
|
|
|
[
|
|
|
|
|
'type' => CorrectionType::SELF,
|
|
|
|
|
'base_date' => '03.03.2023',
|
|
|
|
|
'base_number' => $number,
|
|
|
|
|
]
|
|
|
|
|
);
|
2021-12-03 12:09:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при некорректной дате
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::setDate
|
|
|
|
|
* @covers \AtolOnline\Exceptions\InvalidCorrectionDateException
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws EmptyCorrectionNumberException
|
|
|
|
|
* @throws InvalidCorrectionDateException
|
|
|
|
|
*/
|
|
|
|
|
public function testInvalidCorrectionDateException(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(InvalidCorrectionDateException::class);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new CorrectionInfo(CorrectionType::SELF, Helpers::randomStr(), Helpers::randomStr());
|
2021-12-03 12:09:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при некорректной дате
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo
|
|
|
|
|
* @covers \AtolOnline\Entities\CorrectionInfo::setNumber
|
|
|
|
|
* @covers \AtolOnline\Exceptions\EmptyCorrectionNumberException
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function testEmptyCorrectionNumberException(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(EmptyCorrectionNumberException::class);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new CorrectionInfo(CorrectionType::SELF, '01.01.2021', "\n\r\t\0");
|
2021-12-03 12:09:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|