Поддержка nomenclature_code у предмета расчёта + мелкофиксы

- теперь `getSum()` проверяет по `Constraints::MAX_COUNT_ITEM_SUM` вместо `MAX_COUNT_ITEM_PRICE` (как и должен был изначально)
- подправил `TooLongException`
- всякие phpdoc-и
This commit is contained in:
2021-12-03 11:52:40 +08:00
parent 1c0d8ba64d
commit 2a66889e46
5 changed files with 192 additions and 19 deletions

View File

@@ -34,13 +34,15 @@ use AtolOnline\{
Exceptions\TooHighItemQuantityException,
Exceptions\TooHighPriceException,
Exceptions\TooHighSumException,
Exceptions\TooLongItemCodeException,
Exceptions\TooLongItemNameException,
Exceptions\TooLongMeasurementUnitException,
Exceptions\TooLongPayingAgentOperationException,
Exceptions\TooLongUserdataException,
Exceptions\TooManyException,
Helpers,
Tests\BasicTestCase};
Tests\BasicTestCase
};
/**
* Набор тестов для проверки работы класс продавца
@@ -207,12 +209,12 @@ class ItemTest extends BasicTestCase
}
/**
* Тестирует установку пустой единицы измерения
* Тестирует обнуление единицы измерения
*
* @param mixed $param
* @dataProvider providerNullableStrings
* @covers \AtolOnline\Entities\Item::setMeasurementUnit
* @covers \AtolOnline\Entities\Item::getMeasurementUnit
* @covers \AtolOnline\Entities\Item::setMeasurementUnit
* @covers \AtolOnline\Entities\Item::getMeasurementUnit
* @throws EmptyItemNameException
* @throws NegativeItemPriceException
* @throws TooHighPriceException
@@ -504,12 +506,12 @@ class ItemTest extends BasicTestCase
}
/**
* Тестирует установку пустых пользовательских данных
* Тестирует обнуление пользовательских данных
*
* @param mixed $param
* @dataProvider providerNullableStrings
* @covers \AtolOnline\Entities\Item::setUserData
* @covers \AtolOnline\Entities\Item::getUserData
* @covers \AtolOnline\Entities\Item::setUserData
* @covers \AtolOnline\Entities\Item::getUserData
* @throws EmptyItemNameException
* @throws NegativeItemPriceException
* @throws TooHighPriceException
@@ -689,7 +691,7 @@ class ItemTest extends BasicTestCase
}
/**
* Тестирует установку акциза и расчёт суммы с его учётом
* Тестирует выброс исключения при установке слишком отрицательного акциза
*
* @covers \AtolOnline\Entities\Item::setExcise
* @covers \AtolOnline\Exceptions\NegativeItemExciseException
@@ -706,4 +708,81 @@ class ItemTest extends BasicTestCase
$this->expectException(NegativeItemExciseException::class);
(new Item('test item', 2, 3))->setExcise(-1);
}
/**
* Тестирует установку валидного кода товара
*
* @covers \AtolOnline\Entities\Item::setCode
* @covers \AtolOnline\Entities\Item::getCode
* @covers \AtolOnline\Entities\Item::getCodeHex
* @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws EmptyItemNameException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws TooHighPriceException
* @throws TooLongItemNameException
* @throws TooManyException
* @throws TooLongItemCodeException
*/
public function testValidNomenclatureCode(): void
{
$code = Helpers::randomStr(Constraints::MAX_LENGTH_ITEM_CODE);
$encoded = trim(preg_replace('/([\dA-Fa-f]{2})/', '$1 ', bin2hex($code)));
$item = (new Item('test item', 2, 3))->setCode($code);
$this->assertEquals($code, $item->getCode());
$this->assertEquals($encoded, $item->getCodeHex());
$decoded = hex2bin(str_replace(' ', '', $item->getCodeHex()));
$this->assertEquals($decoded, $item->getCode());
$this->assertAtolable($item, [
'name' => 'test item',
'price' => 2,
'quantity' => 3,
'sum' => 6,
'nomenclature_code' => $item->getCodeHex(),
]);
}
/**
* Тестирует обнуление кода товара
*
* @param mixed $param
* @dataProvider providerNullableStrings
* @covers \AtolOnline\Entities\Item::setCode
* @covers \AtolOnline\Entities\Item::getCode
* @covers \AtolOnline\Entities\Item::getCodeHex
* @throws EmptyItemNameException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws TooHighPriceException
* @throws TooLongItemCodeException
* @throws TooLongItemNameException
* @throws TooManyException
*/
public function testNullableCode(mixed $param): void
{
$item = (new Item('test item', 2, 3))->setCode($param);
$this->assertNull($item->getCode());
$this->assertNull($item->getCodeHex());
}
/**
* Тестирует выброс исключения при установке слишком отрицательного акциза
*
* @covers \AtolOnline\Entities\Item::setCode
* @covers \AtolOnline\Exceptions\TooLongItemCodeException
* @throws TooLongItemNameException
* @throws TooHighPriceException
* @throws TooManyException
* @throws NegativeItemPriceException
* @throws EmptyItemNameException
* @throws NegativeItemQuantityException
*/
public function testTooLongItemCodeException(): void
{
$this->expectException(TooLongItemCodeException::class);
(new Item('test item', 2, 3))->setCode(Helpers::randomStr(Constraints::MAX_LENGTH_ITEM_CODE + 1));
}
}