From bf09641c8bc99f3c7dd78a4587ecfd034c3e2d75 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Mon, 6 Dec 2021 14:16:58 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BB=D0=B0=D1=81=D1=81=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D0=B8=20=D0=BE=D0=BF=D0=BB?= =?UTF-8?q?=D0=B0=D1=82=20`Payments`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entities/Payments.php | 34 +++++ .../Tests/Entities/PaymentsTest.php | 136 ++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 src/Entities/Payments.php create mode 100644 tests/AtolOnline/Tests/Entities/PaymentsTest.php diff --git a/src/Entities/Payments.php b/src/Entities/Payments.php new file mode 100644 index 0000000..413b20b --- /dev/null +++ b/src/Entities/Payments.php @@ -0,0 +1,34 @@ +expectException(TooManyPaymentsException::class); + new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1)); + } + + /** + * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции + * + * @covers \AtolOnline\Entities\EntityCollection::prepend + * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Exceptions\TooManyPaymentsException + * @throws InvalidEnumValueException + * @throws NegativePaymentSumException + * @throws TooHighPaymentSumException + */ + public function testTooManyPaymentsExceptionByPrepend() + { + $this->expectException(TooManyPaymentsException::class); + (new Payments($this->generateObjects(10))) + ->prepend($this->generateObjects()); + } + + /** + * Тестирует выброс исключения при добавлении лишней ставки в конец коллекции + * + * @covers \AtolOnline\Entities\Payments + * @covers \AtolOnline\Entities\Payments::add + * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Exceptions\TooManyPaymentsException + * @throws InvalidEnumValueException + * @throws NegativePaymentSumException + * @throws TooHighPaymentSumException + */ + public function testTooManyPaymentsExceptionByAdd() + { + $this->expectException(TooManyPaymentsException::class); + (new Payments($this->generateObjects(10))) + ->add($this->generateObjects()); + } + + /** + * Тестирует выброс исключения при добавлении лишних оплат в конец коллекции + * + * @covers \AtolOnline\Entities\EntityCollection + * @covers \AtolOnline\Entities\EntityCollection::push + * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Exceptions\TooManyPaymentsException + * @throws InvalidEnumValueException + * @throws NegativePaymentSumException + * @throws TooHighPaymentSumException + */ + public function testTooManyPaymentsExceptionByPush() + { + $this->expectException(TooManyPaymentsException::class); + (new Payments($this->generateObjects(10))) + ->push(...$this->generateObjects()); + } + + /** + * Тестирует выброс исключения при добавлении лишней ставки в начало коллекции + * + * @covers \AtolOnline\Entities\EntityCollection + * @covers \AtolOnline\Entities\EntityCollection::merge + * @covers \AtolOnline\Entities\EntityCollection::checkCount + * @covers \AtolOnline\Exceptions\TooManyPaymentsException + * @throws InvalidEnumValueException + * @throws NegativePaymentSumException + * @throws TooHighPaymentSumException + */ + public function testTooManyPaymentsExceptionByMerge() + { + $this->expectException(TooManyPaymentsException::class); + (new Payments($this->generateObjects(9))) + ->merge($this->generateObjects(2)); + } + + /** + * Генерирует массив тестовых объектов оплаты + * + * @throws InvalidEnumValueException + * @throws NegativePaymentSumException + * @throws TooHighPaymentSumException + * @throws Exception + */ + protected function generateObjects(int $count = 1): array + { + $types = PaymentTypes::toArray(); + $result = []; + for ($i = 0; $i < abs($count); ++$i) { + $result[] = new Payment( + array_values($types)[random_int(min($types), max($types))], + random_int(1, 100) * 2 / 3 + ); + } + return $result; + } +}