2021-12-06 06:16:50 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-12-06 06:16:50 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2021-12-06 08:14:19 +00:00
|
|
|
|
namespace AtolOnline\Tests\Collections;
|
2021-12-06 06:16:50 +00:00
|
|
|
|
|
|
|
|
|
use AtolOnline\{
|
2021-12-06 08:14:19 +00:00
|
|
|
|
Collections\Vats,
|
2022-12-14 16:19:55 +00:00
|
|
|
|
Constraints,
|
2021-12-06 08:14:19 +00:00
|
|
|
|
Entities\Payment,
|
2022-12-14 16:19:55 +00:00
|
|
|
|
Enums\PaymentType,
|
2021-12-09 12:13:43 +00:00
|
|
|
|
Exceptions\EmptyVatsException,
|
2021-12-06 08:14:19 +00:00
|
|
|
|
Exceptions\InvalidEntityInCollectionException,
|
2021-12-06 06:16:50 +00:00
|
|
|
|
Exceptions\InvalidEnumValueException,
|
2021-12-06 08:14:19 +00:00
|
|
|
|
Exceptions\NegativePaymentSumException,
|
|
|
|
|
Exceptions\TooHighPaymentSumException,
|
2021-12-06 06:16:50 +00:00
|
|
|
|
Exceptions\TooManyVatsException,
|
|
|
|
|
Tests\BasicTestCase};
|
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Набор тестов для проверки работы класса коллекции объектов на примере класса коллекции ставок НДС
|
|
|
|
|
*/
|
|
|
|
|
class VatsTest extends BasicTestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует создание коллекции ставок
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
2021-12-09 12:13:43 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
2021-12-06 06:16:50 +00:00
|
|
|
|
* @throws InvalidEnumValueException
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @throws Exception
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructor()
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$vats = new Vats($this->generateVatObjects(3));
|
2021-12-06 06:16:50 +00:00
|
|
|
|
$this->assertIsCollection($vats);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame(3, $vats->count());
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable($vats);
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-12-09 12:13:43 +00:00
|
|
|
|
* Тестирует выброс исключения при установке нулевого количества ставок
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
2021-12-09 12:13:43 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
|
|
|
|
* @covers \AtolOnline\Exceptions\EmptyVatsException
|
2021-12-07 12:04:03 +00:00
|
|
|
|
* @throws InvalidEntityInCollectionException
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*/
|
2021-12-09 12:13:43 +00:00
|
|
|
|
public function testEmptyVatsException()
|
2021-12-06 06:16:50 +00:00
|
|
|
|
{
|
2021-12-09 12:13:43 +00:00
|
|
|
|
$this->expectException(EmptyVatsException::class);
|
|
|
|
|
(new Vats([]))->jsonSerialize();
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-12-09 12:13:43 +00:00
|
|
|
|
* Тестирует выброс исключения при установке слишком большого количества ставок
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
2021-12-09 12:13:43 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
2021-12-06 06:16:50 +00:00
|
|
|
|
* @covers \AtolOnline\Exceptions\TooManyVatsException
|
|
|
|
|
* @throws InvalidEnumValueException
|
2021-12-07 12:04:03 +00:00
|
|
|
|
* @throws InvalidEntityInCollectionException
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*/
|
2021-12-09 12:13:43 +00:00
|
|
|
|
public function testTooManyVatsException()
|
2021-12-06 06:16:50 +00:00
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooManyVatsException::class);
|
2021-12-09 12:13:43 +00:00
|
|
|
|
(new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS + 1)))->jsonSerialize();
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 08:14:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при наличии скаляров в коллекции
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
2021-12-07 12:04:03 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkItemClass
|
2021-12-09 12:13:43 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
|
|
|
|
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
|
|
|
|
|
* @throws InvalidEnumValueException
|
|
|
|
|
* @throws Exception
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @noinspection PhpParamsInspection
|
2021-12-06 08:14:19 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testInvalidCollectionItemExceptionScalar(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(InvalidEntityInCollectionException::class);
|
|
|
|
|
$this->expectExceptionMessage("(string)'bad element'");
|
2021-12-07 12:04:03 +00:00
|
|
|
|
(new Vats($this->generateVatObjects(2)))
|
2021-12-06 08:14:19 +00:00
|
|
|
|
->merge('bad element')
|
|
|
|
|
->jsonSerialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при наличии объектов не тех классов в коллекции
|
|
|
|
|
*
|
2021-12-09 12:13:43 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkItemClass
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @throws InvalidEnumValueException
|
|
|
|
|
* @throws NegativePaymentSumException
|
|
|
|
|
* @throws TooHighPaymentSumException
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testInvalidCollectionItemExceptionObject(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(InvalidEntityInCollectionException::class);
|
|
|
|
|
$this->expectExceptionMessage(Payment::class);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
(new Vats($this->generateVatObjects()))
|
2022-12-14 16:19:55 +00:00
|
|
|
|
->merge([new Payment(PaymentType::PREPAID, 1)])
|
2021-12-06 08:14:19 +00:00
|
|
|
|
->jsonSerialize();
|
|
|
|
|
}
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|