2021-12-06 06:16:50 +00:00
|
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
* 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,
|
2021-12-06 06:16:50 +00:00
|
|
|
|
Constants\Constraints,
|
2021-12-06 08:14:19 +00:00
|
|
|
|
Entities\Payment,
|
|
|
|
|
Enums\PaymentTypes,
|
|
|
|
|
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-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);
|
|
|
|
|
$this->assertEquals(3, $vats->count());
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable($vats);
|
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-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
|
|
|
|
*/
|
|
|
|
|
public function testTooManyVatsExceptionByConstructor()
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooManyVatsException::class);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS + 1));
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует добавление ставки в начало коллекции
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::prepend
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
2021-12-06 06:16:50 +00:00
|
|
|
|
* @throws InvalidEnumValueException
|
2021-12-07 12:04:03 +00:00
|
|
|
|
* @throws InvalidEntityInCollectionException
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testPrepend()
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$vats = (new Vats($this->generateVatObjects(3)))
|
|
|
|
|
->prepend($this->generateVatObjects());
|
2021-12-06 06:16:50 +00:00
|
|
|
|
$this->assertEquals(4, $vats->count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при добавлении лишней ставки в начало коллекции
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::prepend
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
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
|
|
|
|
*/
|
|
|
|
|
public function testTooManyVatsExceptionByPrepend()
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooManyVatsException::class);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
(new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
|
|
|
|
->prepend($this->generateVatObjects());
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует добавление ставки в конец коллекции
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::add
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
2021-12-06 06:16:50 +00:00
|
|
|
|
* @throws InvalidEnumValueException
|
2021-12-07 12:04:03 +00:00
|
|
|
|
* @throws InvalidEntityInCollectionException
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAdd()
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$vats = (new Vats($this->generateVatObjects(3)))
|
|
|
|
|
->add($this->generateVatObjects());
|
2021-12-06 06:16:50 +00:00
|
|
|
|
$this->assertEquals(4, $vats->count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при добавлении лишней ставки в конец коллекции
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::add
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
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
|
|
|
|
*/
|
|
|
|
|
public function testTooManyVatsExceptionByAdd()
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooManyVatsException::class);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
(new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
|
|
|
|
->add($this->generateVatObjects());
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует добавление лишних ставок в конец коллекции
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::push
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
2021-12-06 06:16:50 +00:00
|
|
|
|
* @throws InvalidEnumValueException
|
2021-12-07 12:04:03 +00:00
|
|
|
|
* @throws InvalidEntityInCollectionException
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testPush()
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$vats = (new Vats($this->generateVatObjects(3)))
|
|
|
|
|
->push(...$this->generateVatObjects(3));
|
2021-12-06 06:16:50 +00:00
|
|
|
|
$this->assertEquals(6, $vats->count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при добавлении лишних ставок в конец коллекции
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::push
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
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
|
|
|
|
*/
|
|
|
|
|
public function testTooManyVatsExceptionByPush()
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooManyVatsException::class);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
(new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
|
|
|
|
->push(...$this->generateVatObjects());
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует добавление ставки в начало коллекции
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::merge
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
2021-12-06 06:16:50 +00:00
|
|
|
|
* @throws InvalidEnumValueException
|
2021-12-07 12:04:03 +00:00
|
|
|
|
* @throws InvalidEntityInCollectionException
|
2021-12-06 06:16:50 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testMerge()
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$vats = (new Vats($this->generateVatObjects(3)))
|
|
|
|
|
->merge($this->generateVatObjects(3));
|
2021-12-06 06:16:50 +00:00
|
|
|
|
$this->assertEquals(6, $vats->count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при добавлении лишней ставки в начало коллекции
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::merge
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::checkCount
|
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
|
|
|
|
*/
|
|
|
|
|
public function testTooManyVatsExceptionByMerge()
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooManyVatsException::class);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
(new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS - 1)))
|
|
|
|
|
->merge($this->generateVatObjects(2));
|
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-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
|
|
|
|
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
|
|
|
|
|
* @throws InvalidEnumValueException
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при наличии объектов не тех классов в коллекции
|
|
|
|
|
*
|
|
|
|
|
* @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()))
|
2021-12-06 08:14:19 +00:00
|
|
|
|
->merge([new Payment(PaymentTypes::PREPAID, 1)])
|
|
|
|
|
->jsonSerialize();
|
|
|
|
|
}
|
2021-12-06 06:16:50 +00:00
|
|
|
|
}
|