Compare commits

..

No commits in common. "703c5178f5eef93da00a44b54738726b8f9ec0da" and "b39e76f31276a7107601073e816a84526251e00a" have entirely different histories.

7 changed files with 79 additions and 245 deletions

View File

@ -32,8 +32,8 @@
} }
], ],
"support": { "support": {
"rss": "https://github.com/anthonyaxenov/atol-online/discussions/categories/announcements", "rss": "https://t.me/atolonline_php",
"chat": "https://github.com/anthonyaxenov/atol-online/discussions", "chat": "https://t.me/+Rky7ia68fctjZmUy",
"source": "https://github.com/anthonyaxenov/atol-online", "source": "https://github.com/anthonyaxenov/atol-online",
"issues": "https://github.com/anthonyaxenov/atol-online/issues", "issues": "https://github.com/anthonyaxenov/atol-online/issues",
"docs": "https://github.com/anthonyaxenov/atol-online/blob/master/docs/readme.md" "docs": "https://github.com/anthonyaxenov/atol-online/blob/master/docs/readme.md"

64
composer.lock generated
View File

@ -68,16 +68,16 @@
}, },
{ {
"name": "guzzlehttp/guzzle", "name": "guzzlehttp/guzzle",
"version": "7.4.1", "version": "7.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/guzzle/guzzle.git", "url": "https://github.com/guzzle/guzzle.git",
"reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79" "reference": "868b3571a039f0ebc11ac8f344f4080babe2cb94"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/ee0a041b1760e6a53d2a39c8c34115adc2af2c79", "url": "https://api.github.com/repos/guzzle/guzzle/zipball/868b3571a039f0ebc11ac8f344f4080babe2cb94",
"reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79", "reference": "868b3571a039f0ebc11ac8f344f4080babe2cb94",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -86,7 +86,7 @@
"guzzlehttp/psr7": "^1.8.3 || ^2.1", "guzzlehttp/psr7": "^1.8.3 || ^2.1",
"php": "^7.2.5 || ^8.0", "php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0", "psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0" "symfony/deprecation-contracts": "^2.2"
}, },
"provide": { "provide": {
"psr/http-client-implementation": "1.0" "psr/http-client-implementation": "1.0"
@ -172,7 +172,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/guzzle/guzzle/issues", "issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.4.1" "source": "https://github.com/guzzle/guzzle/tree/7.4.0"
}, },
"funding": [ "funding": [
{ {
@ -188,7 +188,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-12-06T18:43:05+00:00" "time": "2021-10-18T09:52:00+00:00"
}, },
{ {
"name": "guzzlehttp/promises", "name": "guzzlehttp/promises",
@ -391,16 +391,16 @@
}, },
{ {
"name": "illuminate/collections", "name": "illuminate/collections",
"version": "v8.75.0", "version": "v8.74.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/collections.git", "url": "https://github.com/illuminate/collections.git",
"reference": "5a018387352afa2af30fd2be0a78c31e93295720" "reference": "f292b77824b42cd28decc7327e7c2e24c3806371"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/collections/zipball/5a018387352afa2af30fd2be0a78c31e93295720", "url": "https://api.github.com/repos/illuminate/collections/zipball/f292b77824b42cd28decc7327e7c2e24c3806371",
"reference": "5a018387352afa2af30fd2be0a78c31e93295720", "reference": "f292b77824b42cd28decc7327e7c2e24c3806371",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -441,20 +441,20 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2021-12-07T14:48:29+00:00" "time": "2021-11-30T14:29:03+00:00"
}, },
{ {
"name": "illuminate/contracts", "name": "illuminate/contracts",
"version": "v8.75.0", "version": "v8.74.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/contracts.git", "url": "https://github.com/illuminate/contracts.git",
"reference": "b07755f7c456cf587dfbfd6f0854f9f7c1a34b2f" "reference": "b0886ec05a63b204634d64d0b39d5b78a7c06f81"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/contracts/zipball/b07755f7c456cf587dfbfd6f0854f9f7c1a34b2f", "url": "https://api.github.com/repos/illuminate/contracts/zipball/b0886ec05a63b204634d64d0b39d5b78a7c06f81",
"reference": "b07755f7c456cf587dfbfd6f0854f9f7c1a34b2f", "reference": "b0886ec05a63b204634d64d0b39d5b78a7c06f81",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -489,11 +489,11 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2021-12-07T08:18:44+00:00" "time": "2021-11-17T15:04:30+00:00"
}, },
{ {
"name": "illuminate/macroable", "name": "illuminate/macroable",
"version": "v8.75.0", "version": "v8.74.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/macroable.git", "url": "https://github.com/illuminate/macroable.git",
@ -1171,25 +1171,25 @@
}, },
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
"version": "v3.0.0", "version": "v2.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git", "url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "c726b64c1ccfe2896cb7df2e1331c357ad1c8ced" "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/c726b64c1ccfe2896cb7df2e1331c357ad1c8ced", "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8",
"reference": "c726b64c1ccfe2896cb7df2e1331c357ad1c8ced", "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.0.2" "php": ">=7.1"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-main": "3.0-dev" "dev-main": "2.5-dev"
}, },
"thanks": { "thanks": {
"name": "symfony/contracts", "name": "symfony/contracts",
@ -1218,7 +1218,7 @@
"description": "A generic function and convention to trigger deprecation notices", "description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.0" "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.0"
}, },
"funding": [ "funding": [
{ {
@ -1234,7 +1234,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-11-01T23:48:49+00:00" "time": "2021-07-12T14:48:14+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
@ -2002,16 +2002,16 @@
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "9.2.10", "version": "9.2.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "d5850aaf931743067f4bfc1ae4cbd06468400687" "reference": "f301eb1453c9e7a1bc912ee8b0ea9db22c60223b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f301eb1453c9e7a1bc912ee8b0ea9db22c60223b",
"reference": "d5850aaf931743067f4bfc1ae4cbd06468400687", "reference": "f301eb1453c9e7a1bc912ee8b0ea9db22c60223b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2067,7 +2067,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.10" "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.9"
}, },
"funding": [ "funding": [
{ {
@ -2075,7 +2075,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2021-12-05T09:12:13+00:00" "time": "2021-11-19T15:21:02+00:00"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",

View File

@ -27,8 +27,6 @@ abstract class EntityCollection extends Collection
public function __construct($items = []) public function __construct($items = [])
{ {
$this->checkCount($items); $this->checkCount($items);
//TODO следует переделать EntityCollection в обёртку над Collection,
// ибо ломает методы Collection, которые return new static
$this->checkItemsClasses($items); $this->checkItemsClasses($items);
parent::__construct($items); parent::__construct($items);
} }
@ -87,7 +85,6 @@ abstract class EntityCollection extends Collection
*/ */
public function checkCount(array $items = []): void public function checkCount(array $items = []): void
{ {
//TODO проверять пустоту?
if (count($items) > static::MAX_COUNT || $this->count() === static::MAX_COUNT) { if (count($items) > static::MAX_COUNT || $this->count() === static::MAX_COUNT) {
throw new (static::EXCEPTION_CLASS)(static::MAX_COUNT); throw new (static::EXCEPTION_CLASS)(static::MAX_COUNT);
} }

View File

@ -11,29 +11,14 @@ declare(strict_types = 1);
namespace AtolOnline\Entities; namespace AtolOnline\Entities;
use ArrayAccess;
use Illuminate\Contracts\Support\Arrayable;
use JsonSerializable; use JsonSerializable;
use Stringable; use Stringable;
/** /**
* Абстрактное описание любой сущности, представляемой как json * Абстрактное описание любой сущности, представляемой как json
*/ */
abstract class Entity implements JsonSerializable, Stringable, Arrayable, ArrayAccess abstract class Entity implements JsonSerializable, Stringable
{ {
/**
* @inheritDoc
*/
abstract public function jsonSerialize(): array;
/**
* @inheritDoc
*/
public function toArray()
{
return $this->jsonSerialize();
}
/** /**
* Возвращает строковое представление json-структуры объекта * Возвращает строковое представление json-структуры объекта
* *
@ -41,42 +26,6 @@ abstract class Entity implements JsonSerializable, Stringable, Arrayable, ArrayA
*/ */
public function __toString() public function __toString()
{ {
return json_encode($this->toArray(), JSON_UNESCAPED_UNICODE); return json_encode($this->jsonSerialize(), JSON_UNESCAPED_UNICODE);
}
/**
* @inheritDoc
*/
public function offsetExists(mixed $offset): bool
{
return isset($this->toArray()[$offset]);
}
/**
* @inheritDoc
*/
public function offsetGet(mixed $offset): mixed
{
return $this->toArray()[$offset];
}
/**
* @inheritDoc
*/
public function offsetSet(mixed $offset, mixed $value)
{
throw new \BadMethodCallException(
'Объект ' . static::class . ' нельзя изменять как массив. Следует использовать сеттеры.'
);
}
/**
* @inheritDoc
*/
public function offsetUnset(mixed $offset): void
{
throw new \BadMethodCallException(
'Объект ' . static::class . ' нельзя изменять как массив. Следует использовать сеттеры.'
);
} }
} }

View File

@ -196,7 +196,7 @@ class Receipt extends Entity
*/ */
public function getItems(): Items public function getItems(): Items
{ {
return $this->items ?? new Items(); return $this->items;
} }
/** /**
@ -207,7 +207,6 @@ class Receipt extends Entity
* @return Receipt * @return Receipt
* @throws EmptyItemsException * @throws EmptyItemsException
* @throws InvalidEntityInCollectionException * @throws InvalidEntityInCollectionException
* @throws Exception
*/ */
public function setItems(Items $items): self public function setItems(Items $items): self
{ {
@ -216,8 +215,6 @@ class Receipt extends Entity
} }
$items->checkItemsClasses(); $items->checkItemsClasses();
$this->items = $items; $this->items = $items;
$this->getItems()->each(fn ($item) => $this->total += $item->getSum());
$this->total = round($this->total, 2);
return $this; return $this;
} }
@ -254,7 +251,7 @@ class Receipt extends Entity
*/ */
public function getVats(): ?Vats public function getVats(): ?Vats
{ {
return $this->vats ?? new Vats(); return $this->vats;
} }
/** /**
@ -263,7 +260,6 @@ class Receipt extends Entity
* @param Vats|null $vats * @param Vats|null $vats
* @return Receipt * @return Receipt
* @throws EmptyVatsException * @throws EmptyVatsException
* @throws Exception
*/ */
public function setVats(?Vats $vats): self public function setVats(?Vats $vats): self
{ {
@ -271,8 +267,6 @@ class Receipt extends Entity
throw new EmptyVatsException(); throw new EmptyVatsException();
} }
$this->vats = $vats; $this->vats = $vats;
/** @var Vat $vat */
$this->getVats()->each(fn ($vat) => $vat->setSum($this->getTotal()));
return $this; return $this;
} }
@ -286,6 +280,18 @@ class Receipt extends Entity
return $this->total; return $this->total;
} }
/**
* Устанавливает полную сумму чека
*
* @param float $total
* @return Receipt
*/
public function setTotal(float $total): self
{
$this->total = $total;
return $this;
}
/** /**
* Возвращает установленного кассира * Возвращает установленного кассира
* *
@ -381,11 +387,28 @@ class Receipt extends Entity
'payments' => $this->getPayments(), 'payments' => $this->getPayments(),
]; ];
$this->getAgentInfo()?->jsonSerialize() && $json['agent_info'] = $this->getAgentInfo(); $this->getAgentInfo()?->jsonSerialize() && $json['agent_info'] = $this->getAgentInfo();
$this->getSupplier()?->jsonSerialize() && $json['supplier_info'] = $this->getSupplier(); $this->getSupplier()?->jsonSerialize() && $json['vats'] = $this->getVats();
$this->getVats()?->jsonSerialize() && $json['vats'] = $this->getVats(); $this->getVats()?->jsonSerialize() && $json['vats'] = $this->getVats();
!is_null($this->getAddCheckProps()) && $json['additional_check_props'] = $this->getAddCheckProps(); !is_null($this->getAddCheckProps()) && $json['additional_check_props'] = $this->getAddCheckProps();
!is_null($this->getCashier()) && $json['cashier'] = $this->getCashier(); !is_null($this->getCashier()) && $json['cashier'] = $this->getCashier();
$this->getAddUserProps()?->jsonSerialize() && $json['additional_user_props'] = $this->getAddUserProps(); $this->getAddUserProps()?->jsonSerialize() && $json['additional_user_props'] = $this->getAddUserProps();
return $json; return $json;
} }
///**
// * Пересчитывает, сохраняет и возвращает итоговую сумму чека по всем позициям (включая НДС). Тег ФФД - 1020.
// *
// * @return float
// * @throws Exception
// */
//public function calcTotal(): float
//{
// $sum = 0;
// $this->clearVats();
// foreach ($this->items->get() as $item) {
// $sum += $item->calcSum();
// $this->addVat(new Vat($item->getVat()->getType(), $item->getSum()));
// }
// return $this->total = round($sum, 2);
//}
} }

View File

@ -16,7 +16,8 @@ use AtolOnline\Exceptions\InvalidEnumValueException;
use AtolOnline\Helpers; use AtolOnline\Helpers;
use JetBrains\PhpStorm\{ use JetBrains\PhpStorm\{
ArrayShape, ArrayShape,
Pure}; Pure
};
/** /**
* Класс, описывающий ставку НДС * Класс, описывающий ставку НДС
@ -96,7 +97,7 @@ final class Vat extends Entity
} }
/** /**
* Возвращает расчитанный итоговый размер ставки НДС в рублях * Возвращает sdрасчитанный итоговый размер ставки НДС в рублях
* *
* @return float * @return float
* @see https://nalog-nalog.ru/nds/nalogovaya_baza_nds/kak-schitat-nds-pravilno-vychislyaem-20-ot-summy-primer-algoritm/ * @see https://nalog-nalog.ru/nds/nalogovaya_baza_nds/kak-schitat-nds-pravilno-vychislyaem-20-ot-summy-primer-algoritm/

View File

@ -12,7 +12,6 @@ namespace AtolOnline\Tests\Entities;
use AtolOnline\{ use AtolOnline\{
Collections\Items, Collections\Items,
Collections\Payments, Collections\Payments,
Collections\Vats,
Entities\AgentInfo, Entities\AgentInfo,
Entities\Client, Entities\Client,
Entities\Company, Entities\Company,
@ -21,8 +20,6 @@ use AtolOnline\{
Entities\PayingAgent, Entities\PayingAgent,
Entities\Receipt, Entities\Receipt,
Entities\ReceivePaymentsOperator, Entities\ReceivePaymentsOperator,
Entities\Supplier,
Entities\Vat,
Enums\AgentTypes, Enums\AgentTypes,
Enums\SnoTypes, Enums\SnoTypes,
Tests\BasicTestCase}; Tests\BasicTestCase};
@ -30,7 +27,6 @@ use AtolOnline\Exceptions\{
EmptyItemNameException, EmptyItemNameException,
EmptyItemsException, EmptyItemsException,
EmptyPaymentsException, EmptyPaymentsException,
EmptyVatsException,
InvalidEntityInCollectionException, InvalidEntityInCollectionException,
InvalidEnumValueException, InvalidEnumValueException,
InvalidInnLengthException, InvalidInnLengthException,
@ -39,7 +35,6 @@ use AtolOnline\Exceptions\{
NegativeItemQuantityException, NegativeItemQuantityException,
NegativePaymentSumException, NegativePaymentSumException,
TooHighItemPriceException, TooHighItemPriceException,
TooHighItemSumException,
TooHighPaymentSumException, TooHighPaymentSumException,
TooLongItemNameException, TooLongItemNameException,
TooLongPayingAgentOperationException, TooLongPayingAgentOperationException,
@ -81,9 +76,8 @@ class ReceiptTest extends BasicTestCase
*/ */
public function testConstructor(): void public function testConstructor(): void
{ {
$receipt = $this->newReceipt(); $receipt = $this->validReceipt();
$this->assertIsAtolable($receipt); $this->assertIsAtolable($receipt);
$receipt->getItems();
} }
/** /**
@ -110,7 +104,7 @@ class ReceiptTest extends BasicTestCase
* @throws TooLongPayingAgentOperationException * @throws TooLongPayingAgentOperationException
* @throws Exception * @throws Exception
*/ */
public function testAgentInfo(): void public function testSetAgentInfo(): void
{ {
$agent_info = new AgentInfo( $agent_info = new AgentInfo(
AgentTypes::ANOTHER, AgentTypes::ANOTHER,
@ -118,42 +112,9 @@ class ReceiptTest extends BasicTestCase
new ReceivePaymentsOperator(['+79519999999']), new ReceivePaymentsOperator(['+79519999999']),
new MoneyTransferOperator('MTO Name', '9876543210', 'London', ['+79517777777']), new MoneyTransferOperator('MTO Name', '9876543210', 'London', ['+79517777777']),
); );
$receipt = $this->newReceipt()->setAgentInfo($agent_info); $receipt = $this->validReceipt()->setAgentInfo($agent_info);
$this->assertArrayHasKey('agent_info', $receipt->jsonSerialize()); $this->assertArrayHasKey('agent_info', $receipt->jsonSerialize());
$this->assertEquals($receipt->getAgentInfo(), $receipt->jsonSerialize()['agent_info']); $this->assertEquals($receipt->getAgentInfo(), $receipt->jsonSerialize()['agent_info']);
$this->assertArrayNotHasKey('agent_info', $receipt->setAgentInfo(null)->jsonSerialize());
}
/**
* Тестирует установку данных поставщика
*
* @return void
* @covers \AtolOnline\Entities\Receipt::setSupplier
* @covers \AtolOnline\Entities\Receipt::getSupplier
* @covers \AtolOnline\Entities\Receipt::jsonSerialize
* @throws EmptyItemNameException
* @throws EmptyItemsException
* @throws EmptyPaymentsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPhoneException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws NegativePaymentSumException
* @throws TooHighItemPriceException
* @throws TooHighPaymentSumException
* @throws TooLongItemNameException
* @throws TooManyException
* @throws Exception
*/
public function testSupplier(): void
{
$supplier = new Supplier('some name', '+fasd3\qe3fs_=nac99013928czc', ['+122997365456']);
$receipt = $this->newReceipt()->setSupplier($supplier);
$this->assertArrayHasKey('supplier_info', $receipt->jsonSerialize());
$this->assertEquals($receipt->getSupplier(), $receipt->jsonSerialize()['supplier_info']);
$this->assertArrayNotHasKey('supplier_info', $receipt->setSupplier(null)->jsonSerialize());
} }
/** /**
@ -161,7 +122,7 @@ class ReceiptTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Receipt * @covers \AtolOnline\Entities\Receipt
* @covers \AtolOnline\Entities\Receipt::setItems * @covers \AtolOnline\Entities\Receipt::setVats
* @covers \AtolOnline\Collections\Items::checkCount * @covers \AtolOnline\Collections\Items::checkCount
* @covers \AtolOnline\Exceptions\EmptyItemsException * @covers \AtolOnline\Exceptions\EmptyItemsException
* @throws InvalidEnumValueException * @throws InvalidEnumValueException
@ -186,7 +147,7 @@ class ReceiptTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Receipt * @covers \AtolOnline\Entities\Receipt
* @covers \AtolOnline\Entities\Receipt::setItems * @covers \AtolOnline\Entities\Receipt::setVats
* @covers \AtolOnline\Collections\Items::checkItemsClasses * @covers \AtolOnline\Collections\Items::checkItemsClasses
* @covers \AtolOnline\Collections\Items::checkItemClass * @covers \AtolOnline\Collections\Items::checkItemClass
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException * @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
@ -243,7 +204,7 @@ class ReceiptTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Receipt * @covers \AtolOnline\Entities\Receipt
* @covers \AtolOnline\Entities\Receipt::setPayments * @covers \AtolOnline\Entities\Receipt::setVats
* @covers \AtolOnline\Collections\Items::checkItemsClasses * @covers \AtolOnline\Collections\Items::checkItemsClasses
* @covers \AtolOnline\Collections\Items::checkItemClass * @covers \AtolOnline\Collections\Items::checkItemClass
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException * @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
@ -269,103 +230,6 @@ class ReceiptTest extends BasicTestCase
); );
} }
/**
* Тестирует выброс исключения при передаче пустой коллекции ставок НДС
*
* @return void
* @covers \AtolOnline\Entities\Receipt
* @covers \AtolOnline\Entities\Receipt::setVats
* @covers \AtolOnline\Collections\Vats::checkCount
* @covers \AtolOnline\Exceptions\EmptyVatsException
* @throws EmptyItemNameException
* @throws EmptyItemsException
* @throws EmptyPaymentsException
* @throws EmptyVatsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws NegativePaymentSumException
* @throws TooHighItemPriceException
* @throws TooHighPaymentSumException
* @throws TooLongItemNameException
* @throws TooManyException
*/
public function testEmptyVatsException(): void
{
$this->expectException(EmptyVatsException::class);
$this->newReceipt()->setVats(new Vats([]));
}
/**
* Тестирует выброс исключения при передаче коллекции ставок НДС с некорректным содержимым
*
* @return void
* @covers \AtolOnline\Entities\Receipt
* @covers \AtolOnline\Entities\Receipt::setVats
* @covers \AtolOnline\Collections\Vats::checkItemsClasses
* @covers \AtolOnline\Collections\Vats::checkItemClass
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
* @throws EmptyItemNameException
* @throws EmptyItemsException
* @throws EmptyPaymentsException
* @throws EmptyVatsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws NegativePaymentSumException
* @throws TooHighItemPriceException
* @throws TooHighPaymentSumException
* @throws TooLongItemNameException
* @throws TooManyException
*/
public function testInvalidVatInCollectionException(): void
{
$this->expectException(InvalidEntityInCollectionException::class);
$this->expectErrorMessage('Коллекция AtolOnline\Collections\Vats должна содержать объекты AtolOnline\Entities\Vat');
$this->newReceipt()->setVats(new Vats(['qwerty']));
}
/**
* Тестирует просчёт общей суммы чека и ставок НДС
*
* @covers \AtolOnline\Entities\Receipt::setVats
* @covers \AtolOnline\Entities\Receipt::getVats
* @covers \AtolOnline\Entities\Receipt::getTotal
* @throws TooHighItemPriceException
* @throws NegativeItemPriceException
* @throws EmptyPaymentsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws TooHighItemSumException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws EmptyItemsException
* @throws EmptyItemNameException
* @throws TooManyException
* @throws NegativeItemQuantityException
* @throws TooLongItemNameException
* @throws Exception
*/
public function testCalculations(): void
{
$items_total = 0;
$receipt = $this->newReceipt();
//TODO при $receipt->getItems()->pluck('sum') стреляет InvalidEntityInCollectionException
// см. примечания в конструкторе EntityCollection
$receipt->getItems()->each(function ($item) use (&$items_total) {
/** @var Item $item */
return $items_total += $item->getSum();
});
$this->assertEquals($items_total, $receipt->getTotal());
/** @var Vat $vat */
$receipt->setVats(new Vats($this->generateVatObjects(2)))->getVats()
->each(fn ($vat) => $this->assertEquals($items_total, $vat->getSum()));
}
/** /**
* Возвращает валидный тестовый объект чека * Возвращает валидный тестовый объект чека
* *
@ -383,12 +247,12 @@ class ReceiptTest extends BasicTestCase
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooManyException * @throws TooManyException
*/ */
protected function newReceipt(): Receipt protected function validReceipt(): Receipt
{ {
return new Receipt( return new Receipt(
new Client('John Doe', 'john@example.com', '+1/22/99*73s dsdas654 5s6', '+fasd3\qe3fs_=nac99013928czc'), 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 Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'),
new Items($this->generateItemObjects(2)), new Items($this->generateItemObjects()),
new Payments($this->generatePaymentObjects()) new Payments($this->generatePaymentObjects())
); );
} }