mirror of
https://github.com/anthonyaxenov/atol-online.git
synced 2024-11-26 09:54:15 +00:00
Compare commits
No commits in common. "b39e76f31276a7107601073e816a84526251e00a" and "1f3d5d2f3db5a8c2e4b53462188c720a6a588300" have entirely different histories.
b39e76f312
...
1f3d5d2f3d
@ -100,6 +100,7 @@ class KktMonitor extends AtolClient
|
||||
/**
|
||||
* Возвращает информацию о конкретной ККТ по её серийному номеру
|
||||
*
|
||||
* @todo кастовать к отдельному классу со своими геттерами
|
||||
* @param string $serial_number
|
||||
* @return Kkt
|
||||
* @throws GuzzleException
|
||||
|
@ -22,12 +22,10 @@ abstract class EntityCollection extends Collection
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws InvalidEntityInCollectionException
|
||||
*/
|
||||
public function __construct($items = [])
|
||||
{
|
||||
$this->checkCount($items);
|
||||
$this->checkItemsClasses($items);
|
||||
parent::__construct($items);
|
||||
}
|
||||
|
||||
@ -73,17 +71,19 @@ abstract class EntityCollection extends Collection
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
$this->checkItemsClasses();
|
||||
$this->each(function ($item) {
|
||||
$this->checkClass($item);
|
||||
});
|
||||
return parent::jsonSerialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет количество элементов коллекции
|
||||
* Проверяет количество ставок
|
||||
*
|
||||
* @param array $items Массив элементов, если пустой - проверит содержимое коллекции
|
||||
* @return void
|
||||
*/
|
||||
public function checkCount(array $items = []): void
|
||||
private 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,24 +91,14 @@ abstract class EntityCollection extends Collection
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет корректность класса элемента коллекции
|
||||
* Проверяет корректность класса объекта
|
||||
*
|
||||
* @throws InvalidEntityInCollectionException
|
||||
*/
|
||||
public function checkItemClass(mixed $item): void
|
||||
private function checkClass(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));
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,7 @@ use AtolOnline\Collections\Items;
|
||||
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\TooHighPriceException;
|
||||
use AtolOnline\Exceptions\TooLongAddCheckPropException;
|
||||
use AtolOnline\Exceptions\TooLongCashierException;
|
||||
use Exception;
|
||||
@ -78,26 +75,22 @@ class Receipt extends Entity
|
||||
/**
|
||||
* @var string|null Дополнительный реквизит
|
||||
*/
|
||||
protected ?string $add_check_props = null;
|
||||
protected ?string $add_check_props;
|
||||
|
||||
/**
|
||||
* @var AdditionalUserProps|null Дополнительный реквизит пользователя
|
||||
*/
|
||||
protected ?AdditionalUserProps $add_user_props = null;
|
||||
protected ?AdditionalUserProps $add_user_props;
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*
|
||||
* @param Client $client
|
||||
* @param Company $company
|
||||
* @param Items $items
|
||||
* @param Payments $payments
|
||||
* @throws EmptyItemsException
|
||||
* @throws EmptyPaymentsException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
*/
|
||||
public function __construct(Client $client, Company $company, Items $items, Payments $payments)
|
||||
{
|
||||
public function __construct(
|
||||
Client $client,
|
||||
Company $company,
|
||||
Items $items,
|
||||
Payments $payments,
|
||||
) {
|
||||
$this->setClient($client)->setCompany($company)->setItems($items)->setPayments($payments);
|
||||
}
|
||||
|
||||
@ -148,7 +141,7 @@ class Receipt extends Entity
|
||||
/**
|
||||
* Возвращает установленного агента
|
||||
*
|
||||
* @return AgentInfo|null
|
||||
* @return AgentInfo
|
||||
*/
|
||||
public function getAgentInfo(): ?AgentInfo
|
||||
{
|
||||
@ -205,15 +198,9 @@ class Receipt extends Entity
|
||||
* @todo исключение при пустой коллекции
|
||||
* @param Items $items
|
||||
* @return Receipt
|
||||
* @throws EmptyItemsException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
*/
|
||||
public function setItems(Items $items): self
|
||||
{
|
||||
if ($items->isEmpty()) {
|
||||
throw new EmptyItemsException();
|
||||
}
|
||||
$items->checkItemsClasses();
|
||||
$this->items = $items;
|
||||
return $this;
|
||||
}
|
||||
@ -231,15 +218,12 @@ class Receipt extends Entity
|
||||
/**
|
||||
* Устанаваливает коллекцию оплат
|
||||
*
|
||||
* @todo исключение при пустой коллекции
|
||||
* @param Payments $payments
|
||||
* @return Receipt
|
||||
* @throws EmptyPaymentsException
|
||||
*/
|
||||
public function setPayments(Payments $payments): self
|
||||
{
|
||||
if ($payments->isEmpty()) {
|
||||
throw new EmptyPaymentsException();
|
||||
}
|
||||
$this->payments = $payments;
|
||||
return $this;
|
||||
}
|
||||
@ -259,13 +243,9 @@ class Receipt extends Entity
|
||||
*
|
||||
* @param Vats|null $vats
|
||||
* @return Receipt
|
||||
* @throws EmptyVatsException
|
||||
*/
|
||||
public function setVats(?Vats $vats): self
|
||||
{
|
||||
if ($vats->isEmpty()) {
|
||||
throw new EmptyVatsException();
|
||||
}
|
||||
$this->vats = $vats;
|
||||
return $this;
|
||||
}
|
||||
@ -317,7 +297,7 @@ class Receipt extends Entity
|
||||
throw new TooLongCashierException($cashier);
|
||||
}
|
||||
}
|
||||
$this->cashier = $cashier ?: null;
|
||||
$this->cashier = empty($cashier) ? null : $cashier;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -384,7 +364,7 @@ class Receipt extends Entity
|
||||
'company' => $this->getCompany(),
|
||||
'items' => $this->getItems(),
|
||||
'total' => $this->getTotal(),
|
||||
'payments' => $this->getPayments(),
|
||||
'payment' => $this->getPayments(),
|
||||
];
|
||||
$this->getAgentInfo()?->jsonSerialize() && $json['agent_info'] = $this->getAgentInfo();
|
||||
$this->getSupplier()?->jsonSerialize() && $json['vats'] = $this->getVats();
|
||||
|
@ -1,22 +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;
|
||||
|
||||
/**
|
||||
* Исключение, возникающее при попытке указать документу пустую коллекцию предметов расчёта
|
||||
*
|
||||
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 21
|
||||
*/
|
||||
class EmptyItemsException extends AtolException
|
||||
{
|
||||
protected $message = 'Документ не может содержать пустую коллекцию предметов расчёта';
|
||||
}
|
@ -1,22 +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;
|
||||
|
||||
/**
|
||||
* Исключение, возникающее при попытке указать документу пустую коллекцию оплат
|
||||
*
|
||||
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 30
|
||||
*/
|
||||
class EmptyPaymentsException extends AtolException
|
||||
{
|
||||
protected $message = 'Документ не может содержать пустую коллекцию оплат';
|
||||
}
|
@ -1,22 +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;
|
||||
|
||||
/**
|
||||
* Исключение, возникающее при попытке указать документу пустую коллекцию ставок НДС
|
||||
*
|
||||
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 31
|
||||
*/
|
||||
class EmptyVatsException extends AtolException
|
||||
{
|
||||
protected $message = 'Документ не может содержать пустую коллекцию ставок НДС';
|
||||
}
|
@ -339,7 +339,7 @@ class KktMonitorTest extends BasicTestCase
|
||||
$kkt = $client->getOne($serial_number);
|
||||
$this->assertNotEmpty($client->getResponse());
|
||||
$this->assertIsSameClass(Kkt::class, $kkt);
|
||||
$this->assertIsAtolable($kkt);
|
||||
$this->assertAtolable($kkt);
|
||||
$this->assertNotNull($kkt->serialNumber);
|
||||
$this->assertEquals($serial_number, $kkt->serialNumber);
|
||||
}
|
||||
|
@ -13,20 +13,6 @@ 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;
|
||||
@ -39,10 +25,6 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class BasicTestCase extends TestCase
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Методы для управления тестами, использующими тестовый АТОЛ API
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Проверяет наличие подключения к ресурсу по URL
|
||||
*
|
||||
@ -83,10 +65,6 @@ class BasicTestCase extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Дополнительные ассерты
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Тестирует является ли объект приводимым к json-строке согласно схеме АТОЛ Онлайн
|
||||
*
|
||||
@ -97,7 +75,7 @@ class BasicTestCase extends TestCase
|
||||
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
||||
* @throws Exception
|
||||
*/
|
||||
public function assertIsAtolable(Entity|EntityCollection $entity, ?array $json_structure = null): void
|
||||
public function assertAtolable(Entity|EntityCollection $entity, ?array $json_structure = null): void
|
||||
{
|
||||
$this->assertIsArray($entity->jsonSerialize());
|
||||
$this->assertIsString((string)$entity);
|
||||
@ -107,8 +85,6 @@ class BasicTestCase extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Ассерты проверки наследования
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -227,8 +203,6 @@ class BasicTestCase extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Провайдеры данных для прогона тестов
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -314,74 +288,4 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,18 @@ 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};
|
||||
TooManyItemsException,};
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Набор тестов для проверки работы класса коллекции предметов расчёта
|
||||
@ -40,12 +42,11 @@ class ItemsTest extends BasicTestCase
|
||||
* @throws TooHighItemPriceException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws TooManyException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
*/
|
||||
public function testTooManyItemsExceptionByConstructor()
|
||||
{
|
||||
$this->expectException(TooManyItemsException::class);
|
||||
new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS + 1));
|
||||
new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,13 +61,12 @@ class ItemsTest extends BasicTestCase
|
||||
* @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());
|
||||
(new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS)))
|
||||
->prepend($this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,13 +82,12 @@ class ItemsTest extends BasicTestCase
|
||||
* @throws TooHighItemPriceException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws TooManyException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
*/
|
||||
public function testTooManyItemsExceptionByAdd()
|
||||
{
|
||||
$this->expectException(TooManyItemsException::class);
|
||||
(new Items($this->generateItemObjects(Constraints::MAX_COUNT_DOC_ITEMS)))
|
||||
->add($this->generateItemObjects());
|
||||
(new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS)))
|
||||
->add($this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,13 +103,12 @@ class ItemsTest extends BasicTestCase
|
||||
* @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());
|
||||
(new Items($this->generateObjects(Constraints::MAX_COUNT_DOC_ITEMS)))
|
||||
->push(...$this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,12 +124,33 @@ class ItemsTest extends BasicTestCase
|
||||
* @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));
|
||||
(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;
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,14 @@ namespace AtolOnline\Tests\Collections;
|
||||
use AtolOnline\{
|
||||
Collections\Payments,
|
||||
Constants\Constraints,
|
||||
Exceptions\InvalidEntityInCollectionException,
|
||||
Entities\Payment,
|
||||
Enums\PaymentTypes,
|
||||
Exceptions\InvalidEnumValueException,
|
||||
Exceptions\NegativePaymentSumException,
|
||||
Exceptions\TooHighPaymentSumException,
|
||||
Exceptions\TooManyPaymentsException,
|
||||
Tests\BasicTestCase};
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Набор тестов для проверки работы класса коллекции оплат
|
||||
@ -33,12 +35,11 @@ class PaymentsTest extends BasicTestCase
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws NegativePaymentSumException
|
||||
* @throws TooHighPaymentSumException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
*/
|
||||
public function testTooManyPaymentsExceptionByConstructor()
|
||||
{
|
||||
$this->expectException(TooManyPaymentsException::class);
|
||||
new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1));
|
||||
new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,13 +51,12 @@ class PaymentsTest extends BasicTestCase
|
||||
* @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());
|
||||
(new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS)))
|
||||
->prepend($this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,13 +69,12 @@ class PaymentsTest extends BasicTestCase
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws NegativePaymentSumException
|
||||
* @throws TooHighPaymentSumException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
*/
|
||||
public function testTooManyPaymentsExceptionByAdd()
|
||||
{
|
||||
$this->expectException(TooManyPaymentsException::class);
|
||||
(new Payments($this->generatePaymentObjects(Constraints::MAX_COUNT_DOC_PAYMENTS)))
|
||||
->add($this->generatePaymentObjects());
|
||||
(new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS)))
|
||||
->add($this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,13 +87,12 @@ class PaymentsTest extends BasicTestCase
|
||||
* @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());
|
||||
(new Payments($this->generateObjects(Constraints::MAX_COUNT_DOC_PAYMENTS + 1)))
|
||||
->push(...$this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,12 +105,34 @@ class PaymentsTest extends BasicTestCase
|
||||
* @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));
|
||||
(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;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ use AtolOnline\{
|
||||
Collections\Vats,
|
||||
Constants\Constraints,
|
||||
Entities\Payment,
|
||||
Entities\Vat,
|
||||
Enums\PaymentTypes,
|
||||
Enums\VatTypes,
|
||||
Exceptions\InvalidEntityInCollectionException,
|
||||
Exceptions\InvalidEnumValueException,
|
||||
Exceptions\NegativePaymentSumException,
|
||||
@ -37,10 +39,10 @@ class VatsTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$vats = new Vats($this->generateVatObjects(3));
|
||||
$vats = new Vats($this->generateObjects(3));
|
||||
$this->assertIsCollection($vats);
|
||||
$this->assertEquals(3, $vats->count());
|
||||
$this->assertIsAtolable($vats);
|
||||
$this->assertAtolable($vats);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,12 +52,11 @@ 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->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS + 1));
|
||||
new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,12 +66,11 @@ 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->generateVatObjects(3)))
|
||||
->prepend($this->generateVatObjects());
|
||||
$vats = (new Vats($this->generateObjects(3)))
|
||||
->prepend($this->generateObjects());
|
||||
$this->assertEquals(4, $vats->count());
|
||||
}
|
||||
|
||||
@ -82,13 +82,12 @@ 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->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
||||
->prepend($this->generateVatObjects());
|
||||
(new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
||||
->prepend($this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,12 +97,11 @@ 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->generateVatObjects(3)))
|
||||
->add($this->generateVatObjects());
|
||||
$vats = (new Vats($this->generateObjects(3)))
|
||||
->add($this->generateObjects());
|
||||
$this->assertEquals(4, $vats->count());
|
||||
}
|
||||
|
||||
@ -115,13 +113,12 @@ 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->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
||||
->add($this->generateVatObjects());
|
||||
(new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
||||
->add($this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,12 +128,11 @@ 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->generateVatObjects(3)))
|
||||
->push(...$this->generateVatObjects(3));
|
||||
$vats = (new Vats($this->generateObjects(3)))
|
||||
->push(...$this->generateObjects(3));
|
||||
$this->assertEquals(6, $vats->count());
|
||||
}
|
||||
|
||||
@ -148,13 +144,12 @@ 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->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
||||
->push(...$this->generateVatObjects());
|
||||
(new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS)))
|
||||
->push(...$this->generateObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,12 +159,11 @@ 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->generateVatObjects(3)))
|
||||
->merge($this->generateVatObjects(3));
|
||||
$vats = (new Vats($this->generateObjects(3)))
|
||||
->merge($this->generateObjects(3));
|
||||
$this->assertEquals(6, $vats->count());
|
||||
}
|
||||
|
||||
@ -181,20 +175,19 @@ 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->generateVatObjects(Constraints::MAX_COUNT_DOC_VATS - 1)))
|
||||
->merge($this->generateVatObjects(2));
|
||||
(new Vats($this->generateObjects(Constraints::MAX_COUNT_DOC_VATS - 1)))
|
||||
->merge($this->generateObjects(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует выброс исключения при наличии скаляров в коллекции
|
||||
*
|
||||
* @covers \AtolOnline\Collections\EntityCollection
|
||||
* @covers \AtolOnline\Collections\EntityCollection::checkItemClass
|
||||
* @covers \AtolOnline\Collections\EntityCollection::checkClass
|
||||
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
||||
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
|
||||
* @throws InvalidEnumValueException
|
||||
@ -204,7 +197,7 @@ class VatsTest extends BasicTestCase
|
||||
{
|
||||
$this->expectException(InvalidEntityInCollectionException::class);
|
||||
$this->expectExceptionMessage("(string)'bad element'");
|
||||
(new Vats($this->generateVatObjects(2)))
|
||||
(new Vats($this->generateObjects(2)))
|
||||
->merge('bad element')
|
||||
->jsonSerialize();
|
||||
}
|
||||
@ -221,8 +214,29 @@ class VatsTest extends BasicTestCase
|
||||
{
|
||||
$this->expectException(InvalidEntityInCollectionException::class);
|
||||
$this->expectExceptionMessage(Payment::class);
|
||||
(new Vats($this->generateVatObjects()))
|
||||
(new Vats($this->generateObjects()))
|
||||
->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;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class AdditionalUserPropsTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
new AdditionalUserProps('name', 'value'),
|
||||
[
|
||||
'name' => 'name',
|
||||
|
@ -36,7 +36,7 @@ class AgentInfoTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructorWithoutArgs(): void
|
||||
{
|
||||
$this->assertIsAtolable(new AgentInfo(), []);
|
||||
$this->assertAtolable(new AgentInfo(), []);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,20 +63,20 @@ class AgentInfoTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$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(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(
|
||||
$this->assertAtolable(new AgentInfo(
|
||||
AgentTypes::ANOTHER,
|
||||
new PayingAgent(),
|
||||
new ReceivePaymentsOperator(),
|
||||
new MoneyTransferOperator(),
|
||||
), ['type' => AgentTypes::ANOTHER]);
|
||||
|
||||
$this->assertIsAtolable(new AgentInfo(
|
||||
$this->assertAtolable(new AgentInfo(
|
||||
AgentTypes::ANOTHER,
|
||||
new PayingAgent('test', ['+79518888888']),
|
||||
new ReceivePaymentsOperator(['+79519999999']),
|
||||
|
@ -34,7 +34,7 @@ class ClientTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructorWithoutArgs(): void
|
||||
{
|
||||
$this->assertIsAtolable(new Client(), []);
|
||||
$this->assertAtolable(new Client(), []);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,11 +54,11 @@ class ClientTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$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(
|
||||
$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(
|
||||
'John Doe',
|
||||
'john@example.com',
|
||||
'+1/22/99*73s dsdas654 5s6', // +122997365456
|
||||
|
@ -44,7 +44,7 @@ class CompanyTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->assertIsAtolable(new Company(
|
||||
$this->assertAtolable(new Company(
|
||||
$email = 'company@example.com',
|
||||
$sno = SnoTypes::OSN,
|
||||
$inn = '1234567890',
|
||||
|
@ -43,7 +43,7 @@ class CorrectionInfoTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
new CorrectionInfo(CorrectionTypes::SELF, '01.01.2021', $number = Helpers::randomStr()),
|
||||
[
|
||||
'type' => CorrectionTypes::SELF,
|
||||
|
@ -71,7 +71,7 @@ class ItemTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
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->assertIsAtolable($item, [
|
||||
$this->assertAtolable($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->assertIsAtolable($item, [
|
||||
$this->assertAtolable($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->assertIsAtolable($item, [
|
||||
$this->assertAtolable($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->assertIsAtolable($item, [
|
||||
$this->assertAtolable($item, [
|
||||
'name' => 'test item',
|
||||
'price' => 2,
|
||||
'quantity' => 3,
|
||||
@ -502,7 +502,7 @@ class ItemTest extends BasicTestCase
|
||||
*/
|
||||
public function testValidUserdata(): void
|
||||
{
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
(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->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
(new Item('test item', 2, 3))->setCountryCode('800'),
|
||||
[
|
||||
'name' => 'test item',
|
||||
@ -620,7 +620,7 @@ class ItemTest extends BasicTestCase
|
||||
*/
|
||||
public function testValidDeclarationNumber(): void
|
||||
{
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
(new Item('test item', 2, 3))
|
||||
->setDeclarationNumber($code = Helpers::randomStr()),
|
||||
[
|
||||
@ -691,7 +691,7 @@ class ItemTest extends BasicTestCase
|
||||
*/
|
||||
public function testExcise(): void
|
||||
{
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
(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->assertIsAtolable($item, [
|
||||
$this->assertAtolable($item, [
|
||||
'name' => 'test item',
|
||||
'price' => 2,
|
||||
'quantity' => 3,
|
||||
|
@ -57,7 +57,7 @@ class KktEntityTest extends BasicTestCase
|
||||
{
|
||||
$kkt = new Kkt((object)$this->sample_data);
|
||||
$this->assertIsSameClass(Kkt::class, $kkt);
|
||||
$this->assertIsAtolable($kkt);
|
||||
$this->assertAtolable($kkt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,11 +51,11 @@ class MoneyTransferOperatorTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$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(
|
||||
$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(
|
||||
'some name',
|
||||
'+fasd3\qe3fs_=nac99013928czc',
|
||||
'London',
|
||||
|
@ -49,18 +49,18 @@ class PayingAgentTest extends BasicTestCase
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$operation = Helpers::randomStr();
|
||||
$this->assertIsAtolable(new PayingAgent(
|
||||
$this->assertAtolable(new PayingAgent(
|
||||
$operation,
|
||||
['+122997365456'],
|
||||
), [
|
||||
'operation' => $operation,
|
||||
'phones' => ['+122997365456'],
|
||||
]);
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
new PayingAgent($operation),
|
||||
['operation' => $operation]
|
||||
);
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
new PayingAgent(phones: ['+122997365456']),
|
||||
['phones' => ['+122997365456']]
|
||||
);
|
||||
|
@ -42,7 +42,7 @@ class PaymentTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertIsAtolable(
|
||||
$this->assertAtolable(
|
||||
new Payment(PaymentTypes::ELECTRON, 123.456789),
|
||||
[
|
||||
'type' => PaymentTypes::ELECTRON,
|
||||
|
@ -1,259 +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\{
|
||||
Collections\Items,
|
||||
Collections\Payments,
|
||||
Entities\AgentInfo,
|
||||
Entities\Client,
|
||||
Entities\Company,
|
||||
Entities\Item,
|
||||
Entities\MoneyTransferOperator,
|
||||
Entities\PayingAgent,
|
||||
Entities\Receipt,
|
||||
Entities\ReceivePaymentsOperator,
|
||||
Enums\AgentTypes,
|
||||
Enums\SnoTypes,
|
||||
Tests\BasicTestCase};
|
||||
use AtolOnline\Exceptions\{
|
||||
EmptyItemNameException,
|
||||
EmptyItemsException,
|
||||
EmptyPaymentsException,
|
||||
InvalidEntityInCollectionException,
|
||||
InvalidEnumValueException,
|
||||
InvalidInnLengthException,
|
||||
InvalidPhoneException,
|
||||
NegativeItemPriceException,
|
||||
NegativeItemQuantityException,
|
||||
NegativePaymentSumException,
|
||||
TooHighItemPriceException,
|
||||
TooHighPaymentSumException,
|
||||
TooLongItemNameException,
|
||||
TooLongPayingAgentOperationException,
|
||||
TooManyException};
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Набор тестов для проверки работы класса чека прихода, расхода, возврата прихода, возврата расхода
|
||||
*/
|
||||
class ReceiptTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* Тестирует конструктор и корректное приведение к json
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Receipt
|
||||
* @covers \AtolOnline\Entities\Receipt::setClient
|
||||
* @covers \AtolOnline\Entities\Receipt::setCompany
|
||||
* @covers \AtolOnline\Entities\Receipt::setItems
|
||||
* @covers \AtolOnline\Entities\Receipt::setPayments
|
||||
* @covers \AtolOnline\Entities\Receipt::getClient
|
||||
* @covers \AtolOnline\Entities\Receipt::getCompany
|
||||
* @covers \AtolOnline\Entities\Receipt::getItems
|
||||
* @covers \AtolOnline\Entities\Receipt::getPayments
|
||||
* @covers \AtolOnline\Entities\Receipt::getTotal
|
||||
* @covers \AtolOnline\Entities\Receipt::jsonSerialize
|
||||
* @throws TooHighItemPriceException
|
||||
* @throws NegativePaymentSumException
|
||||
* @throws NegativeItemPriceException
|
||||
* @throws EmptyPaymentsException
|
||||
* @throws TooHighPaymentSumException
|
||||
* @throws EmptyItemsException
|
||||
* @throws EmptyItemNameException
|
||||
* @throws TooManyException
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws NegativeItemQuantityException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$receipt = $this->validReceipt();
|
||||
$this->assertIsAtolable($receipt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку данных агента
|
||||
*
|
||||
* @return void
|
||||
* @covers \AtolOnline\Entities\Receipt::setAgentInfo
|
||||
* @covers \AtolOnline\Entities\Receipt::getAgentInfo
|
||||
* @covers \AtolOnline\Entities\Receipt::jsonSerialize
|
||||
* @throws EmptyItemNameException
|
||||
* @throws EmptyItemsException
|
||||
* @throws EmptyPaymentsException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws NegativeItemPriceException
|
||||
* @throws NegativeItemQuantityException
|
||||
* @throws NegativePaymentSumException
|
||||
* @throws TooHighItemPriceException
|
||||
* @throws TooHighPaymentSumException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws TooManyException
|
||||
* @throws InvalidInnLengthException
|
||||
* @throws InvalidPhoneException
|
||||
* @throws TooLongPayingAgentOperationException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSetAgentInfo(): void
|
||||
{
|
||||
$agent_info = new AgentInfo(
|
||||
AgentTypes::ANOTHER,
|
||||
new PayingAgent('test', ['+79518888888']),
|
||||
new ReceivePaymentsOperator(['+79519999999']),
|
||||
new MoneyTransferOperator('MTO Name', '9876543210', 'London', ['+79517777777']),
|
||||
);
|
||||
$receipt = $this->validReceipt()->setAgentInfo($agent_info);
|
||||
$this->assertArrayHasKey('agent_info', $receipt->jsonSerialize());
|
||||
$this->assertEquals($receipt->getAgentInfo(), $receipt->jsonSerialize()['agent_info']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует выброс исключения при передаче пустой коллекции предметов расчёта
|
||||
*
|
||||
* @return void
|
||||
* @covers \AtolOnline\Entities\Receipt
|
||||
* @covers \AtolOnline\Entities\Receipt::setVats
|
||||
* @covers \AtolOnline\Collections\Items::checkCount
|
||||
* @covers \AtolOnline\Exceptions\EmptyItemsException
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws NegativePaymentSumException
|
||||
* @throws TooHighPaymentSumException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
* @throws EmptyPaymentsException
|
||||
*/
|
||||
public function testEmptyItemsException(): void
|
||||
{
|
||||
$this->expectException(EmptyItemsException::class);
|
||||
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 Payments($this->generatePaymentObjects())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует выброс исключения при передаче коллекции предметов расчёта с некорректным содержимым
|
||||
*
|
||||
* @return void
|
||||
* @covers \AtolOnline\Entities\Receipt
|
||||
* @covers \AtolOnline\Entities\Receipt::setVats
|
||||
* @covers \AtolOnline\Collections\Items::checkItemsClasses
|
||||
* @covers \AtolOnline\Collections\Items::checkItemClass
|
||||
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
|
||||
* @throws EmptyItemsException
|
||||
* @throws EmptyPaymentsException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws NegativePaymentSumException
|
||||
* @throws TooHighPaymentSumException
|
||||
*/
|
||||
public function testInvalidItemInCollectionException(): void
|
||||
{
|
||||
$this->expectException(InvalidEntityInCollectionException::class);
|
||||
$this->expectErrorMessage('Коллекция AtolOnline\Collections\Items должна содержать объекты AtolOnline\Entities\Item');
|
||||
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(['qwerty']),
|
||||
new Payments($this->generatePaymentObjects())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует выброс исключения при передаче пустой коллекции оплат
|
||||
*
|
||||
* @return void
|
||||
* @covers \AtolOnline\Entities\Receipt
|
||||
* @covers \AtolOnline\Entities\Receipt::setPayments
|
||||
* @covers \AtolOnline\Collections\Payments::checkCount
|
||||
* @covers \AtolOnline\Exceptions\EmptyPaymentsException
|
||||
* @throws TooHighPaymentSumException
|
||||
* @throws EmptyItemNameException
|
||||
* @throws NegativeItemPriceException
|
||||
* @throws NegativeItemQuantityException
|
||||
* @throws TooHighItemPriceException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws TooManyException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
* @throws EmptyItemsException
|
||||
*/
|
||||
public function testEmptyPaymentsException(): void
|
||||
{
|
||||
$this->expectException(EmptyPaymentsException::class);
|
||||
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)]),
|
||||
new Payments([])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует выброс исключения при передаче коллекции предметов расчёта с некорректным содержимым
|
||||
*
|
||||
* @return void
|
||||
* @covers \AtolOnline\Entities\Receipt
|
||||
* @covers \AtolOnline\Entities\Receipt::setVats
|
||||
* @covers \AtolOnline\Collections\Items::checkItemsClasses
|
||||
* @covers \AtolOnline\Collections\Items::checkItemClass
|
||||
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
|
||||
* @throws EmptyItemNameException
|
||||
* @throws EmptyItemsException
|
||||
* @throws EmptyPaymentsException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
* @throws NegativeItemPriceException
|
||||
* @throws NegativeItemQuantityException
|
||||
* @throws TooHighItemPriceException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws TooManyException
|
||||
*/
|
||||
public function testInvalidPaymentInCollectionException(): void
|
||||
{
|
||||
$this->expectException(InvalidEntityInCollectionException::class);
|
||||
$this->expectErrorMessage('Коллекция AtolOnline\Collections\Payments должна содержать объекты AtolOnline\Entities\Payment');
|
||||
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)]),
|
||||
new Payments(['qwerty'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает валидный тестовый объект чека
|
||||
*
|
||||
* @return Receipt
|
||||
* @throws EmptyItemNameException
|
||||
* @throws EmptyItemsException
|
||||
* @throws EmptyPaymentsException
|
||||
* @throws InvalidEntityInCollectionException
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws NegativeItemPriceException
|
||||
* @throws NegativeItemQuantityException
|
||||
* @throws NegativePaymentSumException
|
||||
* @throws TooHighItemPriceException
|
||||
* @throws TooHighPaymentSumException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws TooManyException
|
||||
*/
|
||||
protected function validReceipt(): Receipt
|
||||
{
|
||||
return 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($this->generateItemObjects()),
|
||||
new Payments($this->generatePaymentObjects())
|
||||
);
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ class ReceivePaymentsOperatorTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$this->assertIsAtolable(new ReceivePaymentsOperator(['+122997365456']), ['phones' => ['+122997365456']]);
|
||||
$this->assertAtolable(new ReceivePaymentsOperator(['+122997365456']), ['phones' => ['+122997365456']]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,10 +49,10 @@ class SupplierTest extends BasicTestCase
|
||||
*/
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$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(
|
||||
$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(
|
||||
'some name',
|
||||
'+fasd3\qe3fs_=nac99013928czc',
|
||||
['+122997365456'],
|
||||
|
@ -76,7 +76,7 @@ class VatTest extends BasicTestCase
|
||||
public function testConstructor(string $type, float $sum): void
|
||||
{
|
||||
$vat = new Vat($type, $sum);
|
||||
$this->assertIsAtolable($vat, [
|
||||
$this->assertAtolable($vat, [
|
||||
'type' => $vat->getType(),
|
||||
'sum' => $vat->getCalculated(),
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user