Compare commits

..

No commits in common. "7d0c526663b69a43d1d6e27f48646be70a2f4fd9" and "d533164d1b80988703d403ca7ed4f8a9725b50f8" have entirely different histories.

11 changed files with 159 additions and 362 deletions

View File

@ -147,11 +147,6 @@ final class Constraints
*/ */
const CORRECTION_DATE_FORMAT = 'd.m.Y'; const CORRECTION_DATE_FORMAT = 'd.m.Y';
/**
* Максимальная сумма одной оплаты
*/
const MAX_COUNT_PAYMENT_SUM = 99999.999;
/** /**
* Регулярное выражение для валидации строки ИНН * Регулярное выражение для валидации строки ИНН
* *

View File

@ -25,9 +25,9 @@ use AtolOnline\Exceptions\{
NegativeItemExciseException, NegativeItemExciseException,
NegativeItemPriceException, NegativeItemPriceException,
NegativeItemQuantityException, NegativeItemQuantityException,
TooHighItemPriceException,
TooHighItemQuantityException, TooHighItemQuantityException,
TooHighItemSumException, TooHighPriceException,
TooHighSumException,
TooLongItemCodeException, TooLongItemCodeException,
TooLongItemNameException, TooLongItemNameException,
TooLongMeasurementUnitException, TooLongMeasurementUnitException,
@ -124,7 +124,7 @@ final class Item extends Entity
* @param float|null $price Цена за одну единицу * @param float|null $price Цена за одну единицу
* @param float|null $quantity Количество * @param float|null $quantity Количество
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -184,22 +184,21 @@ final class Item extends Entity
/** /**
* Устанавливает цену в рублях * Устанавливает цену в рублях
* *
* @param float $price * @param float $rubles
* @return $this * @return $this
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooHighItemSumException * @throws TooHighSumException
*/ */
public function setPrice(float $price): self public function setPrice(float $rubles): self
{ {
$price = round($price, 2); if ($rubles > Constraints::MAX_COUNT_ITEM_PRICE) {
if ($price > Constraints::MAX_COUNT_ITEM_PRICE) { throw new TooHighPriceException($this->getName(), $rubles);
throw new TooHighItemPriceException($this->getName(), $price);
} }
if ($price < 0) { if ($rubles < 0) {
throw new NegativeItemPriceException($this->getName(), $price); throw new NegativeItemPriceException($this->getName(), $rubles);
} }
$this->price = $price; $this->price = $rubles;
$this->getVat()?->setSum($this->getSum()); $this->getVat()?->setSum($this->getSum());
return $this; return $this;
} }
@ -221,7 +220,7 @@ final class Item extends Entity
* @return $this * @return $this
* @throws TooHighItemQuantityException * @throws TooHighItemQuantityException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemSumException * @throws TooHighSumException
*/ */
public function setQuantity(float $quantity): self public function setQuantity(float $quantity): self
{ {
@ -241,13 +240,13 @@ final class Item extends Entity
* Возвращает стоимость (цена * количество + акциз) * Возвращает стоимость (цена * количество + акциз)
* *
* @return float * @return float
* @throws TooHighItemSumException * @throws TooHighSumException
*/ */
public function getSum(): float public function getSum(): float
{ {
$sum = $this->getPrice() * $this->getQuantity() + (float)$this->getExcise(); $sum = $this->getPrice() * $this->getQuantity() + (float)$this->getExcise();
if ($sum > Constraints::MAX_COUNT_ITEM_SUM) { if ($sum > Constraints::MAX_COUNT_ITEM_SUM) {
throw new TooHighItemSumException($this->getName(), $sum); throw new TooHighSumException($this->getName(), $sum);
} }
return $sum; return $sum;
} }
@ -387,7 +386,7 @@ final class Item extends Entity
* *
* @param Vat|string|null $vat Объект ставки, одно из значений VatTypes или null для удаления ставки * @param Vat|string|null $vat Объект ставки, одно из значений VatTypes или null для удаления ставки
* @return $this * @return $this
* @throws TooHighItemSumException * @throws TooHighSumException
* @throws InvalidEnumValueException * @throws InvalidEnumValueException
*/ */
public function setVat(Vat|string|null $vat): self public function setVat(Vat|string|null $vat): self
@ -491,7 +490,7 @@ final class Item extends Entity
* @param float|null $excise * @param float|null $excise
* @return Item * @return Item
* @throws NegativeItemExciseException * @throws NegativeItemExciseException
* @throws TooHighItemSumException * @throws TooHighSumException
*/ */
public function setExcise(?float $excise): self public function setExcise(?float $excise): self
{ {
@ -568,7 +567,7 @@ final class Item extends Entity
/** /**
* @inheritDoc * @inheritDoc
* @throws TooHighItemSumException * @throws TooHighSumException
*/ */
public function jsonSerialize(): array public function jsonSerialize(): array
{ {

View File

@ -1,119 +0,0 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
* This code is licensed under MIT.
* Этот код распространяется по лицензии MIT.
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
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;
/**
* Класс, описывающий оплату
*
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 30
*/
class Payment extends Entity
{
/**
* @var int Тип оплаты
*/
protected int $type;
/**
* @var float Сумма оплаты (1031, 1081, 1215, 1216, 1217)
*/
protected float $sum;
/**
* Конструктор
*
* @param int $type Тип оплаты
* @param float $sum Сумма оплаты
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function __construct(int $type, float $sum)
{
$this->setType($type)->setSum($sum);
}
/**
* Возвращает установленный тип оплаты
*
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* Устанавливает тип оплаты
*
* @param int $type
* @return $this
* @throws InvalidEnumValueException
*/
public function setType(int $type): self
{
PaymentTypes::isValid($type) && $this->type = $type;
return $this;
}
/**
* Возвращает установленную сумму оплаты
*
* @return float
*/
public function getSum(): float
{
return $this->sum;
}
/**
* Устанавливает сумму оплаты
*
* @param float $sum
* @return $this
* @throws TooHighPaymentSumException
* @throws NegativePaymentSumException
*/
public function setSum(float $sum): self
{
$sum = round($sum, 2);
if ($sum > Constraints::MAX_COUNT_PAYMENT_SUM) {
throw new TooHighPaymentSumException($sum);
}
if ($sum < 0) {
throw new NegativePaymentSumException($sum);
}
$this->sum = $sum;
return $this;
}
/**
* @inheritDoc
*/
#[Pure]
#[ArrayShape(['type' => 'int', 'sum' => 'float'])]
public function jsonSerialize(): array
{
return [
'type' => $this->getType(),
'sum' => $this->getSum(),
];
}
}

View File

@ -0,0 +1,99 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
* This code is licensed under MIT.
* Этот код распространяется по лицензии MIT.
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
namespace AtolOnline\Entities;
use AtolOnline\Enums\PaymentTypes;
/**
* Класс, описывающий оплату. Тег ФФД - 1031, 1081, 1215, 1216, 1217.
*
* @package AtolOnline\Entities
*/
class todoPayment extends Entity
{
/**
* @var int Тип оплаты
*/
protected int $type;
/**
* @var float Сумма оплаты
*/
protected float $sum;
/**
* todoPayment constructor.
*
* @param int $payment_type Тип оплаты
* @param float $sum Сумма оплаты
*/
public function __construct(int $payment_type = PaymentTypes::ELECTRON, float $sum = 0.0)
{
$this->setType($payment_type);
$this->setSum($sum);
}
/**
* Возвращает тип оплаты. Тег ФФД - 1031, 1081, 1215, 1216, 1217.
*
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* Устанавливает тип оплаты. Тег ФФД - 1031, 1081, 1215, 1216, 1217.
*
* @param int $type
* @return $this
*/
public function setType(int $type): todoPayment
{
$this->type = $type;
return $this;
}
/**
* Возвращает сумму оплаты
*
* @return float
*/
public function getSum(): float
{
return $this->sum;
}
/**
* Устанавливает сумму оплаты
*
* @param float $sum
* @return $this
*/
public function setSum(float $sum): todoPayment
{
$this->sum = $sum;
return $this;
}
/**
* @inheritDoc
*/
public function jsonSerialize()
{
return [
'type' => $this->getType(),
'sum' => $this->getSum(),
];
}
}

View File

@ -1,38 +0,0 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
* This code is licensed under MIT.
* Этот код распространяется по лицензии MIT.
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
namespace AtolOnline\Exceptions;
use AtolOnline\Constants\Ffd105Tags;
/**
* Исключение, возникающее при попытке указать оплате отрицательную сумму
*/
class NegativePaymentSumException extends AtolException
{
protected array $ffd_tags = [
Ffd105Tags::PAYMENT_TYPE_CASH,
Ffd105Tags::PAYMENT_TYPE_CREDIT,
Ffd105Tags::PAYMENT_TYPE_ELECTRON,
Ffd105Tags::PAYMENT_TYPE_PREPAID,
Ffd105Tags::PAYMENT_TYPE_OTHER,
];
/**
* Конструктор
*
* @param float $sum
*/
public function __construct(float $sum)
{
parent::__construct('Размер оплаты не может быть отрицательным: ' . $sum);
}
}

View File

@ -1,31 +0,0 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
* This code is licensed under MIT.
* Этот код распространяется по лицензии MIT.
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
namespace AtolOnline\Exceptions;
use AtolOnline\Constants\Constraints;
use AtolOnline\Constants\Ffd105Tags;
/**
* Исключение, возникающее при попытке установки слишком большой суммы оплаты
*/
class TooHighPaymentSumException extends TooManyException
{
protected $message = 'Слишком высокый размер оплаты';
protected array $ffd_tags = [
Ffd105Tags::PAYMENT_TYPE_CASH,
Ffd105Tags::PAYMENT_TYPE_CREDIT,
Ffd105Tags::PAYMENT_TYPE_ELECTRON,
Ffd105Tags::PAYMENT_TYPE_PREPAID,
Ffd105Tags::PAYMENT_TYPE_OTHER,
];
protected float $max = Constraints::MAX_COUNT_PAYMENT_SUM;
}

View File

@ -15,9 +15,9 @@ use AtolOnline\Constants\Constraints;
use AtolOnline\Constants\Ffd105Tags; use AtolOnline\Constants\Ffd105Tags;
/** /**
* Исключение, возникающее при попытке указать слишком высокую цену (сумму) предмета расчёта * Исключение, возникающее при попытке указать слишком высокую цену (сумму)
*/ */
class TooHighItemPriceException extends TooManyException class TooHighPriceException extends TooManyException
{ {
protected array $ffd_tags = [Ffd105Tags::ITEM_PRICE]; protected array $ffd_tags = [Ffd105Tags::ITEM_PRICE];
protected float $max = Constraints::MAX_COUNT_ITEM_PRICE; protected float $max = Constraints::MAX_COUNT_ITEM_PRICE;

View File

@ -15,12 +15,12 @@ use AtolOnline\Constants\Constraints;
use AtolOnline\Constants\Ffd105Tags; use AtolOnline\Constants\Ffd105Tags;
/** /**
* Исключение, возникающее при попытке получеиня слишком высокой стоимости предмета расчёта * Исключение, возникающее при попытке получеиня слишком высокой стоимости
*/ */
class TooHighItemSumException extends TooManyException class TooHighSumException extends TooManyException
{ {
protected array $ffd_tags = [Ffd105Tags::ITEM_SUM]; protected array $ffd_tags = [Ffd105Tags::ITEM_SUM];
protected float $max = Constraints::MAX_COUNT_ITEM_SUM; protected float $max = Constraints::MAX_COUNT_ITEM_PRICE;
/** /**
* Конструктор * Конструктор

View File

@ -31,9 +31,9 @@ use AtolOnline\{
Exceptions\NegativeItemExciseException, Exceptions\NegativeItemExciseException,
Exceptions\NegativeItemPriceException, Exceptions\NegativeItemPriceException,
Exceptions\NegativeItemQuantityException, Exceptions\NegativeItemQuantityException,
Exceptions\TooHighItemPriceException,
Exceptions\TooHighItemQuantityException, Exceptions\TooHighItemQuantityException,
Exceptions\TooHighItemSumException, Exceptions\TooHighPriceException,
Exceptions\TooHighSumException,
Exceptions\TooLongItemCodeException, Exceptions\TooLongItemCodeException,
Exceptions\TooLongItemNameException, Exceptions\TooLongItemNameException,
Exceptions\TooLongMeasurementUnitException, Exceptions\TooLongMeasurementUnitException,
@ -62,7 +62,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getSum * @covers \AtolOnline\Entities\Item::getSum
* @covers \AtolOnline\Entities\Item::jsonSerialize * @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -88,7 +88,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::setName * @covers \AtolOnline\Entities\Item::setName
* @covers \AtolOnline\Exceptions\TooLongItemNameException * @covers \AtolOnline\Exceptions\TooLongItemNameException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -107,7 +107,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::setName * @covers \AtolOnline\Entities\Item::setName
* @covers \AtolOnline\Exceptions\EmptyItemNameException * @covers \AtolOnline\Exceptions\EmptyItemNameException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -124,9 +124,9 @@ class ItemTest extends BasicTestCase
* *
* @covers \AtolOnline\Entities\Item * @covers \AtolOnline\Entities\Item
* @covers \AtolOnline\Entities\Item::setPrice * @covers \AtolOnline\Entities\Item::setPrice
* @covers \AtolOnline\Exceptions\TooHighItemPriceException * @covers \AtolOnline\Exceptions\TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -134,7 +134,7 @@ class ItemTest extends BasicTestCase
*/ */
public function testTooHighPriceException(): void public function testTooHighPriceException(): void
{ {
$this->expectException(TooHighItemPriceException::class); $this->expectException(TooHighPriceException::class);
new Item('test', Constraints::MAX_COUNT_ITEM_PRICE + 0.1, 3); new Item('test', Constraints::MAX_COUNT_ITEM_PRICE + 0.1, 3);
} }
@ -143,12 +143,12 @@ class ItemTest extends BasicTestCase
* *
* @covers \AtolOnline\Entities\Item * @covers \AtolOnline\Entities\Item
* @covers \AtolOnline\Entities\Item::setPrice * @covers \AtolOnline\Entities\Item::setPrice
* @covers \AtolOnline\Exceptions\TooHighItemSumException * @covers \AtolOnline\Exceptions\TooHighSumException
* @throws TooHighItemSumException * @throws TooHighSumException
*/ */
public function testTooHighSumException(): void public function testTooHighSumException(): void
{ {
$this->expectException(TooHighItemSumException::class); $this->expectException(TooHighSumException::class);
(new Item('test', Constraints::MAX_COUNT_ITEM_PRICE, Constraints::MAX_COUNT_ITEM_QUANTITY))->getSum(); (new Item('test', Constraints::MAX_COUNT_ITEM_PRICE, Constraints::MAX_COUNT_ITEM_QUANTITY))->getSum();
} }
@ -159,7 +159,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::setPrice * @covers \AtolOnline\Entities\Item::setPrice
* @covers \AtolOnline\Exceptions\NegativeItemPriceException * @covers \AtolOnline\Exceptions\NegativeItemPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -178,7 +178,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::setQuantity * @covers \AtolOnline\Entities\Item::setQuantity
* @covers \AtolOnline\Exceptions\TooHighItemQuantityException * @covers \AtolOnline\Exceptions\TooHighItemQuantityException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -197,7 +197,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::setQuantity * @covers \AtolOnline\Entities\Item::setQuantity
* @covers \AtolOnline\Exceptions\NegativeItemQuantityException * @covers \AtolOnline\Exceptions\NegativeItemQuantityException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -217,7 +217,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getMeasurementUnit * @covers \AtolOnline\Entities\Item::getMeasurementUnit
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongMeasurementUnitException * @throws TooLongMeasurementUnitException
* @throws TooManyException * @throws TooManyException
@ -236,7 +236,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongMeasurementUnitException * @throws TooLongMeasurementUnitException
* @throws TooManyException * @throws TooManyException
@ -260,7 +260,7 @@ class ItemTest extends BasicTestCase
* @throws InvalidEnumValueException * @throws InvalidEnumValueException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooLongItemNameException * @throws TooLongItemNameException
*/ */
@ -294,7 +294,7 @@ class ItemTest extends BasicTestCase
* @throws InvalidEnumValueException * @throws InvalidEnumValueException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooLongItemNameException * @throws TooLongItemNameException
*/ */
@ -314,7 +314,7 @@ class ItemTest extends BasicTestCase
* @throws InvalidEnumValueException * @throws InvalidEnumValueException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooLongItemNameException * @throws TooLongItemNameException
*/ */
@ -334,7 +334,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
*/ */
@ -365,7 +365,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
*/ */
@ -399,7 +399,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
* @throws InvalidEnumValueException * @throws InvalidEnumValueException
@ -422,7 +422,7 @@ class ItemTest extends BasicTestCase
* @throws InvalidPhoneException * @throws InvalidPhoneException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongPayingAgentOperationException * @throws TooLongPayingAgentOperationException
* @throws TooManyException * @throws TooManyException
@ -450,7 +450,7 @@ class ItemTest extends BasicTestCase
* @throws InvalidPhoneException * @throws InvalidPhoneException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
*/ */
@ -485,7 +485,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongUserdataException * @throws TooLongUserdataException
* @throws TooManyException * @throws TooManyException
@ -514,7 +514,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getUserData * @covers \AtolOnline\Entities\Item::getUserData
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
@ -534,7 +534,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongUserdataException * @throws TooLongUserdataException
* @throws TooManyException * @throws TooManyException
@ -555,7 +555,7 @@ class ItemTest extends BasicTestCase
* @throws InvalidOKSMCodeException * @throws InvalidOKSMCodeException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
*/ */
@ -582,7 +582,7 @@ class ItemTest extends BasicTestCase
* @throws InvalidOKSMCodeException * @throws InvalidOKSMCodeException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
*/ */
@ -601,7 +601,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
* @throws InvalidDeclarationNumberException * @throws InvalidDeclarationNumberException
@ -629,7 +629,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws InvalidDeclarationNumberException * @throws InvalidDeclarationNumberException
* @throws TooManyException * @throws TooManyException
@ -649,7 +649,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws InvalidDeclarationNumberException * @throws InvalidDeclarationNumberException
* @throws TooManyException * @throws TooManyException
@ -669,7 +669,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getSum * @covers \AtolOnline\Entities\Item::getSum
* @covers \AtolOnline\Entities\Item::jsonSerialize * @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -696,7 +696,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::setExcise * @covers \AtolOnline\Entities\Item::setExcise
* @covers \AtolOnline\Exceptions\NegativeItemExciseException * @covers \AtolOnline\Exceptions\NegativeItemExciseException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException
@ -719,7 +719,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
* @throws TooLongItemCodeException * @throws TooLongItemCodeException
@ -756,7 +756,7 @@ class ItemTest extends BasicTestCase
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws NegativeItemQuantityException * @throws NegativeItemQuantityException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooLongItemCodeException * @throws TooLongItemCodeException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
@ -774,7 +774,7 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::setCode * @covers \AtolOnline\Entities\Item::setCode
* @covers \AtolOnline\Exceptions\TooLongItemCodeException * @covers \AtolOnline\Exceptions\TooLongItemCodeException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooHighItemPriceException * @throws TooHighPriceException
* @throws TooManyException * @throws TooManyException
* @throws NegativeItemPriceException * @throws NegativeItemPriceException
* @throws EmptyItemNameException * @throws EmptyItemNameException

View File

@ -1,105 +0,0 @@
<?php
/*
* 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\{
Constants\Constraints,
Entities\Payment,
Enums\PaymentTypes,
Tests\BasicTestCase
};
use AtolOnline\Exceptions\{
InvalidEnumValueException,
NegativePaymentSumException,
TooHighPaymentSumException,
};
/**
* Набор тестов для проверки работы класса оплаты
*/
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 InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testConstructor(): void
{
$this->assertAtolable(
new Payment(PaymentTypes::ELECTRON, 123.456789),
[
'type' => PaymentTypes::ELECTRON,
'sum' => 123.46,
]
);
}
/**
* Тестирует исключение при некорректном типе
*
* @covers \AtolOnline\Entities\Payment
* @covers \AtolOnline\Entities\Payment::setType
* @covers \AtolOnline\Enums\PaymentTypes::isValid
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
* @return void
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testInvalidEnumValueException(): void
{
$this->expectException(InvalidEnumValueException::class);
$this->expectExceptionMessage('Некорректное значение AtolOnline\Enums\PaymentTypes::123');
new Payment(123, 123.456789);
}
/**
* Тестирует исключение при слишком большой сумме
*
* @covers \AtolOnline\Entities\Payment
* @covers \AtolOnline\Entities\Payment::setSum
* @covers \AtolOnline\Exceptions\TooHighPaymentSumException
* @return void
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
*/
public function testTooHighPaymentSumException(): void
{
$this->expectException(TooHighPaymentSumException::class);
new Payment(PaymentTypes::ELECTRON, Constraints::MAX_COUNT_PAYMENT_SUM + 1);
}
/**
* Тестирует исключение при отрицательной сумме
*
* @covers \AtolOnline\Entities\Payment
* @covers \AtolOnline\Entities\Payment::setSum
* @covers \AtolOnline\Exceptions\NegativePaymentSumException
* @return void
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testNegativePaymentSumException(): void
{
$this->expectException(NegativePaymentSumException::class);
new Payment(PaymentTypes::ELECTRON, -1);
}
}

View File

@ -12,7 +12,6 @@ namespace AtolOnline\Tests\Entities;
use AtolOnline\{ use AtolOnline\{
Entities\Vat, Entities\Vat,
Enums\VatTypes, Enums\VatTypes,
Exceptions\InvalidEnumValueException,
Tests\BasicTestCase Tests\BasicTestCase
}; };
@ -70,7 +69,6 @@ class VatTest extends BasicTestCase
* @covers \AtolOnline\Entities\Vat::getSum * @covers \AtolOnline\Entities\Vat::getSum
* @covers \AtolOnline\Entities\Vat::getCalculated * @covers \AtolOnline\Entities\Vat::getCalculated
* @covers \AtolOnline\Entities\Vat::jsonSerialize * @covers \AtolOnline\Entities\Vat::jsonSerialize
* @throws InvalidEnumValueException
*/ */
public function testConstructor(string $type, float $sum): void public function testConstructor(string $type, float $sum): void
{ {
@ -92,7 +90,6 @@ class VatTest extends BasicTestCase
* @param float $after_minus Результат после -20р * @param float $after_minus Результат после -20р
* @covers \AtolOnline\Entities\Vat::addSum * @covers \AtolOnline\Entities\Vat::addSum
* @covers \AtolOnline\Entities\Vat::getCalculated * @covers \AtolOnline\Entities\Vat::getCalculated
* @throws InvalidEnumValueException
*/ */
public function testVatAdd(string $type, float $after_plus, float $after_minus) public function testVatAdd(string $type, float $after_plus, float $after_minus)
{ {