2021-11-27 16:58:05 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-11-27 16:58:05 +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\Vat,
|
2022-12-14 16:19:55 +00:00
|
|
|
|
Enums\VatType,
|
2021-12-06 06:13:48 +00:00
|
|
|
|
Tests\BasicTestCase};
|
2021-12-06 08:14:19 +00:00
|
|
|
|
use Exception;
|
2021-11-27 16:58:05 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Набор тестов для проверки работы класса ставки НДС
|
|
|
|
|
*/
|
|
|
|
|
class VatTest extends BasicTestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Провайдер данных для тестирования разных типов ставок НДС
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function providerVatsSet(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2022-12-14 16:19:55 +00:00
|
|
|
|
[VatType::NONE, 0],
|
|
|
|
|
[VatType::VAT0, 0],
|
|
|
|
|
[VatType::VAT10, 10],
|
|
|
|
|
[VatType::VAT18, 18],
|
|
|
|
|
[VatType::VAT20, 20],
|
|
|
|
|
[VatType::VAT110, 9.09],
|
|
|
|
|
[VatType::VAT118, 15.25],
|
|
|
|
|
[VatType::VAT120, 16.67],
|
2021-11-27 16:58:05 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Провайдер данных для тестирования разных типов ставок НДС
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function providerVatsAdd(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2022-12-14 16:19:55 +00:00
|
|
|
|
[VatType::VAT10, 12, 10],
|
|
|
|
|
[VatType::VAT18, 21.6, 18],
|
|
|
|
|
[VatType::VAT20, 24, 20],
|
|
|
|
|
[VatType::VAT110, 10.91, 9.09],
|
|
|
|
|
[VatType::VAT118, 18.31, 15.25],
|
|
|
|
|
[VatType::VAT120, 20, 16.67],
|
2021-11-27 16:58:05 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует конструктор без передачи значений и приведение к json
|
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param VatType $type Тип НДС
|
2021-11-27 16:58:05 +00:00
|
|
|
|
* @param float $sum Исходная сумма
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @throws Exception
|
2021-11-27 16:58:05 +00:00
|
|
|
|
* @dataProvider providerVatsSet
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat::setType
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat::getType
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat::setSum
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat::getSum
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat::getCalculated
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat::jsonSerialize
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function testConstructor(VatType $type, float $sum): void
|
2021-11-27 16:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
$vat = new Vat($type, $sum);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable($vat, [
|
2021-11-27 16:58:05 +00:00
|
|
|
|
'type' => $vat->getType(),
|
|
|
|
|
'sum' => $vat->getCalculated(),
|
|
|
|
|
]);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($type, $vat->getType());
|
|
|
|
|
$this->assertSame($sum, $vat->getSum());
|
2021-11-27 16:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-12-06 06:13:48 +00:00
|
|
|
|
* Тестирует расчёт суммы НДС от суммы 100+20р и 100-20р
|
2021-11-27 16:58:05 +00:00
|
|
|
|
*
|
|
|
|
|
* @dataProvider providerVatsAdd
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param VatType $type Тип НДС
|
2021-11-27 16:58:05 +00:00
|
|
|
|
* @param float $after_plus Результат после +20р
|
|
|
|
|
* @param float $after_minus Результат после -20р
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat::addSum
|
|
|
|
|
* @covers \AtolOnline\Entities\Vat::getCalculated
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function testVatAdd(VatType $type, float $after_plus, float $after_minus)
|
2021-11-27 16:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
$vat = (new Vat($type, 100))->addSum(20); // 120р
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($after_plus, $vat->getCalculated());
|
2021-11-27 16:58:05 +00:00
|
|
|
|
$vat->addSum(-20); // 100р
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($after_minus, $vat->getCalculated());
|
2021-11-27 16:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|