From 058ce5ed3dc0bb9a07d37f11caf5ee6f81cc865f Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Thu, 9 Dec 2021 20:13:43 +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=B8=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B9,=20=D1=87=D0=B5=D0=BA=D0=B0=20=D0=B8=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `EntityCollection` сильно упрощён, добавлен выброс исключений при пустом содержимом - `Receipt::setItems(), setPayments() и setVats()` получили одинаковые проверки входящих данных - округление в `Vat::setSum()` - доработаны тесты коллекций --- src/Collections/EntityCollection.php | 69 ++------ src/Collections/Items.php | 8 +- src/Collections/Payments.php | 8 +- src/Collections/Vats.php | 8 +- src/Entities/Receipt.php | 30 ++-- src/Entities/Vat.php | 2 +- .../Tests/Collections/ItemsTest.php | 94 ++-------- .../Tests/Collections/PaymentsTest.php | 77 +-------- .../AtolOnline/Tests/Collections/VatsTest.php | 163 +++--------------- .../AtolOnline/Tests/Entities/ReceiptTest.php | 8 +- 10 files changed, 97 insertions(+), 370 deletions(-) diff --git a/src/Collections/EntityCollection.php b/src/Collections/EntityCollection.php index 080cb52..3552583 100644 --- a/src/Collections/EntityCollection.php +++ b/src/Collections/EntityCollection.php @@ -12,7 +12,6 @@ declare(strict_types = 1); namespace AtolOnline\Collections; use AtolOnline\Exceptions\InvalidEntityInCollectionException; -use Exception; use Illuminate\Support\Collection; /** @@ -21,60 +20,12 @@ use Illuminate\Support\Collection; abstract class EntityCollection extends Collection { /** - * @inheritDoc + * @return array * @throws InvalidEntityInCollectionException */ - public function __construct($items = []) - { - $this->checkCount($items); - //TODO следует переделать EntityCollection в обёртку над Collection, - // ибо ломает методы Collection, которые return new static - $this->checkItemsClasses($items); - parent::__construct($items); - } - - /** - * @inheritDoc - */ - public function prepend($value, $key = null): self - { - $this->checkCount(); - return parent::prepend($value, $key); - } - - /** - * @inheritDoc - */ - public function add($item): self - { - $this->checkCount(); - return parent::add($item); - } - - /** - * @inheritDoc - */ - public function push(...$values): self - { - $this->checkCount(); - return parent::push(...$values); - } - - /** - * @inheritDoc - */ - public function merge($items): self - { - $this->checkCount(); - return parent::merge($items); - } - - /** - * @inheritDoc - * @throws Exception - */ public function jsonSerialize(): array { + $this->checkCount(); $this->checkItemsClasses(); return parent::jsonSerialize(); } @@ -82,20 +33,19 @@ abstract class EntityCollection extends Collection /** * Проверяет количество элементов коллекции * - * @param array $items Массив элементов, если пустой - проверит содержимое коллекции * @return void */ - public function checkCount(array $items = []): void + public function checkCount(): void { - //TODO проверять пустоту? - if (count($items) > static::MAX_COUNT || $this->count() === static::MAX_COUNT) { - throw new (static::EXCEPTION_CLASS)(static::MAX_COUNT); - } + $this->isEmpty() && throw new (static::EMPTY_EXCEPTION_CLASS)(); + $this->count() > static::MAX_COUNT && throw new (static::TOO_MANY_EXCEPTION_CLASS)(static::MAX_COUNT); } /** * Проверяет корректность класса элемента коллекции * + * @param mixed $item + * @return void * @throws InvalidEntityInCollectionException */ public function checkItemClass(mixed $item): void @@ -108,10 +58,11 @@ abstract class EntityCollection extends Collection /** * Проверяет корректность классов элементов коллекции * + * @return $this * @throws InvalidEntityInCollectionException */ - public function checkItemsClasses(array $items = []): void + public function checkItemsClasses(): self { - (empty($items) ? $this : collect($items))->each(fn ($item) => $this->checkItemClass($item)); + return $this->each(fn($item) => $this->checkItemClass($item)); } } diff --git a/src/Collections/Items.php b/src/Collections/Items.php index 00e740c..62a1d06 100644 --- a/src/Collections/Items.php +++ b/src/Collections/Items.php @@ -11,6 +11,7 @@ namespace AtolOnline\Collections; use AtolOnline\Constants\Constraints; use AtolOnline\Entities\Item; +use AtolOnline\Exceptions\EmptyItemsException; use AtolOnline\Exceptions\TooManyItemsException; /** @@ -28,8 +29,13 @@ final class Items extends EntityCollection */ protected const MAX_COUNT = Constraints::MAX_COUNT_DOC_ITEMS; + /** + * Класс исключения для выброса при пустой коллекции + */ + protected const EMPTY_EXCEPTION_CLASS = EmptyItemsException::class; + /** * Класс-наследник TooManyException для выброса при превышении количества */ - protected const EXCEPTION_CLASS = TooManyItemsException::class; + protected const TOO_MANY_EXCEPTION_CLASS = TooManyItemsException::class; } diff --git a/src/Collections/Payments.php b/src/Collections/Payments.php index 00ce8b8..229aa26 100644 --- a/src/Collections/Payments.php +++ b/src/Collections/Payments.php @@ -11,6 +11,7 @@ namespace AtolOnline\Collections; use AtolOnline\Constants\Constraints; use AtolOnline\Entities\Payment; +use AtolOnline\Exceptions\EmptyPaymentsException; use AtolOnline\Exceptions\TooManyPaymentsException; /** @@ -28,8 +29,13 @@ final class Payments extends EntityCollection */ protected const MAX_COUNT = Constraints::MAX_COUNT_DOC_PAYMENTS; + /** + * Класс исключения для выброса при пустой коллекции + */ + protected const EMPTY_EXCEPTION_CLASS = EmptyPaymentsException::class; + /** * Класс-наследник TooManyException для выброса при превышении количества */ - protected const EXCEPTION_CLASS = TooManyPaymentsException::class; + protected const TOO_MANY_EXCEPTION_CLASS = TooManyPaymentsException::class; } diff --git a/src/Collections/Vats.php b/src/Collections/Vats.php index 8630568..127bb14 100644 --- a/src/Collections/Vats.php +++ b/src/Collections/Vats.php @@ -11,6 +11,7 @@ namespace AtolOnline\Collections; use AtolOnline\Constants\Constraints; use AtolOnline\Entities\Vat; +use AtolOnline\Exceptions\EmptyVatsException; use AtolOnline\Exceptions\TooManyVatsException; /** @@ -28,8 +29,13 @@ final class Vats extends EntityCollection */ protected const MAX_COUNT = Constraints::MAX_COUNT_DOC_VATS; + /** + * Класс исключения для выброса при пустой коллекции + */ + protected const EMPTY_EXCEPTION_CLASS = EmptyVatsException::class; + /** * Класс-наследник TooManyException для выброса при превышении количества */ - protected const EXCEPTION_CLASS = TooManyVatsException::class; + protected const TOO_MANY_EXCEPTION_CLASS = TooManyVatsException::class; } diff --git a/src/Entities/Receipt.php b/src/Entities/Receipt.php index beb8b68..632d634 100644 --- a/src/Entities/Receipt.php +++ b/src/Entities/Receipt.php @@ -16,8 +16,6 @@ use AtolOnline\Collections\Payments; use AtolOnline\Collections\Vats; use AtolOnline\Constants\Constraints; use AtolOnline\Exceptions\EmptyItemsException; -use AtolOnline\Exceptions\EmptyPaymentsException; -use AtolOnline\Exceptions\EmptyVatsException; use AtolOnline\Exceptions\InvalidEntityInCollectionException; use AtolOnline\Exceptions\TooLongAddCheckPropException; use AtolOnline\Exceptions\TooLongCashierException; @@ -93,7 +91,6 @@ class Receipt extends Entity * @param Items $items * @param Payments $payments * @throws EmptyItemsException - * @throws EmptyPaymentsException * @throws InvalidEntityInCollectionException */ public function __construct(Client $client, Company $company, Items $items, Payments $payments) @@ -211,12 +208,10 @@ class Receipt extends Entity */ public function setItems(Items $items): self { - if ($items->isEmpty()) { - throw new EmptyItemsException(); - } + $items->checkCount(); $items->checkItemsClasses(); $this->items = $items; - $this->getItems()->each(fn ($item) => $this->total += $item->getSum()); + $this->getItems()->each(fn($item) => $this->total += $item->getSum()); $this->total = round($this->total, 2); return $this; } @@ -236,13 +231,12 @@ class Receipt extends Entity * * @param Payments $payments * @return Receipt - * @throws EmptyPaymentsException + * @throws InvalidEntityInCollectionException */ public function setPayments(Payments $payments): self { - if ($payments->isEmpty()) { - throw new EmptyPaymentsException(); - } + $payments->checkCount(); + $payments->checkItemsClasses(); $this->payments = $payments; return $this; } @@ -262,17 +256,15 @@ class Receipt extends Entity * * @param Vats|null $vats * @return Receipt - * @throws EmptyVatsException * @throws Exception */ public function setVats(?Vats $vats): self { - if ($vats->isEmpty()) { - throw new EmptyVatsException(); - } + $vats->checkCount(); + $vats->checkItemsClasses(); $this->vats = $vats; /** @var Vat $vat */ - $this->getVats()->each(fn ($vat) => $vat->setSum($this->getTotal())); + $this->getVats()->each(fn($vat) => $vat->setSum($this->getTotal())); return $this; } @@ -376,13 +368,13 @@ class Receipt extends Entity $json = [ 'client' => $this->getClient(), 'company' => $this->getCompany(), - 'items' => $this->getItems(), + 'items' => $this->getItems()->jsonSerialize(), 'total' => $this->getTotal(), - 'payments' => $this->getPayments(), + 'payments' => $this->getPayments()->jsonSerialize(), ]; $this->getAgentInfo()?->jsonSerialize() && $json['agent_info'] = $this->getAgentInfo(); $this->getSupplier()?->jsonSerialize() && $json['supplier_info'] = $this->getSupplier(); - $this->getVats()?->jsonSerialize() && $json['vats'] = $this->getVats(); + $this->getVats()?->isNotEmpty() && $json['vats'] = $this->getVats(); !is_null($this->getAddCheckProps()) && $json['additional_check_props'] = $this->getAddCheckProps(); !is_null($this->getCashier()) && $json['cashier'] = $this->getCashier(); $this->getAddUserProps()?->jsonSerialize() && $json['additional_user_props'] = $this->getAddUserProps(); diff --git a/src/Entities/Vat.php b/src/Entities/Vat.php index 771380c..5b16069 100644 --- a/src/Entities/Vat.php +++ b/src/Entities/Vat.php @@ -91,7 +91,7 @@ final class Vat extends Entity */ public function setSum(float $rubles): self { - $this->sum = $rubles; + $this->sum = round($rubles, 2); return $this; } diff --git a/tests/AtolOnline/Tests/Collections/ItemsTest.php b/tests/AtolOnline/Tests/Collections/ItemsTest.php index 901001b..6cc9ace 100644 --- a/tests/AtolOnline/Tests/Collections/ItemsTest.php +++ b/tests/AtolOnline/Tests/Collections/ItemsTest.php @@ -15,6 +15,7 @@ use AtolOnline\{ Tests\BasicTestCase}; use AtolOnline\Exceptions\{ EmptyItemNameException, + EmptyItemsException, InvalidEntityInCollectionException, NegativeItemPriceException, NegativeItemQuantityException, @@ -29,10 +30,12 @@ use AtolOnline\Exceptions\{ class ItemsTest extends BasicTestCase { /** - * Тестирует выброс исключения при установке слишком большого количества оплат через конструктор + * Тестирует выброс исключения при установке слишком большого количества предметов расчёта * * @covers \AtolOnline\Collections\EntityCollection * @covers \AtolOnline\Collections\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses + * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize * @covers \AtolOnline\Exceptions\TooManyItemsException * @throws EmptyItemNameException * @throws NegativeItemPriceException @@ -42,96 +45,25 @@ class ItemsTest extends BasicTestCase * @throws TooManyException * @throws InvalidEntityInCollectionException */ - public function testTooManyItemsExceptionByConstructor() + public function testTooManyItemsException() { $this->expectException(TooManyItemsException::class); - new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS + 1)); + (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS + 1)))->jsonSerialize(); } /** - * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции - * - * @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 - * @throws InvalidEntityInCollectionException - */ - public function testTooManyItemsExceptionByPrepend() - { - $this->expectException(TooManyItemsException::class); - (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS))) - ->prepend($this->generateItemObjects()); - } - - /** - * Тестирует выброс исключения при добавлении лишней ставки в конец коллекции + * Тестирует выброс исключения при установке нулевого количества предметов расчёта * * @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 + * @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses + * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize + * @covers \AtolOnline\Exceptions\EmptyItemsException * @throws InvalidEntityInCollectionException */ - public function testTooManyItemsExceptionByAdd() + public function testEmptyItemsException() { - $this->expectException(TooManyItemsException::class); - (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS))) - ->add($this->generateItemObjects()); - } - - /** - * Тестирует выброс исключения при добавлении лишних оплат в конец коллекции - * - * @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 - * @throws InvalidEntityInCollectionException - */ - public function testTooManyItemsExceptionByPush() - { - $this->expectException(TooManyItemsException::class); - (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS))) - ->push(...$this->generateItemObjects()); - } - - /** - * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции - * - * @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 - * @throws InvalidEntityInCollectionException - */ - public function testTooManyItemsExceptionByMerge() - { - $this->expectException(TooManyItemsException::class); - (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS))) - ->merge($this->generateItemObjects(2)); + $this->expectException(EmptyItemsException::class); + (new Items([]))->jsonSerialize(); } } diff --git a/tests/AtolOnline/Tests/Collections/PaymentsTest.php b/tests/AtolOnline/Tests/Collections/PaymentsTest.php index 94882ae..dd1a14e 100644 --- a/tests/AtolOnline/Tests/Collections/PaymentsTest.php +++ b/tests/AtolOnline/Tests/Collections/PaymentsTest.php @@ -12,6 +12,7 @@ namespace AtolOnline\Tests\Collections; use AtolOnline\{ Collections\Payments, Constants\Constraints, + Exceptions\EmptyPaymentsException, Exceptions\InvalidEntityInCollectionException, Exceptions\InvalidEnumValueException, Exceptions\NegativePaymentSumException, @@ -25,7 +26,7 @@ use AtolOnline\{ class PaymentsTest extends BasicTestCase { /** - * Тестирует выброс исключения при установке слишком большого количества оплат через конструктор + * Тестирует выброс исключения при установке слишком большого количества оплат * * @covers \AtolOnline\Collections\EntityCollection * @covers \AtolOnline\Collections\EntityCollection::checkCount @@ -38,81 +39,21 @@ class PaymentsTest extends BasicTestCase public function testTooManyPaymentsExceptionByConstructor() { $this->expectException(TooManyPaymentsException::class); - new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1)); + (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1)))->jsonSerialize(); } /** - * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции - * - * @covers \AtolOnline\Collections\EntityCollection::prepend - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @covers \AtolOnline\Exceptions\TooManyPaymentsException - * @throws InvalidEnumValueException - * @throws NegativePaymentSumException - * @throws TooHighPaymentSumException - * @throws InvalidEntityInCollectionException - */ - public function testTooManyPaymentsExceptionByPrepend() - { - $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS))) - ->prepend($this->generatePaymentObjects()); - } - - /** - * Тестирует выброс исключения при добавлении лишней ставки в конец коллекции + * Тестирует выброс исключения при установке нулевого количества оплат * * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::add * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @covers \AtolOnline\Exceptions\TooManyPaymentsException - * @throws InvalidEnumValueException - * @throws NegativePaymentSumException - * @throws TooHighPaymentSumException + * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize + * @covers \AtolOnline\Exceptions\EmptyPaymentsException * @throws InvalidEntityInCollectionException */ - public function testTooManyPaymentsExceptionByAdd() + public function testEmptyPaymentsException() { - $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS))) - ->add($this->generatePaymentObjects()); - } - - /** - * Тестирует выброс исключения при добавлении лишних оплат в конец коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::push - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @covers \AtolOnline\Exceptions\TooManyPaymentsException - * @throws InvalidEnumValueException - * @throws NegativePaymentSumException - * @throws TooHighPaymentSumException - * @throws InvalidEntityInCollectionException - */ - public function testTooManyPaymentsExceptionByPush() - { - $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1))) - ->push(...$this->generatePaymentObjects()); - } - - /** - * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::merge - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @covers \AtolOnline\Exceptions\TooManyPaymentsException - * @throws InvalidEnumValueException - * @throws NegativePaymentSumException - * @throws TooHighPaymentSumException - * @throws InvalidEntityInCollectionException - */ - public function testTooManyPaymentsExceptionByMerge() - { - $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS - 1))) - ->merge($this->generatePaymentObjects(2)); + $this->expectException(EmptyPaymentsException::class); + (new Payments([]))->jsonSerialize(); } } diff --git a/tests/AtolOnline/Tests/Collections/VatsTest.php b/tests/AtolOnline/Tests/Collections/VatsTest.php index 7a20a50..cafadc6 100644 --- a/tests/AtolOnline/Tests/Collections/VatsTest.php +++ b/tests/AtolOnline/Tests/Collections/VatsTest.php @@ -14,6 +14,7 @@ use AtolOnline\{ Constants\Constraints, Entities\Payment, Enums\PaymentTypes, + Exceptions\EmptyVatsException, Exceptions\InvalidEntityInCollectionException, Exceptions\InvalidEnumValueException, Exceptions\NegativePaymentSumException, @@ -32,6 +33,8 @@ class VatsTest extends BasicTestCase * * @covers \AtolOnline\Collections\EntityCollection * @covers \AtolOnline\Collections\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses + * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize * @throws InvalidEnumValueException * @throws Exception */ @@ -44,150 +47,36 @@ class VatsTest extends BasicTestCase } /** - * Тестирует выброс исключения при установке слишком большого количества ставок через конструктор + * Тестирует выброс исключения при установке нулевого количества ставок * * @covers \AtolOnline\Collections\EntityCollection * @covers \AtolOnline\Collections\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses + * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize + * @covers \AtolOnline\Exceptions\EmptyVatsException + * @throws InvalidEntityInCollectionException + */ + public function testEmptyVatsException() + { + $this->expectException(EmptyVatsException::class); + (new Vats([]))->jsonSerialize(); + } + + /** + * Тестирует выброс исключения при установке слишком большого количества ставок + * + * @covers \AtolOnline\Collections\EntityCollection + * @covers \AtolOnline\Collections\EntityCollection::checkCount + * @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses + * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize * @covers \AtolOnline\Exceptions\TooManyVatsException * @throws InvalidEnumValueException * @throws InvalidEntityInCollectionException */ - public function testTooManyVatsExceptionByConstructor() + public function testTooManyVatsException() { $this->expectException(TooManyVatsException::class); - new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS + 1)); - } - - /** - * Тестирует добавление ставки в начало коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::prepend - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @throws InvalidEnumValueException - * @throws InvalidEntityInCollectionException - */ - public function testPrepend() - { - $vats = (new Vats($this->generateVatObjects(3))) - ->prepend($this->generateVatObjects()); - $this->assertEquals(4, $vats->count()); - } - - /** - * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::prepend - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @covers \AtolOnline\Exceptions\TooManyVatsException - * @throws InvalidEnumValueException - * @throws InvalidEntityInCollectionException - */ - public function testTooManyVatsExceptionByPrepend() - { - $this->expectException(TooManyVatsException::class); - (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS))) - ->prepend($this->generateVatObjects()); - } - - /** - * Тестирует добавление ставки в конец коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::add - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @throws InvalidEnumValueException - * @throws InvalidEntityInCollectionException - */ - public function testAdd() - { - $vats = (new Vats($this->generateVatObjects(3))) - ->add($this->generateVatObjects()); - $this->assertEquals(4, $vats->count()); - } - - /** - * Тестирует выброс исключения при добавлении лишней ставки в конец коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::add - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @covers \AtolOnline\Exceptions\TooManyVatsException - * @throws InvalidEnumValueException - * @throws InvalidEntityInCollectionException - */ - public function testTooManyVatsExceptionByAdd() - { - $this->expectException(TooManyVatsException::class); - (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS))) - ->add($this->generateVatObjects()); - } - - /** - * Тестирует добавление лишних ставок в конец коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::push - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @throws InvalidEnumValueException - * @throws InvalidEntityInCollectionException - */ - public function testPush() - { - $vats = (new Vats($this->generateVatObjects(3))) - ->push(...$this->generateVatObjects(3)); - $this->assertEquals(6, $vats->count()); - } - - /** - * Тестирует выброс исключения при добавлении лишних ставок в конец коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::push - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @covers \AtolOnline\Exceptions\TooManyVatsException - * @throws InvalidEnumValueException - * @throws InvalidEntityInCollectionException - */ - public function testTooManyVatsExceptionByPush() - { - $this->expectException(TooManyVatsException::class); - (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS))) - ->push(...$this->generateVatObjects()); - } - - /** - * Тестирует добавление ставки в начало коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::merge - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @throws InvalidEnumValueException - * @throws InvalidEntityInCollectionException - */ - public function testMerge() - { - $vats = (new Vats($this->generateVatObjects(3))) - ->merge($this->generateVatObjects(3)); - $this->assertEquals(6, $vats->count()); - } - - /** - * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции - * - * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::merge - * @covers \AtolOnline\Collections\EntityCollection::checkCount - * @covers \AtolOnline\Exceptions\TooManyVatsException - * @throws InvalidEnumValueException - * @throws InvalidEntityInCollectionException - */ - public function testTooManyVatsExceptionByMerge() - { - $this->expectException(TooManyVatsException::class); - (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS - 1))) - ->merge($this->generateVatObjects(2)); + (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS + 1)))->jsonSerialize(); } /** @@ -195,6 +84,7 @@ class VatsTest extends BasicTestCase * * @covers \AtolOnline\Collections\EntityCollection * @covers \AtolOnline\Collections\EntityCollection::checkItemClass + * @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize * @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException * @throws InvalidEnumValueException @@ -212,6 +102,9 @@ class VatsTest extends BasicTestCase /** * Тестирует выброс исключения при наличии объектов не тех классов в коллекции * + * @covers \AtolOnline\Collections\EntityCollection::checkItemClass + * @covers \AtolOnline\Collections\EntityCollection::checkItemsClasses + * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize * @throws InvalidEnumValueException * @throws NegativePaymentSumException * @throws TooHighPaymentSumException diff --git a/tests/AtolOnline/Tests/Entities/ReceiptTest.php b/tests/AtolOnline/Tests/Entities/ReceiptTest.php index b4cc014..5665af5 100644 --- a/tests/AtolOnline/Tests/Entities/ReceiptTest.php +++ b/tests/AtolOnline/Tests/Entities/ReceiptTest.php @@ -268,7 +268,7 @@ class ReceiptTest extends BasicTestCase { $this->expectException(InvalidEntityInCollectionException::class); $this->expectErrorMessage('Коллекция AtolOnline\Collections\Payments должна содержать объекты AtolOnline\Entities\Payment'); - new Receipt( + (string)new Receipt( new Client('John Doe', 'john@example.com', '+1/22/99*73s dsdas654 5s6', '+fasd3\qe3fs_=nac99013928czc'), new Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'), new Items([new Item('test item', 2, 3)]), @@ -287,7 +287,6 @@ class ReceiptTest extends BasicTestCase * @throws EmptyItemNameException * @throws EmptyItemsException * @throws EmptyPaymentsException - * @throws EmptyVatsException * @throws InvalidEntityInCollectionException * @throws InvalidEnumValueException * @throws NegativeItemPriceException @@ -297,6 +296,7 @@ class ReceiptTest extends BasicTestCase * @throws TooHighPaymentSumException * @throws TooLongItemNameException * @throws TooManyException + * @throws Exception */ public function testEmptyVatsException(): void { @@ -316,7 +316,6 @@ class ReceiptTest extends BasicTestCase * @throws EmptyItemNameException * @throws EmptyItemsException * @throws EmptyPaymentsException - * @throws EmptyVatsException * @throws InvalidEntityInCollectionException * @throws InvalidEnumValueException * @throws NegativeItemPriceException @@ -326,12 +325,13 @@ class ReceiptTest extends BasicTestCase * @throws TooHighPaymentSumException * @throws TooLongItemNameException * @throws TooManyException + * @throws Exception */ public function testInvalidVatInCollectionException(): void { $this->expectException(InvalidEntityInCollectionException::class); $this->expectErrorMessage('Коллекция AtolOnline\Collections\Vats должна содержать объекты AtolOnline\Entities\Vat'); - $this->newReceipt()->setVats(new Vats(['qwerty'])); + (string)$this->newReceipt()->setVats(new Vats(['qwerty'])); } /**