Compare commits

..

No commits in common. "b4af189292034075add17e074c335e05356ac8d8" and "1d6abfd475e46390ed2745104bbec88dab07b89a" have entirely different histories.

9 changed files with 40 additions and 387 deletions

View File

@ -74,6 +74,6 @@
}, },
"scripts": { "scripts": {
"test": "vendor/bin/phpunit --colors=always", "test": "vendor/bin/phpunit --colors=always",
"coverage": "php -dxdebug.mode=coverage vendor/bin/phpunit --coverage-html .coverage" "test-cov": "php -dxdebug.mode=coverage vendor/bin/phpunit --coverage-html .coverage-report"
} }
} }

12
composer.lock generated
View File

@ -1935,16 +1935,16 @@
}, },
{ {
"name": "phpspec/prophecy", "name": "phpspec/prophecy",
"version": "v1.15.0", "version": "1.14.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpspec/prophecy.git", "url": "https://github.com/phpspec/prophecy.git",
"reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", "url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
"reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1996,9 +1996,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/phpspec/prophecy/issues", "issues": "https://github.com/phpspec/prophecy/issues",
"source": "https://github.com/phpspec/prophecy/tree/v1.15.0" "source": "https://github.com/phpspec/prophecy/tree/1.14.0"
}, },
"time": "2021-12-08T12:19:24+00:00" "time": "2021-09-10T09:02:12+00:00"
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",

View File

@ -20,7 +20,7 @@ use Illuminate\Support\Collection;
abstract class EntityCollection extends Collection abstract class EntityCollection extends Collection
{ {
/** /**
* @inheritDoc * @return array
* @throws InvalidEntityInCollectionException * @throws InvalidEntityInCollectionException
*/ */
public function jsonSerialize(): array public function jsonSerialize(): array

View File

@ -11,14 +11,18 @@ declare(strict_types = 1);
namespace AtolOnline\Entities; namespace AtolOnline\Entities;
use AtolOnline\{Constants\Constraints, Enums\SnoTypes, Traits\HasEmail, Traits\HasInn}; use AtolOnline\{
use AtolOnline\Exceptions\{InvalidEmailException, Constants\Constraints,
Enums\SnoTypes,
Traits\HasEmail,
Traits\HasInn};
use AtolOnline\Exceptions\{
InvalidEmailException,
InvalidEnumValueException, InvalidEnumValueException,
InvalidInnLengthException, InvalidInnLengthException,
InvalidPaymentAddressException, InvalidPaymentAddressException,
TooLongEmailException, TooLongEmailException,
TooLongPaymentAddressException TooLongPaymentAddressException};
};
use JetBrains\PhpStorm\ArrayShape; use JetBrains\PhpStorm\ArrayShape;
/** /**
@ -55,8 +59,8 @@ final class Company extends Entity
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function __construct( public function __construct(
string $email, //TODO сделать необязательным здесь string $email,
string $sno, //TODO сделать необязательным здесь string $sno,
string $inn, string $inn,
string $payment_address, string $payment_address,
) { ) {

View File

@ -1,215 +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\Entities;
use AtolOnline\Collections\{Payments, Vats};
use AtolOnline\Constants\Constraints;
use AtolOnline\Exceptions\{InvalidEntityInCollectionException, TooLongCashierException};
use Exception;
use JetBrains\PhpStorm\ArrayShape;
/**
* Класс, описывающий документ коррекции
*
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 35
*/
class Correction extends Entity
{
/**
* @var Company Продавец
*/
protected Company $company;
/**
* @var string|null ФИО кассира
* @todo вынести в трейт
*/
protected ?string $cashier = null;
/**
* @var CorrectionInfo Данные коррекции
*/
protected CorrectionInfo $correction_info;
/**
* @var Payments Коллекция оплат
*/
protected Payments $payments;
/**
* @var Vats Коллекция ставок НДС
*/
protected Vats $vats;
/**
* Конструктор
*
* @param Company $company
* @param CorrectionInfo $correction_info
* @param Payments $payments
* @param Vats $vats
* @throws InvalidEntityInCollectionException
* @throws Exception
*/
public function __construct(
Company $company,
CorrectionInfo $correction_info,
Payments $payments,
Vats $vats,
) {
$this->setCompany($company)->setCorrectionInfo($correction_info)->setPayments($payments)->setVats($vats);
}
/**
* Возвращает установленного продавца
*
* @return Company
*/
public function getCompany(): Company
{
return $this->company;
}
/**
* Устанаваливает продавца
*
* @param Company $company
* @return $this
*/
public function setCompany(Company $company): self
{
$this->company = $company;
return $this;
}
/**
* Возвращает установленного кассира
*
* @return string|null
*/
public function getCashier(): ?string
{
return $this->cashier;
}
/**
* Устанаваливает кассира
*
* @param string|null $cashier
* @return $this
* @throws TooLongCashierException
*/
public function setCashier(?string $cashier): self
{
if (is_string($cashier)) {
$cashier = trim($cashier);
if (mb_strlen($cashier) > Constraints::MAX_LENGTH_CASHIER_NAME) {
throw new TooLongCashierException($cashier);
}
}
$this->cashier = $cashier ?: null;
return $this;
}
/**
* Возвращает установленные данные коррекции
*
* @return CorrectionInfo
*/
public function getCorrectionInfo(): CorrectionInfo
{
return $this->correction_info;
}
/**
* Устанавливает данные коррекции
*
* @param CorrectionInfo $correction_info
* @return Correction
*/
public function setCorrectionInfo(CorrectionInfo $correction_info): Correction
{
$this->correction_info = $correction_info;
return $this;
}
/**
* Возвращает установленную коллекцию оплат
*
* @return Payments
*/
public function getPayments(): Payments
{
return $this->payments;
}
/**
* Устанаваливает коллекцию оплат
*
* @param Payments $payments
* @return $this
* @throws InvalidEntityInCollectionException
*/
public function setPayments(Payments $payments): self
{
$payments->checkCount();
$payments->checkItemsClasses();
$this->payments = $payments;
return $this;
}
/**
* Возвращает установленную коллекцию ставок НДС
*
* @return Vats|null
*/
public function getVats(): ?Vats
{
return $this->vats ?? new Vats();
}
/**
* Устанаваливает коллекцию ставок НДС
*
* @param Vats|null $vats
* @return $this
* @throws Exception
*/
public function setVats(?Vats $vats): self
{
$vats->checkCount();
$vats->checkItemsClasses();
$this->vats = $vats;
return $this;
}
/**
* @inheritDoc
* @throws InvalidEntityInCollectionException
*/
#[ArrayShape([
'company' => "\AtolOnline\Entities\Company",
'correction_info' => "\AtolOnline\Entities\CorrectionInfo",
'payments' => "array",
'vats' => "\AtolOnline\Collections\Vats|null",
'cashier' => "null|string"
])]
public function jsonSerialize(): array
{
$json = [
'company' => $this->getCompany(),
'correction_info' => $this->getCorrectionInfo(),
'payments' => $this->getPayments()->jsonSerialize(),
'vats' => $this->getVats(),
];
!is_null($this->getCashier()) && $json['cashier'] = $this->getCashier();
return $json;
}
}

View File

@ -13,15 +13,20 @@ namespace AtolOnline\Entities;
use AtolOnline\Constants\Constraints; use AtolOnline\Constants\Constraints;
use AtolOnline\Enums\PaymentTypes; use AtolOnline\Enums\PaymentTypes;
use AtolOnline\Exceptions\{InvalidEnumValueException, NegativePaymentSumException, TooHighPaymentSumException,}; use AtolOnline\Exceptions\{
use JetBrains\PhpStorm\{ArrayShape, Pure}; InvalidEnumValueException,
NegativePaymentSumException,
TooHighPaymentSumException,};
use JetBrains\PhpStorm\{
ArrayShape,
Pure};
/** /**
* Класс, описывающий оплату * Класс, описывающий оплату
* *
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 30 * @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 30
*/ */
final class Payment extends Entity class Payment extends Entity
{ {
/** /**
* @var int Тип оплаты * @var int Тип оплаты

View File

@ -26,7 +26,7 @@ use Exception;
* *
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 17 * @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 17
*/ */
final class Receipt extends Entity class Receipt extends Entity
{ {
/** /**
* @var Client Покупатель * @var Client Покупатель
@ -35,7 +35,6 @@ final class Receipt extends Entity
/** /**
* @var Company Продавец * @var Company Продавец
* @todo вынести в трейт
*/ */
protected Company $company; protected Company $company;
@ -56,7 +55,6 @@ final class Receipt extends Entity
/** /**
* @var Payments Коллекция оплат * @var Payments Коллекция оплат
* @todo вынести в трейт
*/ */
protected Payments $payments; protected Payments $payments;
@ -72,7 +70,6 @@ final class Receipt extends Entity
/** /**
* @var string|null ФИО кассира * @var string|null ФИО кассира
* @todo вынести в трейт
*/ */
protected ?string $cashier = null; protected ?string $cashier = null;
@ -115,7 +112,7 @@ final class Receipt extends Entity
* Устанаваливает покупателя * Устанаваливает покупателя
* *
* @param Client $client * @param Client $client
* @return $this * @return Receipt
*/ */
public function setClient(Client $client): self public function setClient(Client $client): self
{ {
@ -137,7 +134,7 @@ final class Receipt extends Entity
* Устанаваливает продавца * Устанаваливает продавца
* *
* @param Company $company * @param Company $company
* @return $this * @return Receipt
*/ */
public function setCompany(Company $company): self public function setCompany(Company $company): self
{ {
@ -159,7 +156,7 @@ final class Receipt extends Entity
* Устанаваливает агента * Устанаваливает агента
* *
* @param AgentInfo|null $agent_info * @param AgentInfo|null $agent_info
* @return $this * @return Receipt
*/ */
public function setAgentInfo(?AgentInfo $agent_info): self public function setAgentInfo(?AgentInfo $agent_info): self
{ {
@ -181,7 +178,7 @@ final class Receipt extends Entity
* Поставщика * Поставщика
* *
* @param Supplier|null $supplier * @param Supplier|null $supplier
* @return $this * @return Receipt
*/ */
public function setSupplier(?Supplier $supplier): self public function setSupplier(?Supplier $supplier): self
{ {
@ -202,12 +199,12 @@ final class Receipt extends Entity
/** /**
* Устанаваливает коллекцию предметов расчёта * Устанаваливает коллекцию предметов расчёта
* *
* @todo исключение при пустой коллекции
* @param Items $items * @param Items $items
* @return $this * @return Receipt
* @throws EmptyItemsException * @throws EmptyItemsException
* @throws InvalidEntityInCollectionException * @throws InvalidEntityInCollectionException
* @throws Exception * @throws Exception
* @todo исключение при пустой коллекции
*/ */
public function setItems(Items $items): self public function setItems(Items $items): self
{ {
@ -233,7 +230,7 @@ final class Receipt extends Entity
* Устанаваливает коллекцию оплат * Устанаваливает коллекцию оплат
* *
* @param Payments $payments * @param Payments $payments
* @return $this * @return Receipt
* @throws InvalidEntityInCollectionException * @throws InvalidEntityInCollectionException
*/ */
public function setPayments(Payments $payments): self public function setPayments(Payments $payments): self
@ -258,7 +255,7 @@ final class Receipt extends Entity
* Устанаваливает коллекцию ставок НДС * Устанаваливает коллекцию ставок НДС
* *
* @param Vats|null $vats * @param Vats|null $vats
* @return $this * @return Receipt
* @throws Exception * @throws Exception
*/ */
public function setVats(?Vats $vats): self public function setVats(?Vats $vats): self
@ -295,7 +292,7 @@ final class Receipt extends Entity
* Устанаваливает кассира * Устанаваливает кассира
* *
* @param string|null $cashier * @param string|null $cashier
* @return $this * @return Receipt
* @throws TooLongCashierException * @throws TooLongCashierException
*/ */
public function setCashier(?string $cashier): self public function setCashier(?string $cashier): self
@ -324,7 +321,7 @@ final class Receipt extends Entity
* Устанаваливает дополнительный реквизит чека * Устанаваливает дополнительный реквизит чека
* *
* @param string|null $add_check_props * @param string|null $add_check_props
* @return $this * @return Receipt
* @throws TooLongAddCheckPropException * @throws TooLongAddCheckPropException
*/ */
public function setAddCheckProps(?string $add_check_props): self public function setAddCheckProps(?string $add_check_props): self
@ -353,7 +350,7 @@ final class Receipt extends Entity
* Устанаваливает дополнительный реквизит пользователя * Устанаваливает дополнительный реквизит пользователя
* *
* @param AdditionalUserProps|null $add_user_props * @param AdditionalUserProps|null $add_user_props
* @return $this * @return Receipt
*/ */
public function setAddUserProps(?AdditionalUserProps $add_user_props): self public function setAddUserProps(?AdditionalUserProps $add_user_props): self
{ {

View File

@ -17,12 +17,12 @@ namespace AtolOnline\Enums;
final class DocumentTypes extends Enum final class DocumentTypes extends Enum
{ {
/** /**
* Документ прихода, возврата прихода, расхода, возврата расхода * Чек прихода, возврата прихода, расхода, возврата расхода
*/ */
const RECEIPT = 'receipt'; const RECEIPT = 'receipt';
/** /**
* Документ коррекции * Чек коррекции
*/ */
const CORRECTION = 'correction'; const CORRECTION = 'correction';

View File

@ -1,138 +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, Helpers, Tests\BasicTestCase};
use AtolOnline\Collections\{Payments, Vats,};
use AtolOnline\Entities\{Company, Correction, CorrectionInfo};
use AtolOnline\Enums\{CorrectionTypes, SnoTypes};
use AtolOnline\Exceptions\{EmptyCorrectionNumberException,
InvalidCorrectionDateException,
InvalidEntityInCollectionException,
InvalidEnumValueException,
NegativePaymentSumException,
TooHighPaymentSumException,
TooLongCashierException
};
use Exception;
/**
* Набор тестов для проверки работы класса чека коррекции
*/
class CorrectionTest extends BasicTestCase
{
/**
* Тестирует конструктор и корректное приведение к json
*
* @return void
* @covers \AtolOnline\Entities\Correction
* @covers \AtolOnline\Entities\Correction::setCompany
* @covers \AtolOnline\Entities\Correction::setCorrectionInfo
* @covers \AtolOnline\Entities\Correction::setPayments
* @covers \AtolOnline\Entities\Correction::setVats
* @covers \AtolOnline\Entities\Correction::jsonSerialize
* @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws Exception
*/
public function testConstructor(): void
{
$correction = $this->newCorrection();
$this->assertIsAtolable($correction);
}
/**
* Тестирует установку валидного кассира
*
* @return void
* @covers \AtolOnline\Entities\Correction::setCashier
* @covers \AtolOnline\Entities\Correction::getCashier
* @covers \AtolOnline\Entities\Correction::jsonSerialize
* @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws TooLongCashierException
*/
public function testCashier(): void
{
$correction = $this->newCorrection()->setCashier(Helpers::randomStr());
$this->assertArrayHasKey('cashier', $correction->jsonSerialize());
$this->assertEquals($correction->getCashier(), $correction->jsonSerialize()['cashier']);
}
/**
* Тестирует обнуление кассира
*
* @param mixed $param
* @return void
* @dataProvider providerNullableStrings
* @covers \AtolOnline\Entities\Correction::setCashier
* @covers \AtolOnline\Entities\Correction::getCashier
* @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws TooLongCashierException
*/
public function testNullableCashier(mixed $param): void
{
$this->assertNull($this->newCorrection()->setCashier($param)->getCashier());
}
/**
* Тестирует выброс исключения при установке слишком длинного кассира (лол)
*
* @return void
* @covers \AtolOnline\Entities\Correction::setCashier
* @covers \AtolOnline\Exceptions\TooLongCashierException
* @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws TooLongCashierException
*/
public function testTooLongCashierException(): void
{
$this->expectException(TooLongCashierException::class);
$this->newCorrection()->setCashier(Helpers::randomStr(Constraints::MAX_LENGTH_CASHIER_NAME + 1));
}
/**
* Возвращает валидный тестовый объект чека
*
* @return Correction
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException
*/
protected function newCorrection(): Correction
{
return new Correction(
new Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'),
new CorrectionInfo(CorrectionTypes::SELF, '01.01.2021', Helpers::randomStr()),
new Payments($this->generatePaymentObjects(2)),
new Vats($this->generateVatObjects(2)),
);
}
}