From 557c76fefa7bab7f161ac9ef630e1ef9127f3024 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Mon, 6 Dec 2021 16:14:19 +0800 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B8=20=D0=BD=D0=B5=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - коллекция `Items` с покрытием - вынос коллекций из `AtolOnline\Entities` в `AtolOnline\Collections` - фикс ] в `AtolException` - финализирован `CorrectionInfo` - фиксы по тестам коллекций - прочие мелочи по phpdoc --- .../EntityCollection.php | 45 ++--- src/Collections/Items.php | 35 ++++ src/{Entities => Collections}/Payments.php | 3 +- src/{Entities => Collections}/Vats.php | 10 +- src/Entities/Company.php | 14 +- src/Entities/CorrectionInfo.php | 8 +- src/Entities/Payment.php | 14 +- src/Exceptions/AtolException.php | 2 +- .../InvalidEntityInCollectionException.php | 37 +++++ tests/AtolOnline/Tests/Api/KktMonitorTest.php | 2 + tests/AtolOnline/Tests/BasicTestCase.php | 12 +- .../Tests/Collections/ItemsTest.php | 156 ++++++++++++++++++ .../PaymentsTest.php | 40 ++--- .../{Entities => Collections}/VatsTest.php | 113 +++++++++---- .../Tests/Entities/AgentInfoTest.php | 6 +- .../AtolOnline/Tests/Entities/ClientTest.php | 3 + .../AtolOnline/Tests/Entities/CompanyTest.php | 20 +++ .../Tests/Entities/CorrectionInfoTest.php | 5 +- tests/AtolOnline/Tests/Entities/ItemTest.php | 18 +- .../Entities/MoneyTransferOperatorTest.php | 2 + .../Tests/Entities/PayingAgentTest.php | 2 + .../AtolOnline/Tests/Entities/PaymentTest.php | 8 +- .../Entities/ReceivePaymentsOperatorTest.php | 2 + .../Tests/Entities/SupplierTest.php | 2 + tests/AtolOnline/Tests/Entities/VatTest.php | 2 + 25 files changed, 441 insertions(+), 120 deletions(-) rename src/{Entities => Collections}/EntityCollection.php (57%) create mode 100644 src/Collections/Items.php rename src/{Entities => Collections}/Payments.php (94%) rename src/{Entities => Collections}/Vats.php (72%) create mode 100644 src/Exceptions/InvalidEntityInCollectionException.php create mode 100644 tests/AtolOnline/Tests/Collections/ItemsTest.php rename tests/AtolOnline/Tests/{Entities => Collections}/PaymentsTest.php (76%) rename tests/AtolOnline/Tests/{Entities => Collections}/VatsTest.php (59%) diff --git a/src/Entities/EntityCollection.php b/src/Collections/EntityCollection.php similarity index 57% rename from src/Entities/EntityCollection.php rename to src/Collections/EntityCollection.php index e74557f..74e4c77 100644 --- a/src/Entities/EntityCollection.php +++ b/src/Collections/EntityCollection.php @@ -9,16 +9,14 @@ declare(strict_types = 1); -namespace AtolOnline\Entities; +namespace AtolOnline\Collections; -use Illuminate\Contracts\Support\Arrayable; -use Illuminate\Contracts\Support\Jsonable; +use AtolOnline\Exceptions\InvalidEntityInCollectionException; +use Exception; use Illuminate\Support\Collection; /** * Абстрактное описание коллекции любых сущностей - * - * @todo вот бы ещё проверять классы добавляемых объектов через static.... ммм мякотка */ abstract class EntityCollection extends Collection { @@ -69,21 +67,14 @@ abstract class EntityCollection extends Collection /** * @inheritDoc - * @throws \Exception + * @throws Exception */ public function jsonSerialize(): array { - return array_map(function ($value) { - $this->checkEntityClass($value); - if ($value instanceof \JsonSerializable) { - return $value->jsonSerialize(); - } elseif ($value instanceof Jsonable) { - return json_decode($value->toJson(), true); - } elseif ($value instanceof Arrayable) { - return $value->toArray(); - } - return $value; - }, $this->all()); + $this->each(function ($item) { + $this->checkClass($item); + }); + return parent::jsonSerialize(); } /** @@ -94,26 +85,20 @@ abstract class EntityCollection extends Collection */ private function checkCount(array $items = []): void { - if ( - count($items) > static::MAX_COUNT || - $this->count() === static::MAX_COUNT - ) { - $exception = static::EXCEPTION_CLASS; - throw new $exception(static::MAX_COUNT); + if (count($items) > static::MAX_COUNT || $this->count() === static::MAX_COUNT) { + throw new (static::EXCEPTION_CLASS)(static::MAX_COUNT); } } /** - * @throws \Exception + * Проверяет корректность класса объекта + * + * @throws InvalidEntityInCollectionException */ - private function checkEntityClass(mixed $item): void + private function checkClass(mixed $item): void { if (!is_object($item) || $item::class !== static::ENTITY_CLASS) { - //TODO proper exception - throw new \Exception( - 'Коллекция должна содержать только объекты класса ' . - static::ENTITY_CLASS . ', найден ' . $item::class - ); + throw new InvalidEntityInCollectionException(static::class, static::ENTITY_CLASS, $item); } } } diff --git a/src/Collections/Items.php b/src/Collections/Items.php new file mode 100644 index 0000000..00e740c --- /dev/null +++ b/src/Collections/Items.php @@ -0,0 +1,35 @@ + "string", - 'sno' => "string", - 'inn' => "string", - 'payment_address' => "string", + 'email' => 'string', + 'sno' => 'string', + 'inn' => 'string', + 'payment_address' => 'string', ])] public function jsonSerialize(): array { diff --git a/src/Entities/CorrectionInfo.php b/src/Entities/CorrectionInfo.php index 5579c94..2402640 100644 --- a/src/Entities/CorrectionInfo.php +++ b/src/Entities/CorrectionInfo.php @@ -16,21 +16,19 @@ use AtolOnline\Enums\CorrectionTypes; use AtolOnline\Exceptions\{ EmptyCorrectionNumberException, InvalidCorrectionDateException, - InvalidEnumValueException -}; + InvalidEnumValueException}; use DateTime; use Exception; use JetBrains\PhpStorm\{ ArrayShape, - Pure -}; + Pure}; /** * Класс, описывающий данные коррекции * * @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 35 */ -class CorrectionInfo extends Entity +final class CorrectionInfo extends Entity { /** * @var string|null Тип коррекции (1173) diff --git a/src/Entities/Payment.php b/src/Entities/Payment.php index 17381b4..2982833 100644 --- a/src/Entities/Payment.php +++ b/src/Entities/Payment.php @@ -13,11 +13,13 @@ namespace AtolOnline\Entities; use AtolOnline\Constants\Constraints; use AtolOnline\Enums\PaymentTypes; -use AtolOnline\Exceptions\InvalidEnumValueException; -use AtolOnline\Exceptions\NegativePaymentSumException; -use AtolOnline\Exceptions\TooHighPaymentSumException; -use JetBrains\PhpStorm\ArrayShape; -use JetBrains\PhpStorm\Pure; +use AtolOnline\Exceptions\{ + InvalidEnumValueException, + NegativePaymentSumException, + TooHighPaymentSumException,}; +use JetBrains\PhpStorm\{ + ArrayShape, + Pure}; /** * Класс, описывающий оплату @@ -41,9 +43,9 @@ class Payment extends Entity * * @param int $type Тип оплаты * @param float $sum Сумма оплаты - * @throws InvalidEnumValueException * @throws NegativePaymentSumException * @throws TooHighPaymentSumException + * @throws InvalidEnumValueException */ public function __construct(int $type, float $sum) { diff --git a/src/Exceptions/AtolException.php b/src/Exceptions/AtolException.php index 6b86648..6a7f34e 100644 --- a/src/Exceptions/AtolException.php +++ b/src/Exceptions/AtolException.php @@ -33,7 +33,7 @@ class AtolException extends Exception { $tags = implode(', ', $ffd_tags ?: $this->ffd_tags); parent::__construct( - ($message ?: $this->message) . ($tags ? ' [Теги ФФД: ' . $tags : '') . ']' + ($message ?: $this->message) . ($tags ? ' [Теги ФФД: ' . $tags . ']' : '') ); } } diff --git a/src/Exceptions/InvalidEntityInCollectionException.php b/src/Exceptions/InvalidEntityInCollectionException.php new file mode 100644 index 0000000..f58cd2c --- /dev/null +++ b/src/Exceptions/InvalidEntityInCollectionException.php @@ -0,0 +1,37 @@ +assertIsArray($entity->jsonSerialize()); $this->assertIsString((string)$entity); @@ -204,7 +208,7 @@ class BasicTestCase extends TestCase /** * Провайдер строк, которые приводятся к null * - * @return array> + * @return array */ public function providerNullableStrings(): array { diff --git a/tests/AtolOnline/Tests/Collections/ItemsTest.php b/tests/AtolOnline/Tests/Collections/ItemsTest.php new file mode 100644 index 0000000..7289f6e --- /dev/null +++ b/tests/AtolOnline/Tests/Collections/ItemsTest.php @@ -0,0 +1,156 @@ +expectException(TooManyItemsException::class); + new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS + 1)); + } + + /** + * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции + * + * @covers \AtolOnline\Collections\EntityCollection::prepend + * @covers \AtolOnline\Collections\EntityCollection::checkCount + * @covers \AtolOnline\Exceptions\TooManyItemsException + * @throws EmptyItemNameException + * @throws NegativeItemPriceException + * @throws NegativeItemQuantityException + * @throws TooHighItemPriceException + * @throws TooLongItemNameException + * @throws TooManyException + */ + public function testTooManyItemsExceptionByPrepend() + { + $this->expectException(TooManyItemsException::class); + (new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS))) + ->prepend($this->generateObjects()); + } + + /** + * Тестирует выброс исключения при добавлении лишней ставки в конец коллекции + * + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::add + * @covers \AtolOnline\Collections\EntityCollection::checkCount + * @covers \AtolOnline\Exceptions\TooManyItemsException + * @throws EmptyItemNameException + * @throws NegativeItemPriceException + * @throws NegativeItemQuantityException + * @throws TooHighItemPriceException + * @throws TooLongItemNameException + * @throws TooManyException + */ + public function testTooManyItemsExceptionByAdd() + { + $this->expectException(TooManyItemsException::class); + (new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS))) + ->add($this->generateObjects()); + } + + /** + * Тестирует выброс исключения при добавлении лишних оплат в конец коллекции + * + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::push + * @covers \AtolOnline\Collections\EntityCollection::checkCount + * @covers \AtolOnline\Exceptions\TooManyItemsException + * @throws EmptyItemNameException + * @throws NegativeItemPriceException + * @throws NegativeItemQuantityException + * @throws TooHighItemPriceException + * @throws TooLongItemNameException + * @throws TooManyException + */ + public function testTooManyItemsExceptionByPush() + { + $this->expectException(TooManyItemsException::class); + (new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS))) + ->push(...$this->generateObjects()); + } + + /** + * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции + * + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::merge + * @covers \AtolOnline\Collections\EntityCollection::checkCount + * @covers \AtolOnline\Exceptions\TooManyItemsException + * @throws EmptyItemNameException + * @throws NegativeItemPriceException + * @throws NegativeItemQuantityException + * @throws TooHighItemPriceException + * @throws TooLongItemNameException + * @throws TooManyException + */ + public function testTooManyItemsExceptionByMerge() + { + $this->expectException(TooManyItemsException::class); + (new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS))) + ->merge($this->generateObjects(2)); + } + + /** + * Генерирует массив тестовых объектов предметов расчёта + * + * @param int $count + * @return Item[] + * @throws EmptyItemNameException + * @throws NegativeItemPriceException + * @throws NegativeItemQuantityException + * @throws TooHighItemPriceException + * @throws TooLongItemNameException + * @throws TooManyException + * @throws Exception + */ + protected function generateObjects(int $count = 1): array + { + $result = []; + for ($i = 0; $i < abs($count); ++$i) { + $result[] = new Item(Helpers::randomStr(), random_int(1, 100), random_int(1, 10)); + } + return $result; + } +} diff --git a/tests/AtolOnline/Tests/Entities/PaymentsTest.php b/tests/AtolOnline/Tests/Collections/PaymentsTest.php similarity index 76% rename from tests/AtolOnline/Tests/Entities/PaymentsTest.php rename to tests/AtolOnline/Tests/Collections/PaymentsTest.php index 7e71a8f..a10d679 100644 --- a/tests/AtolOnline/Tests/Entities/PaymentsTest.php +++ b/tests/AtolOnline/Tests/Collections/PaymentsTest.php @@ -7,12 +7,12 @@ * https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE */ -namespace AtolOnline\Tests\Entities; +namespace AtolOnline\Tests\Collections; use AtolOnline\{ + Collections\Payments, Constants\Constraints, Entities\Payment, - Entities\Payments, Enums\PaymentTypes, Exceptions\InvalidEnumValueException, Exceptions\NegativePaymentSumException, @@ -29,8 +29,8 @@ class PaymentsTest extends BasicTestCase /** * Тестирует выброс исключения при установке слишком большого количества оплат через конструктор * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyPaymentsException * @throws InvalidEnumValueException * @throws NegativePaymentSumException @@ -45,8 +45,8 @@ class PaymentsTest extends BasicTestCase /** * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции * - * @covers \AtolOnline\Entities\EntityCollection::prepend - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection::prepend + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyPaymentsException * @throws InvalidEnumValueException * @throws NegativePaymentSumException @@ -55,16 +55,16 @@ class PaymentsTest extends BasicTestCase public function testTooManyPaymentsExceptionByPrepend() { $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generateObjects(10))) + (new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS))) ->prepend($this->generateObjects()); } /** * Тестирует выброс исключения при добавлении лишней ставки в конец коллекции * - * @covers \AtolOnline\Entities\Payments - * @covers \AtolOnline\Entities\Payments::add - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::add + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyPaymentsException * @throws InvalidEnumValueException * @throws NegativePaymentSumException @@ -73,16 +73,16 @@ class PaymentsTest extends BasicTestCase public function testTooManyPaymentsExceptionByAdd() { $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generateObjects(10))) + (new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS))) ->add($this->generateObjects()); } /** * Тестирует выброс исключения при добавлении лишних оплат в конец коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::push - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::push + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyPaymentsException * @throws InvalidEnumValueException * @throws NegativePaymentSumException @@ -91,16 +91,16 @@ class PaymentsTest extends BasicTestCase public function testTooManyPaymentsExceptionByPush() { $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generateObjects(10))) + (new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1))) ->push(...$this->generateObjects()); } /** * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::merge - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::merge + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyPaymentsException * @throws InvalidEnumValueException * @throws NegativePaymentSumException @@ -109,13 +109,15 @@ class PaymentsTest extends BasicTestCase public function testTooManyPaymentsExceptionByMerge() { $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generateObjects(9))) + (new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS - 1))) ->merge($this->generateObjects(2)); } /** * Генерирует массив тестовых объектов оплаты * + * @param int $count + * @return Payment[] * @throws InvalidEnumValueException * @throws NegativePaymentSumException * @throws TooHighPaymentSumException diff --git a/tests/AtolOnline/Tests/Entities/VatsTest.php b/tests/AtolOnline/Tests/Collections/VatsTest.php similarity index 59% rename from tests/AtolOnline/Tests/Entities/VatsTest.php rename to tests/AtolOnline/Tests/Collections/VatsTest.php index 516df86..288fe61 100644 --- a/tests/AtolOnline/Tests/Entities/VatsTest.php +++ b/tests/AtolOnline/Tests/Collections/VatsTest.php @@ -7,14 +7,19 @@ * https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE */ -namespace AtolOnline\Tests\Entities; +namespace AtolOnline\Tests\Collections; use AtolOnline\{ + Collections\Vats, Constants\Constraints, + Entities\Payment, Entities\Vat, - Entities\Vats, + Enums\PaymentTypes, Enums\VatTypes, + Exceptions\InvalidEntityInCollectionException, Exceptions\InvalidEnumValueException, + Exceptions\NegativePaymentSumException, + Exceptions\TooHighPaymentSumException, Exceptions\TooManyVatsException, Tests\BasicTestCase}; use Exception; @@ -27,22 +32,24 @@ class VatsTest extends BasicTestCase /** * Тестирует создание коллекции ставок * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException + * @throws Exception */ public function testConstructor() { $vats = new Vats($this->generateObjects(3)); $this->assertIsCollection($vats); $this->assertEquals(3, $vats->count()); + $this->assertAtolable($vats); } /** * Тестирует выброс исключения при установке слишком большого количества ставок через конструктор * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyVatsException * @throws InvalidEnumValueException */ @@ -55,9 +62,9 @@ class VatsTest extends BasicTestCase /** * Тестирует добавление ставки в начало коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::prepend - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::prepend + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException */ public function testPrepend() @@ -70,25 +77,25 @@ class VatsTest extends BasicTestCase /** * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::prepend - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::prepend + * @covers \AtolOnline\Collections\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))) + (new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS))) ->prepend($this->generateObjects()); } /** * Тестирует добавление ставки в конец коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::add - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::add + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException */ public function testAdd() @@ -101,25 +108,25 @@ class VatsTest extends BasicTestCase /** * Тестирует выброс исключения при добавлении лишней ставки в конец коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::add - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::add + * @covers \AtolOnline\Collections\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))) + (new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS))) ->add($this->generateObjects()); } /** * Тестирует добавление лишних ставок в конец коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::push - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::push + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException */ public function testPush() @@ -132,25 +139,25 @@ class VatsTest extends BasicTestCase /** * Тестирует выброс исключения при добавлении лишних ставок в конец коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::push - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::push + * @covers \AtolOnline\Collections\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))) + (new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS))) ->push(...$this->generateObjects()); } /** * Тестирует добавление ставки в начало коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::merge - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::merge + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException */ public function testMerge() @@ -163,22 +170,60 @@ class VatsTest extends BasicTestCase /** * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции * - * @covers \AtolOnline\Entities\EntityCollection - * @covers \AtolOnline\Entities\EntityCollection::merge - * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::merge + * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyVatsException * @throws InvalidEnumValueException */ public function testTooManyVatsExceptionByMerge() { $this->expectException(TooManyVatsException::class); - (new Vats($this->generateObjects(9))) + (new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS - 1))) ->merge($this->generateObjects(2)); } + /** + * Тестирует выброс исключения при наличии скаляров в коллекции + * + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::checkClass + * @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'"); + (new Vats($this->generateObjects(2))) + ->merge('bad element') + ->jsonSerialize(); + } + + /** + * Тестирует выброс исключения при наличии объектов не тех классов в коллекции + * + * @throws InvalidEnumValueException + * @throws NegativePaymentSumException + * @throws TooHighPaymentSumException + * @throws Exception + */ + public function testInvalidCollectionItemExceptionObject(): void + { + $this->expectException(InvalidEntityInCollectionException::class); + $this->expectExceptionMessage(Payment::class); + (new Vats($this->generateObjects())) + ->merge([new Payment(PaymentTypes::PREPAID, 1)]) + ->jsonSerialize(); + } + /** * Генерирует массив тестовых объектов ставок НДС * + * @param int $count + * @return Vat[] * @throws InvalidEnumValueException * @throws Exception */ diff --git a/tests/AtolOnline/Tests/Entities/AgentInfoTest.php b/tests/AtolOnline/Tests/Entities/AgentInfoTest.php index 5cb76f1..5ee5a65 100644 --- a/tests/AtolOnline/Tests/Entities/AgentInfoTest.php +++ b/tests/AtolOnline/Tests/Entities/AgentInfoTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/ClientTest.php b/tests/AtolOnline/Tests/Entities/ClientTest.php index b498433..a8b55ff 100644 --- a/tests/AtolOnline/Tests/Entities/ClientTest.php +++ b/tests/AtolOnline/Tests/Entities/ClientTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/CompanyTest.php b/tests/AtolOnline/Tests/Entities/CompanyTest.php index 2ed59ef..1012cd3 100644 --- a/tests/AtolOnline/Tests/Entities/CompanyTest.php +++ b/tests/AtolOnline/Tests/Entities/CompanyTest.php @@ -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() { diff --git a/tests/AtolOnline/Tests/Entities/CorrectionInfoTest.php b/tests/AtolOnline/Tests/Entities/CorrectionInfoTest.php index 30ad629..e01cde6 100644 --- a/tests/AtolOnline/Tests/Entities/CorrectionInfoTest.php +++ b/tests/AtolOnline/Tests/Entities/CorrectionInfoTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/ItemTest.php b/tests/AtolOnline/Tests/Entities/ItemTest.php index f55aa2e..35dc71e 100644 --- a/tests/AtolOnline/Tests/Entities/ItemTest.php +++ b/tests/AtolOnline/Tests/Entities/ItemTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/MoneyTransferOperatorTest.php b/tests/AtolOnline/Tests/Entities/MoneyTransferOperatorTest.php index bf6560a..1416bfd 100644 --- a/tests/AtolOnline/Tests/Entities/MoneyTransferOperatorTest.php +++ b/tests/AtolOnline/Tests/Entities/MoneyTransferOperatorTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/PayingAgentTest.php b/tests/AtolOnline/Tests/Entities/PayingAgentTest.php index 0967ff0..6e194e6 100644 --- a/tests/AtolOnline/Tests/Entities/PayingAgentTest.php +++ b/tests/AtolOnline/Tests/Entities/PayingAgentTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/PaymentTest.php b/tests/AtolOnline/Tests/Entities/PaymentTest.php index 1bc2fa7..db1368b 100644 --- a/tests/AtolOnline/Tests/Entities/PaymentTest.php +++ b/tests/AtolOnline/Tests/Entities/PaymentTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/ReceivePaymentsOperatorTest.php b/tests/AtolOnline/Tests/Entities/ReceivePaymentsOperatorTest.php index ffe501e..b2b38af 100644 --- a/tests/AtolOnline/Tests/Entities/ReceivePaymentsOperatorTest.php +++ b/tests/AtolOnline/Tests/Entities/ReceivePaymentsOperatorTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/SupplierTest.php b/tests/AtolOnline/Tests/Entities/SupplierTest.php index 57fb253..b24d670 100644 --- a/tests/AtolOnline/Tests/Entities/SupplierTest.php +++ b/tests/AtolOnline/Tests/Entities/SupplierTest.php @@ -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 { diff --git a/tests/AtolOnline/Tests/Entities/VatTest.php b/tests/AtolOnline/Tests/Entities/VatTest.php index d1b1ab0..40a2568 100644 --- a/tests/AtolOnline/Tests/Entities/VatTest.php +++ b/tests/AtolOnline/Tests/Entities/VatTest.php @@ -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 {