2020-01-11 06:30:25 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-11-18 04:24:30 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-14 16:19:55 +00:00
|
|
|
|
declare(strict_types=1);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2021-11-23 17:30:54 +00:00
|
|
|
|
namespace AtolOnline\Tests;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2021-12-06 08:14:19 +00:00
|
|
|
|
use AtolOnline\Collections\EntityCollection;
|
2021-12-18 06:45:00 +00:00
|
|
|
|
use AtolOnline\Collections\Items;
|
|
|
|
|
use AtolOnline\Collections\Payments;
|
|
|
|
|
use AtolOnline\Collections\Vats;
|
|
|
|
|
use AtolOnline\Entities\Client;
|
|
|
|
|
use AtolOnline\Entities\Company;
|
|
|
|
|
use AtolOnline\Entities\Correction;
|
|
|
|
|
use AtolOnline\Entities\CorrectionInfo;
|
2020-04-17 12:10:50 +00:00
|
|
|
|
use AtolOnline\Entities\Entity;
|
2021-12-07 12:04:03 +00:00
|
|
|
|
use AtolOnline\Entities\Item;
|
|
|
|
|
use AtolOnline\Entities\Payment;
|
2021-12-18 06:45:00 +00:00
|
|
|
|
use AtolOnline\Entities\Receipt;
|
2021-12-07 12:04:03 +00:00
|
|
|
|
use AtolOnline\Entities\Vat;
|
2022-12-14 16:19:55 +00:00
|
|
|
|
use AtolOnline\Enums\CorrectionType;
|
|
|
|
|
use AtolOnline\Enums\PaymentType;
|
|
|
|
|
use AtolOnline\Enums\SnoType;
|
|
|
|
|
use AtolOnline\Enums\VatType;
|
2021-12-18 06:45:00 +00:00
|
|
|
|
use AtolOnline\Exceptions\EmptyCorrectionNumberException;
|
2021-12-07 12:04:03 +00:00
|
|
|
|
use AtolOnline\Exceptions\EmptyItemNameException;
|
2021-12-18 06:45:00 +00:00
|
|
|
|
use AtolOnline\Exceptions\EmptyItemsException;
|
|
|
|
|
use AtolOnline\Exceptions\InvalidCorrectionDateException;
|
|
|
|
|
use AtolOnline\Exceptions\InvalidEntityInCollectionException;
|
2021-12-07 12:04:03 +00:00
|
|
|
|
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;
|
2021-11-22 06:51:10 +00:00
|
|
|
|
use AtolOnline\Helpers;
|
2021-12-06 08:14:19 +00:00
|
|
|
|
use Exception;
|
2021-12-18 06:45:00 +00:00
|
|
|
|
use GuzzleHttp\Client as GuzzleClient;
|
2021-11-18 11:07:32 +00:00
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
|
use Illuminate\Support\Collection;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Базовый класс для тестов
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
class BasicTestCase extends TestCase
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
// Методы для управления тестами, использующими тестовый АТОЛ API
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-11-18 11:07:32 +00:00
|
|
|
|
* Проверяет наличие подключения к ресурсу по URL
|
|
|
|
|
*
|
|
|
|
|
* @param string $url
|
|
|
|
|
* @param int $code
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
protected function ping(string $url, int $code): bool
|
|
|
|
|
{
|
2021-11-19 10:42:14 +00:00
|
|
|
|
try {
|
2021-12-18 06:45:00 +00:00
|
|
|
|
$result = (new GuzzleClient([
|
2021-11-19 10:42:14 +00:00
|
|
|
|
'http_errors' => false,
|
|
|
|
|
'timeout' => 3,
|
|
|
|
|
]))->request('GET', $url);
|
|
|
|
|
} catch (GuzzleException) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-18 11:07:32 +00:00
|
|
|
|
return $result->getStatusCode() === $code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Проверяет доступность API мониторинга
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-11-18 11:07:32 +00:00
|
|
|
|
protected function isMonitoringOnline(): bool
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-11-18 11:07:32 +00:00
|
|
|
|
return $this->ping('https://testonline.atol.ru/api/auth/v1/gettoken', 400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-20 15:38:19 +00:00
|
|
|
|
* Пропускает текущий тест если API мониторинга недоступен
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
|
|
|
|
protected function skipIfMonitoringIsOffline(): void
|
|
|
|
|
{
|
|
|
|
|
if (!$this->isMonitoringOnline()) {
|
|
|
|
|
$this->markTestSkipped($this->getName() . ': Monitoring API is inaccessible. Skipping test.');
|
|
|
|
|
}
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2021-12-07 12:04:03 +00:00
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
// Дополнительные ассерты
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* Тестирует является ли объект приводимым к json-строке согласно схеме АТОЛ Онлайн
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @param Entity|EntityCollection $entity
|
2021-11-27 09:59:50 +00:00
|
|
|
|
* @param array|null $json_structure
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\Entity::__toString
|
2021-12-12 03:09:12 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\Entity::toArray
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\Entity::jsonSerialize
|
|
|
|
|
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
|
|
|
|
|
* @throws Exception
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function assertIsAtolable(Entity | EntityCollection $entity, ?array $json_structure = []): void
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-11-23 17:30:54 +00:00
|
|
|
|
$this->assertIsArray($entity->jsonSerialize());
|
2021-12-12 03:09:12 +00:00
|
|
|
|
$this->assertIsArray($entity->toArray());
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($entity->jsonSerialize(), $entity->toArray());
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->assertIsString((string)$entity);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$this->assertJson((string)$entity);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
if (!empty($json_structure)) {
|
|
|
|
|
$this->assertSame(json_encode($json_structure), (string)$entity);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2021-12-07 12:04:03 +00:00
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
// Ассерты проверки наследования
|
2021-12-06 06:15:47 +00:00
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2021-11-18 11:07:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует идентичность двух классов
|
|
|
|
|
*
|
2021-12-06 06:15:47 +00:00
|
|
|
|
* @param object|string $expected Ожидаемый класс
|
|
|
|
|
* @param object|string $actual Фактический класс
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function assertIsSameClass(object | string $expected, object | string $actual): void
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
2021-12-06 06:15:47 +00:00
|
|
|
|
$this->assertTrue($this->checkisSameClass($expected, $actual));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Проверяет идентичность двух классов
|
|
|
|
|
*
|
|
|
|
|
* @param object|string $class1
|
|
|
|
|
* @param object|string $class2
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
private function checkisSameClass(object | string $class1, object | string $class2): bool
|
2021-12-06 06:15:47 +00:00
|
|
|
|
{
|
|
|
|
|
return (is_object($class1) ? $class1::class : $class1)
|
|
|
|
|
=== (is_object($class2) ? $class2::class : $class2);
|
2021-11-18 11:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует наследование класса (объекта) от указанных классов
|
|
|
|
|
*
|
2021-12-06 06:15:47 +00:00
|
|
|
|
* @param array $expected Массив ожидаемых имён классов-родителей
|
|
|
|
|
* @param object|string $actual Объект или имя класса для проверки
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function assertExtendsClasses(array $expected, object | string $actual): void
|
2021-12-06 06:15:47 +00:00
|
|
|
|
{
|
|
|
|
|
$this->assertTrue($this->checkExtendsClasses($expected, $actual));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Проверяет наследование класса (объекта) от указанных классов
|
|
|
|
|
*
|
|
|
|
|
* @param string[] $parents Имена классов-родителей
|
|
|
|
|
* @param object|string $class Объект или имя класса для проверки
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
private function checkExtendsClasses(array $parents, object | string $class): bool
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
2021-12-06 06:15:47 +00:00
|
|
|
|
return !empty(array_intersect($parents, is_object($class) ? class_parents($class) : [$class]));
|
2021-11-18 11:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует имплементацию классом (объектом) указанных интерфейсов
|
|
|
|
|
*
|
2021-12-06 06:15:47 +00:00
|
|
|
|
* @param string[] $expected Массив ожидаемых имён интерфейсов
|
|
|
|
|
* @param object|string $actual Объект или имя класса для проверки
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function assertImplementsInterfaces(array $expected, object | string $actual): void
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
2021-12-06 06:15:47 +00:00
|
|
|
|
$this->assertTrue($this->checkImplementsInterfaces($expected, $actual));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Проверяет имплементацию классом (объектом) указанных интерфейсов
|
|
|
|
|
*
|
|
|
|
|
* @param string[] $interfaces Имена классов-интерфейсов
|
|
|
|
|
* @param object|string $class Объект или имя класса для проверки
|
|
|
|
|
* @see https://www.php.net/manual/ru/function.class-implements.php
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
private function checkImplementsInterfaces(array $interfaces, object | string $class): bool
|
2021-12-06 06:15:47 +00:00
|
|
|
|
{
|
|
|
|
|
return !empty(array_intersect($interfaces, is_object($class) ? class_implements($class) : [$class]));
|
2021-11-18 11:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует использование классом (объектом) указанных трейтов
|
|
|
|
|
*
|
2021-12-06 06:15:47 +00:00
|
|
|
|
* @param string[] $expected Массив ожидаемых имён трейтов
|
|
|
|
|
* @param object|string $actual Объект или имя класса для проверки
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function assertUsesTraits(array $expected, object | string $actual): void
|
2021-12-06 06:15:47 +00:00
|
|
|
|
{
|
|
|
|
|
$this->assertTrue($this->checkUsesTraits($expected, $actual));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Проверяет использование классом (объектом) указанных трейтов (исключает родителей)
|
|
|
|
|
*
|
|
|
|
|
* @param string[] $traits Массив ожидаемых имён трейтов
|
|
|
|
|
* @param object|string $class Объект или имя класса для проверки
|
|
|
|
|
* @return bool
|
|
|
|
|
* @see https://www.php.net/manual/ru/function.class-uses.php#110752
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
private function checkUsesTraits(array $traits, object | string $class): bool
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
2021-12-06 06:15:47 +00:00
|
|
|
|
$found_traits = [];
|
|
|
|
|
$check_class = is_object($class) ? $class::class : $class;
|
|
|
|
|
do {
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$found_traits = array_merge(class_uses($check_class), $found_traits);
|
2021-12-06 06:15:47 +00:00
|
|
|
|
} while ($check_class = get_parent_class($check_class));
|
|
|
|
|
foreach ($found_traits as $trait => $same) {
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$found_traits = array_merge(class_uses($trait), $found_traits);
|
2021-12-06 06:15:47 +00:00
|
|
|
|
}
|
|
|
|
|
return !empty(array_intersect(array_unique($found_traits), $traits));
|
2021-11-18 11:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует, является ли объект коллекцией
|
|
|
|
|
*
|
2021-12-06 06:15:47 +00:00
|
|
|
|
* @param mixed $value
|
2021-11-18 11:07:32 +00:00
|
|
|
|
*/
|
2021-12-06 06:15:47 +00:00
|
|
|
|
public function assertIsCollection(mixed $value): void
|
2021-11-18 11:07:32 +00:00
|
|
|
|
{
|
2021-12-06 06:15:47 +00:00
|
|
|
|
$this->assertIsObject($value);
|
|
|
|
|
$this->assertIsIterable($value);
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$this->checkisSameClass(Collection::class, $value) ||
|
|
|
|
|
$this->checkExtendsClasses([Collection::class], $value)
|
|
|
|
|
);
|
2021-11-18 11:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-07 12:04:03 +00:00
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
// Провайдеры данных для прогона тестов
|
2021-11-23 17:30:54 +00:00
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Провайдер строк, которые приводятся к null
|
|
|
|
|
*
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @return array
|
2021-11-23 17:30:54 +00:00
|
|
|
|
*/
|
|
|
|
|
public function providerNullableStrings(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
[''],
|
|
|
|
|
[' '],
|
|
|
|
|
[null],
|
|
|
|
|
["\n\r\t"],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* Провайдер валидных телефонов
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @return array<array<string, string>>
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-11-18 04:24:30 +00:00
|
|
|
|
public function providerValidPhones(): array
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-11-18 04:24:30 +00:00
|
|
|
|
return [
|
|
|
|
|
['+79991234567', '+79991234567'],
|
|
|
|
|
['79991234567', '+79991234567'],
|
|
|
|
|
['89991234567', '+89991234567'],
|
|
|
|
|
['+7 999 123 45 67', '+79991234567'],
|
|
|
|
|
['+7 (999) 123-45-67', '+79991234567'],
|
|
|
|
|
["+7 %(?9:9\"9')abc\r123\n45\t67\0", '+79991234567'],
|
|
|
|
|
];
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2021-11-23 17:30:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* Провайдер телефонов, которые приводятся к null
|
|
|
|
|
*
|
|
|
|
|
* @return array<array<string>>
|
|
|
|
|
*/
|
|
|
|
|
public function providerNullablePhones(): array
|
|
|
|
|
{
|
|
|
|
|
return array_merge(
|
|
|
|
|
$this->providerNullableStrings(),
|
|
|
|
|
[
|
|
|
|
|
[Helpers::randomStr(10, false)],
|
|
|
|
|
["asdfgvs \n\rtt\t*/(*&%^*$%"],
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 14:24:15 +00:00
|
|
|
|
/**
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* Провайдер валидных email-ов
|
2020-05-29 14:24:15 +00:00
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @return array<array<string>>
|
2020-05-29 14:24:15 +00:00
|
|
|
|
*/
|
2021-11-18 04:24:30 +00:00
|
|
|
|
public function providerValidEmails(): array
|
2020-05-29 14:24:15 +00:00
|
|
|
|
{
|
2021-11-18 04:24:30 +00:00
|
|
|
|
return [
|
|
|
|
|
['abc@mail.com'],
|
|
|
|
|
['abc-d@mail.com'],
|
|
|
|
|
['abc.def@mail.com'],
|
|
|
|
|
['abc.def@mail.org'],
|
|
|
|
|
['abc.def@mail-archive.com'],
|
|
|
|
|
];
|
2020-05-29 14:24:15 +00:00
|
|
|
|
}
|
2021-11-23 17:30:54 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Провайдер невалидных email-ов
|
|
|
|
|
*
|
|
|
|
|
* @return array<array<string>>
|
|
|
|
|
*/
|
|
|
|
|
public function providerInvalidEmails(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
['@example'],
|
|
|
|
|
[Helpers::randomStr(15)],
|
|
|
|
|
['@example.com'],
|
|
|
|
|
['abc.def@mail'],
|
|
|
|
|
['.abc@mail.com'],
|
|
|
|
|
['example@example'],
|
|
|
|
|
['abc..def@mail.com'],
|
|
|
|
|
['abc.def@mail..com'],
|
|
|
|
|
['abc.def@mail#archive.com'],
|
|
|
|
|
];
|
|
|
|
|
}
|
2021-12-07 12:04:03 +00:00
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
// Генераторы тестовых объектов
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Генерирует массив тестовых объектов предметов расчёта
|
|
|
|
|
*
|
|
|
|
|
* @param int $count
|
|
|
|
|
* @return Item[]
|
|
|
|
|
* @throws EmptyItemNameException
|
|
|
|
|
* @throws NegativeItemPriceException
|
|
|
|
|
* @throws NegativeItemQuantityException
|
|
|
|
|
* @throws TooHighItemPriceException
|
|
|
|
|
* @throws TooLongItemNameException
|
|
|
|
|
* @throws TooManyException
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected function generateItemObjects(int $count = 1): iterable
|
2021-12-07 12:04:03 +00:00
|
|
|
|
{
|
|
|
|
|
for ($i = 0; $i < abs($count); ++$i) {
|
2022-12-14 16:19:55 +00:00
|
|
|
|
yield new Item(Helpers::randomStr(), random_int(1, 100), random_int(1, 10));
|
2021-12-07 12:04:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Генерирует массив тестовых объектов оплаты
|
|
|
|
|
*
|
|
|
|
|
* @param int $count
|
|
|
|
|
* @return Payment[]
|
|
|
|
|
* @throws NegativePaymentSumException
|
|
|
|
|
* @throws TooHighPaymentSumException
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected function generatePaymentObjects(int $count = 1): iterable
|
2021-12-07 12:04:03 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$types = PaymentType::cases();
|
2021-12-07 12:04:03 +00:00
|
|
|
|
for ($i = 0; $i < abs($count); ++$i) {
|
2022-12-14 16:19:55 +00:00
|
|
|
|
yield new Payment(
|
|
|
|
|
$types[random_int(0, count($types) - 1)],
|
2021-12-07 12:04:03 +00:00
|
|
|
|
random_int(1, 100) * 2 / 3
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Генерирует массив тестовых объектов ставок НДС
|
|
|
|
|
*
|
|
|
|
|
* @param int $count
|
|
|
|
|
* @return Vat[]
|
|
|
|
|
* @throws InvalidEnumValueException
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected function generateVatObjects(int $count = 1): iterable
|
2021-12-07 12:04:03 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$types = VatType::cases();
|
2021-12-07 12:04:03 +00:00
|
|
|
|
for ($i = 0; $i < abs($count); ++$i) {
|
2022-12-14 16:19:55 +00:00
|
|
|
|
yield new Vat(
|
|
|
|
|
$types[random_int(0, count($types) - 1)],
|
2021-12-07 12:04:03 +00:00
|
|
|
|
random_int(1, 100) * 2 / 3
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-18 06:45:00 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает валидный тестовый объект чека прихода
|
|
|
|
|
*
|
|
|
|
|
* @return Receipt
|
|
|
|
|
* @throws EmptyItemNameException
|
|
|
|
|
* @throws EmptyItemsException
|
|
|
|
|
* @throws InvalidEntityInCollectionException
|
|
|
|
|
* @throws NegativeItemPriceException
|
|
|
|
|
* @throws NegativeItemQuantityException
|
|
|
|
|
* @throws NegativePaymentSumException
|
|
|
|
|
* @throws TooHighItemPriceException
|
|
|
|
|
* @throws TooHighPaymentSumException
|
|
|
|
|
* @throws TooLongItemNameException
|
|
|
|
|
* @throws TooManyException
|
|
|
|
|
*/
|
|
|
|
|
protected function newReceipt(): Receipt
|
|
|
|
|
{
|
|
|
|
|
return new Receipt(
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new Client('John Doe', '+79501234567', 'john@example.com', '1234567890'),
|
|
|
|
|
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@example.com'),
|
2021-12-18 06:45:00 +00:00
|
|
|
|
new Items($this->generateItemObjects(2)),
|
|
|
|
|
new Payments($this->generatePaymentObjects())
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает валидный тестовый объект чека
|
|
|
|
|
*
|
|
|
|
|
* @return Correction
|
|
|
|
|
* @throws InvalidEntityInCollectionException
|
|
|
|
|
* @throws InvalidEnumValueException
|
|
|
|
|
* @throws NegativePaymentSumException
|
|
|
|
|
* @throws TooHighPaymentSumException
|
|
|
|
|
* @throws EmptyCorrectionNumberException
|
|
|
|
|
* @throws InvalidCorrectionDateException
|
|
|
|
|
*/
|
|
|
|
|
protected function newCorrection(): Correction
|
|
|
|
|
{
|
|
|
|
|
return new Correction(
|
2022-12-14 16:19:55 +00:00
|
|
|
|
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@example.com'),
|
|
|
|
|
new CorrectionInfo(CorrectionType::SELF, '01.01.2021', Helpers::randomStr()),
|
2021-12-18 06:45:00 +00:00
|
|
|
|
new Payments($this->generatePaymentObjects(2)),
|
|
|
|
|
new Vats($this->generateVatObjects(2)),
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-11-23 17:30:54 +00:00
|
|
|
|
}
|