Четвёртая итерация Receipt

- 100% покрытие
- элвисы в разных сеттерах
This commit is contained in:
Anthony Axenov 2021-12-08 19:04:14 +08:00
parent 703c5178f5
commit 16d1146826
6 changed files with 226 additions and 28 deletions

View File

@ -17,12 +17,10 @@ use AtolOnline\Exceptions\{
InvalidInnLengthException,
InvalidPhoneException,
TooLongClientNameException,
TooLongEmailException
};
TooLongEmailException};
use AtolOnline\Traits\{
HasEmail,
HasInn
};
HasInn};
use JetBrains\PhpStorm\Pure;
/**
@ -94,7 +92,7 @@ final class Client extends Entity
throw new TooLongClientNameException($name);
}
}
$this->name = empty($name) ? null : $name;
$this->name = $name ?: null;
return $this;
}

View File

@ -14,8 +14,7 @@ namespace AtolOnline\Entities;
use AtolOnline\Constants\Constraints;
use AtolOnline\Exceptions\{
InvalidPhoneException,
TooLongPayingAgentOperationException
};
TooLongPayingAgentOperationException};
use AtolOnline\Traits\HasPhones;
use Illuminate\Support\Collection;
@ -64,7 +63,7 @@ final class PayingAgent extends Entity
throw new TooLongPayingAgentOperationException($operation);
}
}
$this->operation = empty($operation) ? null : $operation;
$this->operation = $operation ?: null;
return $this;
}

View File

@ -340,7 +340,7 @@ class Receipt extends Entity
throw new TooLongAddCheckPropException($add_check_props);
}
}
$this->add_check_props = empty($add_check_props) ? null : $add_check_props;
$this->add_check_props = $add_check_props ?: null;
return $this;
}

View File

@ -41,7 +41,7 @@ trait HasEmail
throw new InvalidEmailException($email);
}
}
$this->email = empty($email) ? null : $email;
$this->email = $email ?: null;
return $this;
}

View File

@ -37,7 +37,7 @@ trait HasInn
throw new InvalidInnLengthException($inn);
}
}
$this->inn = empty($inn) ? null : $inn;
$this->inn = $inn ?: null;
return $this;
}

View File

@ -10,22 +10,28 @@
namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Collections\Items,
Collections\Payments,
Collections\Vats,
Entities\AgentInfo,
Entities\Client,
Entities\Company,
Entities\Item,
Entities\MoneyTransferOperator,
Entities\PayingAgent,
Entities\Receipt,
Entities\ReceivePaymentsOperator,
Entities\Supplier,
Entities\Vat,
Enums\AgentTypes,
Enums\SnoTypes,
Constants\Constraints,
Helpers,
Tests\BasicTestCase};
use AtolOnline\Collections\{
Items,
Payments,
Vats,};
use AtolOnline\Entities\{
AdditionalUserProps,
AgentInfo,
Client,
Company,
Item,
MoneyTransferOperator,
PayingAgent,
Receipt,
ReceivePaymentsOperator,
Supplier,
Vat,};
use AtolOnline\Enums\{
AgentTypes,
SnoTypes,};
use AtolOnline\Exceptions\{
EmptyItemNameException,
EmptyItemsException,
@ -41,6 +47,8 @@ use AtolOnline\Exceptions\{
TooHighItemPriceException,
TooHighItemSumException,
TooHighPaymentSumException,
TooLongAddCheckPropException,
TooLongCashierException,
TooLongItemNameException,
TooLongPayingAgentOperationException,
TooManyException};
@ -83,7 +91,6 @@ class ReceiptTest extends BasicTestCase
{
$receipt = $this->newReceipt();
$this->assertIsAtolable($receipt);
$receipt->getItems();
}
/**
@ -363,7 +370,201 @@ class ReceiptTest extends BasicTestCase
/** @var Vat $vat */
$receipt->setVats(new Vats($this->generateVatObjects(2)))->getVats()
->each(fn ($vat) => $this->assertEquals($items_total, $vat->getSum()));
->each(fn($vat) => $this->assertEquals($items_total, $vat->getSum()));
}
/**
* Тестирует установку валидного кассира
*
* @return void
* @covers \AtolOnline\Entities\Receipt::setCashier
* @covers \AtolOnline\Entities\Receipt::getCashier
* @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 TooLongCashierException
* @throws Exception
*/
public function testCashier(): void
{
$receipt = $this->newReceipt()->setCashier(Helpers::randomStr());
$this->assertArrayHasKey('cashier', $receipt->jsonSerialize());
$this->assertEquals($receipt->getCashier(), $receipt->jsonSerialize()['cashier']);
}
/**
* Тестирует обнуление кассира
*
* @param mixed $param
* @return void
* @dataProvider providerNullableStrings
* @covers \AtolOnline\Entities\Receipt::setCashier
* @covers \AtolOnline\Entities\Receipt::getCashier
* @throws EmptyItemNameException
* @throws EmptyItemsException
* @throws EmptyPaymentsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws NegativePaymentSumException
* @throws TooHighItemPriceException
* @throws TooHighPaymentSumException
* @throws TooLongCashierException
* @throws TooLongItemNameException
* @throws TooManyException
*/
public function testNullableCashier(mixed $param): void
{
$this->assertNull($this->newReceipt()->setCashier($param)->getCashier());
}
/**
* Тестирует выброс исключения при установке слишком длинного кассира (лол)
*
* @return void
* @covers \AtolOnline\Entities\Receipt::setCashier
* @covers \AtolOnline\Exceptions\TooLongCashierException
* @throws EmptyItemNameException
* @throws EmptyItemsException
* @throws EmptyPaymentsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws NegativePaymentSumException
* @throws TooHighItemPriceException
* @throws TooHighPaymentSumException
* @throws TooLongCashierException
* @throws TooLongItemNameException
* @throws TooManyException
*/
public function testTooLongCashierException(): void
{
$this->expectException(TooLongCashierException::class);
$this->newReceipt()->setCashier(Helpers::randomStr(Constraints::MAX_LENGTH_CASHIER_NAME + 1));
}
/**
* Тестирует установку дополнительного реквизита чека
*
* @return void
* @covers \AtolOnline\Entities\Receipt::setAddCheckProps
* @covers \AtolOnline\Entities\Receipt::getAddCheckProps
* @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 TooLongAddCheckPropException
* @throws Exception
*/
public function testAddCheckProps(): void
{
$receipt = $this->newReceipt()->setAddCheckProps(Helpers::randomStr());
$this->assertArrayHasKey('additional_check_props', $receipt->jsonSerialize());
$this->assertEquals($receipt->getAddCheckProps(), $receipt->jsonSerialize()['additional_check_props']);
}
/**
* Тестирует обнуление дополнительного реквизита чека
*
* @param mixed $param
* @return void
* @dataProvider providerNullableStrings
* @covers \AtolOnline\Entities\Receipt::setAddCheckProps
* @covers \AtolOnline\Entities\Receipt::getAddCheckProps
* @throws EmptyItemNameException
* @throws EmptyItemsException
* @throws EmptyPaymentsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws NegativePaymentSumException
* @throws TooHighItemPriceException
* @throws TooHighPaymentSumException
* @throws TooLongAddCheckPropException
* @throws TooLongItemNameException
* @throws TooManyException
*/
public function testNullableAddCheckProps(mixed $param): void
{
$this->assertNull($this->newReceipt()->setAddCheckProps($param)->getAddCheckProps());
}
/**
* Тестирует выброс исключения при установке слишком длинного дополнительного реквизита чека
*
* @return void
* @covers \AtolOnline\Entities\Receipt::setAddCheckProps
* @covers \AtolOnline\Exceptions\TooLongAddCheckPropException
* @throws EmptyItemNameException
* @throws EmptyItemsException
* @throws EmptyPaymentsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws NegativePaymentSumException
* @throws TooHighItemPriceException
* @throws TooHighPaymentSumException
* @throws TooLongAddCheckPropException
* @throws TooLongItemNameException
* @throws TooManyException
*/
public function testTooLongAddCheckPropException(): void
{
$this->expectException(TooLongAddCheckPropException::class);
$this->newReceipt()->setAddCheckProps(Helpers::randomStr(Constraints::MAX_LENGTH_ADD_CHECK_PROP + 1));
}
/**
* Тестирует установку дополнительного реквизита пользователя
*
* @return void
* @covers \AtolOnline\Entities\Receipt::setAddUserProps
* @covers \AtolOnline\Entities\Receipt::getAddUserProps
* @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 Exception
*/
public function testAdditionalUserProps(): void
{
$aup = new AdditionalUserProps('name', 'value');
$receipt = $this->newReceipt()->setAddUserProps($aup);
$this->assertArrayHasKey('additional_user_props', $receipt->jsonSerialize());
$this->assertEquals($receipt->getAddUserProps(), $receipt->jsonSerialize()['additional_user_props']);
$this->assertArrayNotHasKey('additional_user_props', $receipt->setAddUserProps(null)->jsonSerialize());
}
/**