2021-12-03 15:53:42 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-12-03 15:53:42 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace AtolOnline\Tests\Entities;
|
|
|
|
|
|
|
|
|
|
use AtolOnline\{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
Constraints,
|
2021-12-03 15:53:42 +00:00
|
|
|
|
Entities\Payment,
|
2022-12-14 16:19:55 +00:00
|
|
|
|
Enums\PaymentType,
|
2021-12-06 08:14:19 +00:00
|
|
|
|
Tests\BasicTestCase};
|
2021-12-03 15:53:42 +00:00
|
|
|
|
use AtolOnline\Exceptions\{
|
|
|
|
|
NegativePaymentSumException,
|
2021-12-06 08:14:19 +00:00
|
|
|
|
TooHighPaymentSumException,};
|
|
|
|
|
use Exception;
|
2021-12-03 15:53:42 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Набор тестов для проверки работы класса оплаты
|
|
|
|
|
*/
|
|
|
|
|
class PaymentTest extends BasicTestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует конструктор
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment::setType
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment::getType
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment::setSum
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment::getSum
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment::jsonSerialize
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws NegativePaymentSumException
|
|
|
|
|
* @throws TooHighPaymentSumException
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @throws Exception
|
2021-12-03 15:53:42 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructor(): void
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable(
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new Payment(PaymentType::ELECTRON, 123.456789),
|
2021-12-03 15:53:42 +00:00
|
|
|
|
[
|
2022-12-14 16:19:55 +00:00
|
|
|
|
'type' => PaymentType::ELECTRON,
|
2021-12-03 15:53:42 +00:00
|
|
|
|
'sum' => 123.46,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при слишком большой сумме
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment::setSum
|
|
|
|
|
* @covers \AtolOnline\Exceptions\TooHighPaymentSumException
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws NegativePaymentSumException
|
|
|
|
|
*/
|
|
|
|
|
public function testTooHighPaymentSumException(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(TooHighPaymentSumException::class);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new Payment(PaymentType::ELECTRON, Constraints::MAX_COUNT_PAYMENT_SUM + 1);
|
2021-12-03 15:53:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение при отрицательной сумме
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment
|
|
|
|
|
* @covers \AtolOnline\Entities\Payment::setSum
|
|
|
|
|
* @covers \AtolOnline\Exceptions\NegativePaymentSumException
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws NegativePaymentSumException
|
|
|
|
|
* @throws TooHighPaymentSumException
|
|
|
|
|
*/
|
|
|
|
|
public function testNegativePaymentSumException(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(NegativePaymentSumException::class);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new Payment(PaymentType::ELECTRON, -1);
|
2021-12-03 15:53:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|