Доработка коллекций и не только

- коллекция `Items` с покрытием
- вынос коллекций из `AtolOnline\Entities` в `AtolOnline\Collections`
- фикс ] в `AtolException`
- финализирован `CorrectionInfo`
- фиксы по тестам коллекций
- прочие мелочи по phpdoc
This commit is contained in:
2021-12-06 16:14:19 +08:00
parent bf09641c8b
commit 557c76fefa
25 changed files with 441 additions and 120 deletions

View File

@@ -19,8 +19,8 @@ use AtolOnline\{
Exceptions\InvalidInnLengthException,
Exceptions\InvalidPhoneException,
Exceptions\TooLongPayingAgentOperationException,
Tests\BasicTestCase
};
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса агента
@@ -32,6 +32,7 @@ class AgentInfoTest extends BasicTestCase
*
* @covers \AtolOnline\Entities\AgentInfo
* @covers \AtolOnline\Entities\AgentInfo::jsonSerialize
* @throws Exception
*/
public function testConstructorWithoutArgs(): void
{
@@ -58,6 +59,7 @@ class AgentInfoTest extends BasicTestCase
* @throws TooLongPayingAgentOperationException
* @throws InvalidInnLengthException
* @throws InvalidEnumValueException
* @throws Exception
*/
public function testConstructorWithArgs(): void
{

View File

@@ -18,6 +18,7 @@ use AtolOnline\{
Exceptions\TooLongEmailException,
Helpers,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса покупателя
@@ -29,6 +30,7 @@ class ClientTest extends BasicTestCase
*
* @covers \AtolOnline\Entities\Client
* @covers \AtolOnline\Entities\Client::jsonSerialize
* @throws Exception
*/
public function testConstructorWithoutArgs(): void
{
@@ -48,6 +50,7 @@ class ClientTest extends BasicTestCase
* @covers \AtolOnline\Entities\Client::getPhone
* @covers \AtolOnline\Entities\Client::getEmail
* @covers \AtolOnline\Entities\Client::getInn
* @throws Exception
*/
public function testConstructorWithArgs(): void
{

View File

@@ -20,6 +20,7 @@ use AtolOnline\{
Exceptions\TooLongPaymentAddressException,
Helpers,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса продавца
@@ -39,6 +40,7 @@ class CompanyTest extends BasicTestCase
* @covers \AtolOnline\Entities\Company::getSno
* @covers \AtolOnline\Entities\Company::getInn
* @covers \AtolOnline\Entities\Company::getPaymentAddress
* @throws Exception
*/
public function testConstructor()
{
@@ -61,6 +63,12 @@ class CompanyTest extends BasicTestCase
* @covers \AtolOnline\Entities\Company
* @covers \AtolOnline\Entities\Company::setEmail
* @covers \AtolOnline\Exceptions\TooLongEmailException
* @throws InvalidEmailException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws TooLongEmailException
* @throws TooLongPaymentAddressException
*/
public function testEmailTooLongException()
{
@@ -100,6 +108,12 @@ class CompanyTest extends BasicTestCase
* @covers \AtolOnline\Entities\Company
* @covers \AtolOnline\Entities\Company::setInn
* @covers \AtolOnline\Exceptions\InvalidInnLengthException
* @throws InvalidEmailException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws TooLongEmailException
* @throws TooLongPaymentAddressException
*/
public function testInvalidInnLengthException()
{
@@ -113,6 +127,12 @@ class CompanyTest extends BasicTestCase
* @covers \AtolOnline\Entities\Company
* @covers \AtolOnline\Entities\Company::setPaymentAddress
* @covers \AtolOnline\Exceptions\TooLongPaymentAddressException
* @throws InvalidEmailException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws TooLongEmailException
* @throws TooLongPaymentAddressException
*/
public function testTooLongPaymentAddressException()
{

View File

@@ -16,8 +16,8 @@ use AtolOnline\{
Exceptions\InvalidCorrectionDateException,
Exceptions\InvalidEnumValueException,
Helpers,
Tests\BasicTestCase
};
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса данных коррекции
@@ -39,6 +39,7 @@ class CorrectionInfoTest extends BasicTestCase
* @throws InvalidEnumValueException
* @throws InvalidCorrectionDateException
* @throws EmptyCorrectionNumberException
* @throws Exception
*/
public function testConstructor(): void
{

View File

@@ -41,8 +41,8 @@ use AtolOnline\{
Exceptions\TooLongUserdataException,
Exceptions\TooManyException,
Helpers,
Tests\BasicTestCase
};
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класс продавца
@@ -67,6 +67,7 @@ class ItemTest extends BasicTestCase
* @throws NegativeItemPriceException
* @throws EmptyItemNameException
* @throws NegativeItemQuantityException
* @throws Exception
*/
public function testConstructor(): void
{
@@ -263,6 +264,7 @@ class ItemTest extends BasicTestCase
* @throws TooHighItemPriceException
* @throws NegativeItemQuantityException
* @throws TooLongItemNameException
* @throws Exception
*/
public function testValidEnums(): void
{
@@ -332,11 +334,14 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getVat
* @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws EmptyItemNameException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws TooHighItemPriceException
* @throws TooHighItemSumException
* @throws TooLongItemNameException
* @throws TooManyException
* @throws Exception
*/
public function testValidVatByString(): void
{
@@ -363,11 +368,14 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getVat
* @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws EmptyItemNameException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws TooHighItemPriceException
* @throws TooHighItemSumException
* @throws TooLongItemNameException
* @throws TooManyException
* @throws Exception
*/
public function testValidVatByObject(): void
{
@@ -453,6 +461,7 @@ class ItemTest extends BasicTestCase
* @throws TooHighItemPriceException
* @throws TooLongItemNameException
* @throws TooManyException
* @throws Exception
*/
public function testSupplier(): void
{
@@ -489,6 +498,7 @@ class ItemTest extends BasicTestCase
* @throws TooLongItemNameException
* @throws TooLongUserdataException
* @throws TooManyException
* @throws Exception
*/
public function testValidUserdata(): void
{
@@ -558,6 +568,7 @@ class ItemTest extends BasicTestCase
* @throws TooHighItemPriceException
* @throws TooLongItemNameException
* @throws TooManyException
* @throws Exception
*/
public function testCountryCode(): void
{
@@ -605,6 +616,7 @@ class ItemTest extends BasicTestCase
* @throws TooLongItemNameException
* @throws TooManyException
* @throws InvalidDeclarationNumberException
* @throws Exception
*/
public function testValidDeclarationNumber(): void
{
@@ -675,6 +687,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException
* @throws NegativeItemQuantityException
* @throws NegativeItemExciseException
* @throws Exception
*/
public function testExcise(): void
{
@@ -723,6 +736,7 @@ class ItemTest extends BasicTestCase
* @throws TooLongItemNameException
* @throws TooManyException
* @throws TooLongItemCodeException
* @throws Exception
*/
public function testValidNomenclatureCode(): void
{

View File

@@ -14,6 +14,7 @@ use AtolOnline\{
Exceptions\InvalidInnLengthException,
Exceptions\InvalidPhoneException,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса оператора перевода
@@ -46,6 +47,7 @@ class MoneyTransferOperatorTest extends BasicTestCase
* @covers \AtolOnline\Entities\MoneyTransferOperator::getAddress
* @throws InvalidPhoneException
* @throws InvalidInnLengthException
* @throws Exception
*/
public function testConstructorWithArgs(): void
{

View File

@@ -15,6 +15,7 @@ use AtolOnline\{
Exceptions\TooLongPayingAgentOperationException,
Helpers,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса платёжного агента
@@ -43,6 +44,7 @@ class PayingAgentTest extends BasicTestCase
* @covers \AtolOnline\Entities\PayingAgent::getPhones
* @throws InvalidPhoneException
* @throws TooLongPayingAgentOperationException
* @throws Exception
*/
public function testConstructorWithArgs(): void
{

View File

@@ -13,13 +13,12 @@ use AtolOnline\{
Constants\Constraints,
Entities\Payment,
Enums\PaymentTypes,
Tests\BasicTestCase
};
Tests\BasicTestCase};
use AtolOnline\Exceptions\{
InvalidEnumValueException,
NegativePaymentSumException,
TooHighPaymentSumException,
};
TooHighPaymentSumException,};
use Exception;
/**
* Набор тестов для проверки работы класса оплаты
@@ -39,6 +38,7 @@ class PaymentTest extends BasicTestCase
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws Exception
*/
public function testConstructor(): void
{

View File

@@ -1,136 +0,0 @@
<?php
/*
* 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\{
Constants\Constraints,
Entities\Payment,
Entities\Payments,
Enums\PaymentTypes,
Exceptions\InvalidEnumValueException,
Exceptions\NegativePaymentSumException,
Exceptions\TooHighPaymentSumException,
Exceptions\TooManyPaymentsException,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса коллекции оплат
*/
class PaymentsTest extends BasicTestCase
{
/**
* Тестирует выброс исключения при установке слишком большого количества оплат через конструктор
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyPaymentsException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testTooManyPaymentsExceptionByConstructor()
{
$this->expectException(TooManyPaymentsException::class);
new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1));
}
/**
* Тестирует выброс исключения при добавлении лишней ставки в начало коллекции
*
* @covers \AtolOnline\Entities\EntityCollection::prepend
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyPaymentsException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testTooManyPaymentsExceptionByPrepend()
{
$this->expectException(TooManyPaymentsException::class);
(new Payments($this->generateObjects(10)))
->prepend($this->generateObjects());
}
/**
* Тестирует выброс исключения при добавлении лишней ставки в конец коллекции
*
* @covers \AtolOnline\Entities\Payments
* @covers \AtolOnline\Entities\Payments::add
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyPaymentsException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testTooManyPaymentsExceptionByAdd()
{
$this->expectException(TooManyPaymentsException::class);
(new Payments($this->generateObjects(10)))
->add($this->generateObjects());
}
/**
* Тестирует выброс исключения при добавлении лишних оплат в конец коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::push
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyPaymentsException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testTooManyPaymentsExceptionByPush()
{
$this->expectException(TooManyPaymentsException::class);
(new Payments($this->generateObjects(10)))
->push(...$this->generateObjects());
}
/**
* Тестирует выброс исключения при добавлении лишней ставки в начало коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::merge
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyPaymentsException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testTooManyPaymentsExceptionByMerge()
{
$this->expectException(TooManyPaymentsException::class);
(new Payments($this->generateObjects(9)))
->merge($this->generateObjects(2));
}
/**
* Генерирует массив тестовых объектов оплаты
*
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws Exception
*/
protected function generateObjects(int $count = 1): array
{
$types = PaymentTypes::toArray();
$result = [];
for ($i = 0; $i < abs($count); ++$i) {
$result[] = new Payment(
array_values($types)[random_int(min($types), max($types))],
random_int(1, 100) * 2 / 3
);
}
return $result;
}
}

View File

@@ -13,6 +13,7 @@ use AtolOnline\{
Entities\ReceivePaymentsOperator,
Exceptions\InvalidPhoneException,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса оператора по приёму платежей
@@ -38,6 +39,7 @@ class ReceivePaymentsOperatorTest extends BasicTestCase
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::setPhones
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::getPhones
* @throws InvalidPhoneException
* @throws Exception
*/
public function testConstructorWithArgs(): void
{

View File

@@ -14,6 +14,7 @@ use AtolOnline\{
Exceptions\InvalidInnLengthException,
Exceptions\InvalidPhoneException,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса поставщика
@@ -44,6 +45,7 @@ class SupplierTest extends BasicTestCase
* @covers \AtolOnline\Entities\Supplier::getInn
* @throws InvalidPhoneException
* @throws InvalidInnLengthException
* @throws Exception
*/
public function testConstructorWithArgs(): void
{

View File

@@ -14,6 +14,7 @@ use AtolOnline\{
Enums\VatTypes,
Exceptions\InvalidEnumValueException,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса ставки НДС
@@ -70,6 +71,7 @@ class VatTest extends BasicTestCase
* @covers \AtolOnline\Entities\Vat::getCalculated
* @covers \AtolOnline\Entities\Vat::jsonSerialize
* @throws InvalidEnumValueException
* @throws Exception
*/
public function testConstructor(string $type, float $sum): void
{

View File

@@ -1,197 +0,0 @@
<?php
/*
* 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\{
Constants\Constraints,
Entities\Vat,
Entities\Vats,
Enums\VatTypes,
Exceptions\InvalidEnumValueException,
Exceptions\TooManyVatsException,
Tests\BasicTestCase};
use Exception;
/**
* Набор тестов для проверки работы класса коллекции объектов на примере класса коллекции ставок НДС
*/
class VatsTest extends BasicTestCase
{
/**
* Тестирует создание коллекции ставок
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @throws InvalidEnumValueException
*/
public function testConstructor()
{
$vats = new Vats($this->generateObjects(3));
$this->assertIsCollection($vats);
$this->assertEquals(3, $vats->count());
}
/**
* Тестирует выброс исключения при установке слишком большого количества ставок через конструктор
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyVatsException
* @throws InvalidEnumValueException
*/
public function testTooManyVatsExceptionByConstructor()
{
$this->expectException(TooManyVatsException::class);
new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS + 1));
}
/**
* Тестирует добавление ставки в начало коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::prepend
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @throws InvalidEnumValueException
*/
public function testPrepend()
{
$vats = (new Vats($this->generateObjects(3)))
->prepend($this->generateObjects());
$this->assertEquals(4, $vats->count());
}
/**
* Тестирует выброс исключения при добавлении лишней ставки в начало коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::prepend
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyVatsException
* @throws InvalidEnumValueException
*/
public function testTooManyVatsExceptionByPrepend()
{
$this->expectException(TooManyVatsException::class);
(new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS + 1)))
->prepend($this->generateObjects());
}
/**
* Тестирует добавление ставки в конец коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::add
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @throws InvalidEnumValueException
*/
public function testAdd()
{
$vats = (new Vats($this->generateObjects(3)))
->add($this->generateObjects());
$this->assertEquals(4, $vats->count());
}
/**
* Тестирует выброс исключения при добавлении лишней ставки в конец коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::add
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyVatsException
* @throws InvalidEnumValueException
*/
public function testTooManyVatsExceptionByAdd()
{
$this->expectException(TooManyVatsException::class);
(new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS + 1)))
->add($this->generateObjects());
}
/**
* Тестирует добавление лишних ставок в конец коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::push
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @throws InvalidEnumValueException
*/
public function testPush()
{
$vats = (new Vats($this->generateObjects(3)))
->push(...$this->generateObjects(3));
$this->assertEquals(6, $vats->count());
}
/**
* Тестирует выброс исключения при добавлении лишних ставок в конец коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::push
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyVatsException
* @throws InvalidEnumValueException
*/
public function testTooManyVatsExceptionByPush()
{
$this->expectException(TooManyVatsException::class);
(new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS + 1)))
->push(...$this->generateObjects());
}
/**
* Тестирует добавление ставки в начало коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::merge
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @throws InvalidEnumValueException
*/
public function testMerge()
{
$vats = (new Vats($this->generateObjects(3)))
->merge($this->generateObjects(3));
$this->assertEquals(6, $vats->count());
}
/**
* Тестирует выброс исключения при добавлении лишней ставки в начало коллекции
*
* @covers \AtolOnline\Entities\EntityCollection
* @covers \AtolOnline\Entities\EntityCollection::merge
* @covers \AtolOnline\Entities\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyVatsException
* @throws InvalidEnumValueException
*/
public function testTooManyVatsExceptionByMerge()
{
$this->expectException(TooManyVatsException::class);
(new Vats($this->generateObjects(9)))
->merge($this->generateObjects(2));
}
/**
* Генерирует массив тестовых объектов ставок НДС
*
* @throws InvalidEnumValueException
* @throws Exception
*/
protected function generateObjects(int $count = 1): array
{
$types = VatTypes::toArray();
$result = [];
for ($i = 0; $i < abs($count); ++$i) {
$result[] = new Vat(
array_values($types)[random_int(0, count($types) - 1)],
random_int(1, 100) * 2 / 3
);
}
return $result;
}
}