From a34a6927d17495741e65e1427ed567ac1158b867 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Tue, 7 Dec 2021 20:04:03 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3=20=D0=BF=D0=BE=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `BasicTestCase::assertAtolable() => assertIsAtolable()` - генерация тестовых объектов `Vat`, `Payment` и `Item` вынесены в `BasicTestCase` --- src/Api/KktMonitor.php | 1 - src/Collections/EntityCollection.php | 24 +++-- tests/AtolOnline/Tests/Api/KktMonitorTest.php | 2 +- tests/AtolOnline/Tests/BasicTestCase.php | 98 ++++++++++++++++++- .../Tests/Collections/ItemsTest.php | 51 +++------- .../Tests/Collections/PaymentsTest.php | 50 +++------- .../AtolOnline/Tests/Collections/VatsTest.php | 76 ++++++-------- .../Entities/AdditionalUserPropsTest.php | 2 +- .../Tests/Entities/AgentInfoTest.php | 16 +-- .../AtolOnline/Tests/Entities/ClientTest.php | 12 +-- .../AtolOnline/Tests/Entities/CompanyTest.php | 2 +- .../Tests/Entities/CorrectionInfoTest.php | 2 +- tests/AtolOnline/Tests/Entities/ItemTest.php | 20 ++-- .../Tests/Entities/KktEntityTest.php | 2 +- .../Entities/MoneyTransferOperatorTest.php | 10 +- .../Tests/Entities/PayingAgentTest.php | 6 +- .../AtolOnline/Tests/Entities/PaymentTest.php | 2 +- .../Entities/ReceivePaymentsOperatorTest.php | 2 +- .../Tests/Entities/SupplierTest.php | 8 +- tests/AtolOnline/Tests/Entities/VatTest.php | 2 +- 20 files changed, 220 insertions(+), 168 deletions(-) diff --git a/src/Api/KktMonitor.php b/src/Api/KktMonitor.php index 1e63643..e43f43c 100644 --- a/src/Api/KktMonitor.php +++ b/src/Api/KktMonitor.php @@ -100,7 +100,6 @@ class KktMonitor extends AtolClient /** * Возвращает информацию о конкретной ККТ по её серийному номеру * - * @todo кастовать к отдельному классу со своими геттерами * @param string $serial_number * @return Kkt * @throws GuzzleException diff --git a/src/Collections/EntityCollection.php b/src/Collections/EntityCollection.php index 74e4c77..fc80b97 100644 --- a/src/Collections/EntityCollection.php +++ b/src/Collections/EntityCollection.php @@ -22,10 +22,12 @@ abstract class EntityCollection extends Collection { /** * @inheritDoc + * @throws InvalidEntityInCollectionException */ public function __construct($items = []) { $this->checkCount($items); + $this->checkItemsClasses($items); parent::__construct($items); } @@ -71,19 +73,17 @@ abstract class EntityCollection extends Collection */ public function jsonSerialize(): array { - $this->each(function ($item) { - $this->checkClass($item); - }); + $this->checkItemsClasses(); return parent::jsonSerialize(); } /** - * Проверяет количество ставок + * Проверяет количество элементов коллекции * * @param array $items Массив элементов, если пустой - проверит содержимое коллекции * @return void */ - private function checkCount(array $items = []): void + public function checkCount(array $items = []): void { if (count($items) > static::MAX_COUNT || $this->count() === static::MAX_COUNT) { throw new (static::EXCEPTION_CLASS)(static::MAX_COUNT); @@ -91,14 +91,24 @@ abstract class EntityCollection extends Collection } /** - * Проверяет корректность класса объекта + * Проверяет корректность класса элемента коллекции * * @throws InvalidEntityInCollectionException */ - private function checkClass(mixed $item): void + public function checkItemClass(mixed $item): void { if (!is_object($item) || $item::class !== static::ENTITY_CLASS) { throw new InvalidEntityInCollectionException(static::class, static::ENTITY_CLASS, $item); } } + + /** + * Проверяет корректность классов элементов коллекции + * + * @throws InvalidEntityInCollectionException + */ + public function checkItemsClasses(array $items = []): void + { + (empty($items) ? $this : collect($items))->each(fn ($item) => $this->checkItemClass($item)); + } } diff --git a/tests/AtolOnline/Tests/Api/KktMonitorTest.php b/tests/AtolOnline/Tests/Api/KktMonitorTest.php index 502432b..34ccb7f 100644 --- a/tests/AtolOnline/Tests/Api/KktMonitorTest.php +++ b/tests/AtolOnline/Tests/Api/KktMonitorTest.php @@ -339,7 +339,7 @@ class KktMonitorTest extends BasicTestCase $kkt = $client->getOne($serial_number); $this->assertNotEmpty($client->getResponse()); $this->assertIsSameClass(Kkt::class, $kkt); - $this->assertAtolable($kkt); + $this->assertIsAtolable($kkt); $this->assertNotNull($kkt->serialNumber); $this->assertEquals($serial_number, $kkt->serialNumber); } diff --git a/tests/AtolOnline/Tests/BasicTestCase.php b/tests/AtolOnline/Tests/BasicTestCase.php index 9a32546..8c6aacf 100644 --- a/tests/AtolOnline/Tests/BasicTestCase.php +++ b/tests/AtolOnline/Tests/BasicTestCase.php @@ -13,6 +13,20 @@ namespace AtolOnline\Tests; use AtolOnline\Collections\EntityCollection; use AtolOnline\Entities\Entity; +use AtolOnline\Entities\Item; +use AtolOnline\Entities\Payment; +use AtolOnline\Entities\Vat; +use AtolOnline\Enums\PaymentTypes; +use AtolOnline\Enums\VatTypes; +use AtolOnline\Exceptions\EmptyItemNameException; +use AtolOnline\Exceptions\InvalidEnumValueException; +use AtolOnline\Exceptions\NegativeItemPriceException; +use AtolOnline\Exceptions\NegativeItemQuantityException; +use AtolOnline\Exceptions\NegativePaymentSumException; +use AtolOnline\Exceptions\TooHighItemPriceException; +use AtolOnline\Exceptions\TooHighPaymentSumException; +use AtolOnline\Exceptions\TooLongItemNameException; +use AtolOnline\Exceptions\TooManyException; use AtolOnline\Helpers; use Exception; use GuzzleHttp\Client; @@ -25,6 +39,10 @@ use PHPUnit\Framework\TestCase; */ class BasicTestCase extends TestCase { + //------------------------------------------------------------------------------------------------------------------ + // Методы для управления тестами, использующими тестовый АТОЛ API + //------------------------------------------------------------------------------------------------------------------ + /** * Проверяет наличие подключения к ресурсу по URL * @@ -65,6 +83,10 @@ class BasicTestCase extends TestCase } } + //------------------------------------------------------------------------------------------------------------------ + // Дополнительные ассерты + //------------------------------------------------------------------------------------------------------------------ + /** * Тестирует является ли объект приводимым к json-строке согласно схеме АТОЛ Онлайн * @@ -75,7 +97,7 @@ class BasicTestCase extends TestCase * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize * @throws Exception */ - public function assertAtolable(Entity|EntityCollection $entity, ?array $json_structure = null): void + public function assertIsAtolable(Entity|EntityCollection $entity, ?array $json_structure = null): void { $this->assertIsArray($entity->jsonSerialize()); $this->assertIsString((string)$entity); @@ -85,6 +107,8 @@ class BasicTestCase extends TestCase } } + //------------------------------------------------------------------------------------------------------------------ + // Ассерты проверки наследования //------------------------------------------------------------------------------------------------------------------ /** @@ -203,6 +227,8 @@ class BasicTestCase extends TestCase ); } + //------------------------------------------------------------------------------------------------------------------ + // Провайдеры данных для прогона тестов //------------------------------------------------------------------------------------------------------------------ /** @@ -288,4 +314,74 @@ class BasicTestCase extends TestCase ['abc.def@mail#archive.com'], ]; } + + //------------------------------------------------------------------------------------------------------------------ + // Генераторы тестовых объектов + //------------------------------------------------------------------------------------------------------------------ + + /** + * Генерирует массив тестовых объектов предметов расчёта + * + * @param int $count + * @return Item[] + * @throws EmptyItemNameException + * @throws NegativeItemPriceException + * @throws NegativeItemQuantityException + * @throws TooHighItemPriceException + * @throws TooLongItemNameException + * @throws TooManyException + * @throws Exception + */ + protected function generateItemObjects(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; + } + + /** + * Генерирует массив тестовых объектов оплаты + * + * @param int $count + * @return Payment[] + * @throws InvalidEnumValueException + * @throws NegativePaymentSumException + * @throws TooHighPaymentSumException + * @throws Exception + */ + protected function generatePaymentObjects(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; + } + + /** + * Генерирует массив тестовых объектов ставок НДС + * + * @param int $count + * @return Vat[] + * @throws InvalidEnumValueException + * @throws Exception + */ + protected function generateVatObjects(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; + } } diff --git a/tests/AtolOnline/Tests/Collections/ItemsTest.php b/tests/AtolOnline/Tests/Collections/ItemsTest.php index 7289f6e..901001b 100644 --- a/tests/AtolOnline/Tests/Collections/ItemsTest.php +++ b/tests/AtolOnline/Tests/Collections/ItemsTest.php @@ -12,18 +12,16 @@ namespace AtolOnline\Tests\Collections; use AtolOnline\{ Collections\Items, Constants\Constraints, - Entities\Item, - Helpers, Tests\BasicTestCase}; use AtolOnline\Exceptions\{ EmptyItemNameException, + InvalidEntityInCollectionException, NegativeItemPriceException, NegativeItemQuantityException, TooHighItemPriceException, TooLongItemNameException, TooManyException, - TooManyItemsException,}; -use Exception; + TooManyItemsException}; /** * Набор тестов для проверки работы класса коллекции предметов расчёта @@ -42,11 +40,12 @@ class ItemsTest extends BasicTestCase * @throws TooHighItemPriceException * @throws TooLongItemNameException * @throws TooManyException + * @throws InvalidEntityInCollectionException */ public function testTooManyItemsExceptionByConstructor() { $this->expectException(TooManyItemsException::class); - new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS + 1)); + new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS + 1)); } /** @@ -61,12 +60,13 @@ class ItemsTest extends BasicTestCase * @throws TooHighItemPriceException * @throws TooLongItemNameException * @throws TooManyException + * @throws InvalidEntityInCollectionException */ public function testTooManyItemsExceptionByPrepend() { $this->expectException(TooManyItemsException::class); - (new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS))) - ->prepend($this->generateObjects()); + (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS))) + ->prepend($this->generateItemObjects()); } /** @@ -82,12 +82,13 @@ class ItemsTest extends BasicTestCase * @throws TooHighItemPriceException * @throws TooLongItemNameException * @throws TooManyException + * @throws InvalidEntityInCollectionException */ public function testTooManyItemsExceptionByAdd() { $this->expectException(TooManyItemsException::class); - (new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS))) - ->add($this->generateObjects()); + (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS))) + ->add($this->generateItemObjects()); } /** @@ -103,12 +104,13 @@ class ItemsTest extends BasicTestCase * @throws TooHighItemPriceException * @throws TooLongItemNameException * @throws TooManyException + * @throws InvalidEntityInCollectionException */ public function testTooManyItemsExceptionByPush() { $this->expectException(TooManyItemsException::class); - (new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS))) - ->push(...$this->generateObjects()); + (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS))) + ->push(...$this->generateItemObjects()); } /** @@ -124,33 +126,12 @@ class ItemsTest extends BasicTestCase * @throws TooHighItemPriceException * @throws TooLongItemNameException * @throws TooManyException + * @throws InvalidEntityInCollectionException */ 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; + (new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS))) + ->merge($this->generateItemObjects(2)); } } diff --git a/tests/AtolOnline/Tests/Collections/PaymentsTest.php b/tests/AtolOnline/Tests/Collections/PaymentsTest.php index a10d679..94882ae 100644 --- a/tests/AtolOnline/Tests/Collections/PaymentsTest.php +++ b/tests/AtolOnline/Tests/Collections/PaymentsTest.php @@ -12,14 +12,12 @@ namespace AtolOnline\Tests\Collections; use AtolOnline\{ Collections\Payments, Constants\Constraints, - Entities\Payment, - Enums\PaymentTypes, + Exceptions\InvalidEntityInCollectionException, Exceptions\InvalidEnumValueException, Exceptions\NegativePaymentSumException, Exceptions\TooHighPaymentSumException, Exceptions\TooManyPaymentsException, Tests\BasicTestCase}; -use Exception; /** * Набор тестов для проверки работы класса коллекции оплат @@ -35,11 +33,12 @@ class PaymentsTest extends BasicTestCase * @throws InvalidEnumValueException * @throws NegativePaymentSumException * @throws TooHighPaymentSumException + * @throws InvalidEntityInCollectionException */ public function testTooManyPaymentsExceptionByConstructor() { $this->expectException(TooManyPaymentsException::class); - new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1)); + new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1)); } /** @@ -51,12 +50,13 @@ class PaymentsTest extends BasicTestCase * @throws InvalidEnumValueException * @throws NegativePaymentSumException * @throws TooHighPaymentSumException + * @throws InvalidEntityInCollectionException */ public function testTooManyPaymentsExceptionByPrepend() { $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS))) - ->prepend($this->generateObjects()); + (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS))) + ->prepend($this->generatePaymentObjects()); } /** @@ -69,12 +69,13 @@ class PaymentsTest extends BasicTestCase * @throws InvalidEnumValueException * @throws NegativePaymentSumException * @throws TooHighPaymentSumException + * @throws InvalidEntityInCollectionException */ public function testTooManyPaymentsExceptionByAdd() { $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS))) - ->add($this->generateObjects()); + (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS))) + ->add($this->generatePaymentObjects()); } /** @@ -87,12 +88,13 @@ class PaymentsTest extends BasicTestCase * @throws InvalidEnumValueException * @throws NegativePaymentSumException * @throws TooHighPaymentSumException + * @throws InvalidEntityInCollectionException */ public function testTooManyPaymentsExceptionByPush() { $this->expectException(TooManyPaymentsException::class); - (new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1))) - ->push(...$this->generateObjects()); + (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1))) + ->push(...$this->generatePaymentObjects()); } /** @@ -105,34 +107,12 @@ class PaymentsTest extends BasicTestCase * @throws InvalidEnumValueException * @throws NegativePaymentSumException * @throws TooHighPaymentSumException + * @throws InvalidEntityInCollectionException */ public function testTooManyPaymentsExceptionByMerge() { $this->expectException(TooManyPaymentsException::class); - (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 - * @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; + (new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS - 1))) + ->merge($this->generatePaymentObjects(2)); } } diff --git a/tests/AtolOnline/Tests/Collections/VatsTest.php b/tests/AtolOnline/Tests/Collections/VatsTest.php index 288fe61..7a20a50 100644 --- a/tests/AtolOnline/Tests/Collections/VatsTest.php +++ b/tests/AtolOnline/Tests/Collections/VatsTest.php @@ -13,9 +13,7 @@ use AtolOnline\{ Collections\Vats, Constants\Constraints, Entities\Payment, - Entities\Vat, Enums\PaymentTypes, - Enums\VatTypes, Exceptions\InvalidEntityInCollectionException, Exceptions\InvalidEnumValueException, Exceptions\NegativePaymentSumException, @@ -39,10 +37,10 @@ class VatsTest extends BasicTestCase */ public function testConstructor() { - $vats = new Vats($this->generateObjects(3)); + $vats = new Vats($this->generateVatObjects(3)); $this->assertIsCollection($vats); $this->assertEquals(3, $vats->count()); - $this->assertAtolable($vats); + $this->assertIsAtolable($vats); } /** @@ -52,11 +50,12 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyVatsException * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testTooManyVatsExceptionByConstructor() { $this->expectException(TooManyVatsException::class); - new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS + 1)); + new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS + 1)); } /** @@ -66,11 +65,12 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::prepend * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testPrepend() { - $vats = (new Vats($this->generateObjects(3))) - ->prepend($this->generateObjects()); + $vats = (new Vats($this->generateVatObjects(3))) + ->prepend($this->generateVatObjects()); $this->assertEquals(4, $vats->count()); } @@ -82,12 +82,13 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyVatsException * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testTooManyVatsExceptionByPrepend() { $this->expectException(TooManyVatsException::class); - (new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS))) - ->prepend($this->generateObjects()); + (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS))) + ->prepend($this->generateVatObjects()); } /** @@ -97,11 +98,12 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::add * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testAdd() { - $vats = (new Vats($this->generateObjects(3))) - ->add($this->generateObjects()); + $vats = (new Vats($this->generateVatObjects(3))) + ->add($this->generateVatObjects()); $this->assertEquals(4, $vats->count()); } @@ -113,12 +115,13 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyVatsException * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testTooManyVatsExceptionByAdd() { $this->expectException(TooManyVatsException::class); - (new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS))) - ->add($this->generateObjects()); + (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS))) + ->add($this->generateVatObjects()); } /** @@ -128,11 +131,12 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::push * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testPush() { - $vats = (new Vats($this->generateObjects(3))) - ->push(...$this->generateObjects(3)); + $vats = (new Vats($this->generateVatObjects(3))) + ->push(...$this->generateVatObjects(3)); $this->assertEquals(6, $vats->count()); } @@ -144,12 +148,13 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyVatsException * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testTooManyVatsExceptionByPush() { $this->expectException(TooManyVatsException::class); - (new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS))) - ->push(...$this->generateObjects()); + (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS))) + ->push(...$this->generateVatObjects()); } /** @@ -159,11 +164,12 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::merge * @covers \AtolOnline\Collections\EntityCollection::checkCount * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testMerge() { - $vats = (new Vats($this->generateObjects(3))) - ->merge($this->generateObjects(3)); + $vats = (new Vats($this->generateVatObjects(3))) + ->merge($this->generateVatObjects(3)); $this->assertEquals(6, $vats->count()); } @@ -175,19 +181,20 @@ class VatsTest extends BasicTestCase * @covers \AtolOnline\Collections\EntityCollection::checkCount * @covers \AtolOnline\Exceptions\TooManyVatsException * @throws InvalidEnumValueException + * @throws InvalidEntityInCollectionException */ public function testTooManyVatsExceptionByMerge() { $this->expectException(TooManyVatsException::class); - (new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS - 1))) - ->merge($this->generateObjects(2)); + (new Vats($this->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS - 1))) + ->merge($this->generateVatObjects(2)); } /** * Тестирует выброс исключения при наличии скаляров в коллекции * * @covers \AtolOnline\Collections\EntityCollection - * @covers \AtolOnline\Collections\EntityCollection::checkClass + * @covers \AtolOnline\Collections\EntityCollection::checkItemClass * @covers \AtolOnline\Collections\EntityCollection::jsonSerialize * @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException * @throws InvalidEnumValueException @@ -197,7 +204,7 @@ class VatsTest extends BasicTestCase { $this->expectException(InvalidEntityInCollectionException::class); $this->expectExceptionMessage("(string)'bad element'"); - (new Vats($this->generateObjects(2))) + (new Vats($this->generateVatObjects(2))) ->merge('bad element') ->jsonSerialize(); } @@ -214,29 +221,8 @@ class VatsTest extends BasicTestCase { $this->expectException(InvalidEntityInCollectionException::class); $this->expectExceptionMessage(Payment::class); - (new Vats($this->generateObjects())) + (new Vats($this->generateVatObjects())) ->merge([new Payment(PaymentTypes::PREPAID, 1)]) ->jsonSerialize(); } - - /** - * Генерирует массив тестовых объектов ставок НДС - * - * @param int $count - * @return Vat[] - * @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; - } } diff --git a/tests/AtolOnline/Tests/Entities/AdditionalUserPropsTest.php b/tests/AtolOnline/Tests/Entities/AdditionalUserPropsTest.php index eecae47..8ee0f58 100644 --- a/tests/AtolOnline/Tests/Entities/AdditionalUserPropsTest.php +++ b/tests/AtolOnline/Tests/Entities/AdditionalUserPropsTest.php @@ -38,7 +38,7 @@ class AdditionalUserPropsTest extends BasicTestCase */ public function testConstructor(): void { - $this->assertAtolable( + $this->assertIsAtolable( new AdditionalUserProps('name', 'value'), [ 'name' => 'name', diff --git a/tests/AtolOnline/Tests/Entities/AgentInfoTest.php b/tests/AtolOnline/Tests/Entities/AgentInfoTest.php index 5ee5a65..745890e 100644 --- a/tests/AtolOnline/Tests/Entities/AgentInfoTest.php +++ b/tests/AtolOnline/Tests/Entities/AgentInfoTest.php @@ -36,7 +36,7 @@ class AgentInfoTest extends BasicTestCase */ public function testConstructorWithoutArgs(): void { - $this->assertAtolable(new AgentInfo(), []); + $this->assertIsAtolable(new AgentInfo(), []); } /** @@ -63,20 +63,20 @@ class AgentInfoTest extends BasicTestCase */ public function testConstructorWithArgs(): void { - $this->assertAtolable(new AgentInfo(null), []); - $this->assertAtolable(new AgentInfo(AgentTypes::ANOTHER), ['type' => AgentTypes::ANOTHER]); - $this->assertAtolable(new AgentInfo(pagent: new PayingAgent()), []); - $this->assertAtolable(new AgentInfo(mt_operator: new MoneyTransferOperator()), []); - $this->assertAtolable(new AgentInfo(rp_operator: new ReceivePaymentsOperator()), []); + $this->assertIsAtolable(new AgentInfo(null), []); + $this->assertIsAtolable(new AgentInfo(AgentTypes::ANOTHER), ['type' => AgentTypes::ANOTHER]); + $this->assertIsAtolable(new AgentInfo(pagent: new PayingAgent()), []); + $this->assertIsAtolable(new AgentInfo(mt_operator: new MoneyTransferOperator()), []); + $this->assertIsAtolable(new AgentInfo(rp_operator: new ReceivePaymentsOperator()), []); - $this->assertAtolable(new AgentInfo( + $this->assertIsAtolable(new AgentInfo( AgentTypes::ANOTHER, new PayingAgent(), new ReceivePaymentsOperator(), new MoneyTransferOperator(), ), ['type' => AgentTypes::ANOTHER]); - $this->assertAtolable(new AgentInfo( + $this->assertIsAtolable(new AgentInfo( AgentTypes::ANOTHER, new PayingAgent('test', ['+79518888888']), new ReceivePaymentsOperator(['+79519999999']), diff --git a/tests/AtolOnline/Tests/Entities/ClientTest.php b/tests/AtolOnline/Tests/Entities/ClientTest.php index a8b55ff..25c8976 100644 --- a/tests/AtolOnline/Tests/Entities/ClientTest.php +++ b/tests/AtolOnline/Tests/Entities/ClientTest.php @@ -34,7 +34,7 @@ class ClientTest extends BasicTestCase */ public function testConstructorWithoutArgs(): void { - $this->assertAtolable(new Client(), []); + $this->assertIsAtolable(new Client(), []); } /** @@ -54,11 +54,11 @@ class ClientTest extends BasicTestCase */ public function testConstructorWithArgs(): void { - $this->assertAtolable(new Client('John Doe'), ['name' => 'John Doe']); - $this->assertAtolable(new Client(email: 'john@example.com'), ['email' => 'john@example.com']); - $this->assertAtolable(new Client(phone: '+1/22/99*73s dsdas654 5s6'), ['phone' => '+122997365456']); - $this->assertAtolable(new Client(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']); - $this->assertAtolable(new Client( + $this->assertIsAtolable(new Client('John Doe'), ['name' => 'John Doe']); + $this->assertIsAtolable(new Client(email: 'john@example.com'), ['email' => 'john@example.com']); + $this->assertIsAtolable(new Client(phone: '+1/22/99*73s dsdas654 5s6'), ['phone' => '+122997365456']); + $this->assertIsAtolable(new Client(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']); + $this->assertIsAtolable(new Client( 'John Doe', 'john@example.com', '+1/22/99*73s dsdas654 5s6', // +122997365456 diff --git a/tests/AtolOnline/Tests/Entities/CompanyTest.php b/tests/AtolOnline/Tests/Entities/CompanyTest.php index 1012cd3..862c68e 100644 --- a/tests/AtolOnline/Tests/Entities/CompanyTest.php +++ b/tests/AtolOnline/Tests/Entities/CompanyTest.php @@ -44,7 +44,7 @@ class CompanyTest extends BasicTestCase */ public function testConstructor() { - $this->assertAtolable(new Company( + $this->assertIsAtolable(new Company( $email = 'company@example.com', $sno = SnoTypes::OSN, $inn = '1234567890', diff --git a/tests/AtolOnline/Tests/Entities/CorrectionInfoTest.php b/tests/AtolOnline/Tests/Entities/CorrectionInfoTest.php index e01cde6..3cf7e8d 100644 --- a/tests/AtolOnline/Tests/Entities/CorrectionInfoTest.php +++ b/tests/AtolOnline/Tests/Entities/CorrectionInfoTest.php @@ -43,7 +43,7 @@ class CorrectionInfoTest extends BasicTestCase */ public function testConstructor(): void { - $this->assertAtolable( + $this->assertIsAtolable( new CorrectionInfo(CorrectionTypes::SELF, '01.01.2021', $number = Helpers::randomStr()), [ 'type' => CorrectionTypes::SELF, diff --git a/tests/AtolOnline/Tests/Entities/ItemTest.php b/tests/AtolOnline/Tests/Entities/ItemTest.php index 35dc71e..3be1b50 100644 --- a/tests/AtolOnline/Tests/Entities/ItemTest.php +++ b/tests/AtolOnline/Tests/Entities/ItemTest.php @@ -71,7 +71,7 @@ class ItemTest extends BasicTestCase */ public function testConstructor(): void { - $this->assertAtolable( + $this->assertIsAtolable( new Item('test item', 2, 3), [ 'name' => 'test item', @@ -277,7 +277,7 @@ class ItemTest extends BasicTestCase PaymentObjects::COMMODITY, $item->setPaymentObject(PaymentObjects::COMMODITY)->getPaymentObject() ); - $this->assertAtolable($item, [ + $this->assertIsAtolable($item, [ 'name' => 'test item', 'price' => 2, 'quantity' => 3, @@ -349,7 +349,7 @@ class ItemTest extends BasicTestCase $this->assertIsSameClass(Vat::class, $item->getVat()); $this->assertEquals(VatTypes::VAT20, $item->getVat()->getType()); $this->assertEquals($item->getSum(), $item->getVat()->getSum()); - $this->assertAtolable($item, [ + $this->assertIsAtolable($item, [ 'name' => 'test item', 'price' => 2, 'quantity' => 3, @@ -384,7 +384,7 @@ class ItemTest extends BasicTestCase $this->assertIsSameClass(Vat::class, $item->getVat()); $this->assertEquals(VatTypes::VAT20, $item->getVat()->getType()); $this->assertEquals($item->getSum(), $item->getVat()->getSum()); - $this->assertAtolable($item, [ + $this->assertIsAtolable($item, [ 'name' => 'test item', 'price' => 2, 'quantity' => 3, @@ -472,7 +472,7 @@ class ItemTest extends BasicTestCase ); $item = (new Item('test item', 2, 3))->setSupplier($supplier); $this->assertEquals($supplier, $item->getSupplier()); - $this->assertAtolable($item, [ + $this->assertIsAtolable($item, [ 'name' => 'test item', 'price' => 2, 'quantity' => 3, @@ -502,7 +502,7 @@ class ItemTest extends BasicTestCase */ public function testValidUserdata(): void { - $this->assertAtolable( + $this->assertIsAtolable( (new Item('test item', 2, 3)) ->setUserData($user_data = Helpers::randomStr(Constraints::MAX_LENGTH_USER_DATA)), [ @@ -572,7 +572,7 @@ class ItemTest extends BasicTestCase */ public function testCountryCode(): void { - $this->assertAtolable( + $this->assertIsAtolable( (new Item('test item', 2, 3))->setCountryCode('800'), [ 'name' => 'test item', @@ -620,7 +620,7 @@ class ItemTest extends BasicTestCase */ public function testValidDeclarationNumber(): void { - $this->assertAtolable( + $this->assertIsAtolable( (new Item('test item', 2, 3)) ->setDeclarationNumber($code = Helpers::randomStr()), [ @@ -691,7 +691,7 @@ class ItemTest extends BasicTestCase */ public function testExcise(): void { - $this->assertAtolable( + $this->assertIsAtolable( (new Item('test item', 2, 3))->setExcise(1), [ 'name' => 'test item', @@ -750,7 +750,7 @@ class ItemTest extends BasicTestCase $decoded = hex2bin(str_replace(' ', '', $item->getCodeHex())); $this->assertEquals($decoded, $item->getCode()); - $this->assertAtolable($item, [ + $this->assertIsAtolable($item, [ 'name' => 'test item', 'price' => 2, 'quantity' => 3, diff --git a/tests/AtolOnline/Tests/Entities/KktEntityTest.php b/tests/AtolOnline/Tests/Entities/KktEntityTest.php index 6e6cbba..f27758e 100644 --- a/tests/AtolOnline/Tests/Entities/KktEntityTest.php +++ b/tests/AtolOnline/Tests/Entities/KktEntityTest.php @@ -57,7 +57,7 @@ class KktEntityTest extends BasicTestCase { $kkt = new Kkt((object)$this->sample_data); $this->assertIsSameClass(Kkt::class, $kkt); - $this->assertAtolable($kkt); + $this->assertIsAtolable($kkt); } /** diff --git a/tests/AtolOnline/Tests/Entities/MoneyTransferOperatorTest.php b/tests/AtolOnline/Tests/Entities/MoneyTransferOperatorTest.php index 1416bfd..f077466 100644 --- a/tests/AtolOnline/Tests/Entities/MoneyTransferOperatorTest.php +++ b/tests/AtolOnline/Tests/Entities/MoneyTransferOperatorTest.php @@ -51,11 +51,11 @@ class MoneyTransferOperatorTest extends BasicTestCase */ public function testConstructorWithArgs(): void { - $this->assertAtolable(new MoneyTransferOperator('some name'), ['name' => 'some name']); - $this->assertAtolable(new MoneyTransferOperator(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']); - $this->assertAtolable(new MoneyTransferOperator(address: 'London'), ['address' => 'London']); - $this->assertAtolable(new MoneyTransferOperator(phones: ['+122997365456']), ['phones' => ['+122997365456']]); - $this->assertAtolable(new MoneyTransferOperator( + $this->assertIsAtolable(new MoneyTransferOperator('some name'), ['name' => 'some name']); + $this->assertIsAtolable(new MoneyTransferOperator(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']); + $this->assertIsAtolable(new MoneyTransferOperator(address: 'London'), ['address' => 'London']); + $this->assertIsAtolable(new MoneyTransferOperator(phones: ['+122997365456']), ['phones' => ['+122997365456']]); + $this->assertIsAtolable(new MoneyTransferOperator( 'some name', '+fasd3\qe3fs_=nac99013928czc', 'London', diff --git a/tests/AtolOnline/Tests/Entities/PayingAgentTest.php b/tests/AtolOnline/Tests/Entities/PayingAgentTest.php index 6e194e6..62ed0a4 100644 --- a/tests/AtolOnline/Tests/Entities/PayingAgentTest.php +++ b/tests/AtolOnline/Tests/Entities/PayingAgentTest.php @@ -49,18 +49,18 @@ class PayingAgentTest extends BasicTestCase public function testConstructorWithArgs(): void { $operation = Helpers::randomStr(); - $this->assertAtolable(new PayingAgent( + $this->assertIsAtolable(new PayingAgent( $operation, ['+122997365456'], ), [ 'operation' => $operation, 'phones' => ['+122997365456'], ]); - $this->assertAtolable( + $this->assertIsAtolable( new PayingAgent($operation), ['operation' => $operation] ); - $this->assertAtolable( + $this->assertIsAtolable( new PayingAgent(phones: ['+122997365456']), ['phones' => ['+122997365456']] ); diff --git a/tests/AtolOnline/Tests/Entities/PaymentTest.php b/tests/AtolOnline/Tests/Entities/PaymentTest.php index db1368b..da58d5a 100644 --- a/tests/AtolOnline/Tests/Entities/PaymentTest.php +++ b/tests/AtolOnline/Tests/Entities/PaymentTest.php @@ -42,7 +42,7 @@ class PaymentTest extends BasicTestCase */ public function testConstructor(): void { - $this->assertAtolable( + $this->assertIsAtolable( new Payment(PaymentTypes::ELECTRON, 123.456789), [ 'type' => PaymentTypes::ELECTRON, diff --git a/tests/AtolOnline/Tests/Entities/ReceivePaymentsOperatorTest.php b/tests/AtolOnline/Tests/Entities/ReceivePaymentsOperatorTest.php index b2b38af..8ed134d 100644 --- a/tests/AtolOnline/Tests/Entities/ReceivePaymentsOperatorTest.php +++ b/tests/AtolOnline/Tests/Entities/ReceivePaymentsOperatorTest.php @@ -43,7 +43,7 @@ class ReceivePaymentsOperatorTest extends BasicTestCase */ public function testConstructorWithArgs(): void { - $this->assertAtolable(new ReceivePaymentsOperator(['+122997365456']), ['phones' => ['+122997365456']]); + $this->assertIsAtolable(new ReceivePaymentsOperator(['+122997365456']), ['phones' => ['+122997365456']]); } /** diff --git a/tests/AtolOnline/Tests/Entities/SupplierTest.php b/tests/AtolOnline/Tests/Entities/SupplierTest.php index b24d670..c14720c 100644 --- a/tests/AtolOnline/Tests/Entities/SupplierTest.php +++ b/tests/AtolOnline/Tests/Entities/SupplierTest.php @@ -49,10 +49,10 @@ class SupplierTest extends BasicTestCase */ public function testConstructorWithArgs(): void { - $this->assertAtolable(new Supplier('some name'), ['name' => 'some name']); - $this->assertAtolable(new Supplier(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']); - $this->assertAtolable(new Supplier(phones: ['+122997365456']), ['phones' => ['+122997365456']]); - $this->assertAtolable(new Supplier( + $this->assertIsAtolable(new Supplier('some name'), ['name' => 'some name']); + $this->assertIsAtolable(new Supplier(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']); + $this->assertIsAtolable(new Supplier(phones: ['+122997365456']), ['phones' => ['+122997365456']]); + $this->assertIsAtolable(new Supplier( 'some name', '+fasd3\qe3fs_=nac99013928czc', ['+122997365456'], diff --git a/tests/AtolOnline/Tests/Entities/VatTest.php b/tests/AtolOnline/Tests/Entities/VatTest.php index 40a2568..33d39cd 100644 --- a/tests/AtolOnline/Tests/Entities/VatTest.php +++ b/tests/AtolOnline/Tests/Entities/VatTest.php @@ -76,7 +76,7 @@ class VatTest extends BasicTestCase public function testConstructor(string $type, float $sum): void { $vat = new Vat($type, $sum); - $this->assertAtolable($vat, [ + $this->assertIsAtolable($vat, [ 'type' => $vat->getType(), 'sum' => $vat->getCalculated(), ]);