Туча доработок

- класс `PayingAgent`, покрытый тестами
- новые константы для тегов ФФД 1.05 `Ffd105Tags`
- `Entity::jsonSerialize()` object -> array (again)
- `TooManyException::$max` int -> float
- тесты по psr-4, потому что почему бы и нет
- некоторые провайдеры вынесены в `BasicTestCase`
- улучшен тест покупателя
This commit is contained in:
2021-11-24 01:30:54 +08:00
parent b5a01debd2
commit 42d194116f
40 changed files with 622 additions and 192 deletions

View File

@@ -0,0 +1,123 @@
<?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;
use AtolOnline\Helpers;
/**
* Набор тестов для проверки работы функций-хелперов
*/
class HelpersTest extends BasicTestCase
{
/**
* Провайдер копеек для перевода в рубли
*
* @return array<array<int|null, float>>
*/
public function providerKopeksToRubles(): array
{
return [
[null, 0],
[0, 0],
[1, 0.01],
[12, 0.12],
[123, 1.23],
[1234, 12.34],
[12345, 123.45],
[-1, 0.01],
[-12, 0.12],
[-123, 1.23],
[-1234, 12.34],
[-12345, 123.45],
];
}
/**
* Провайдер рублей для перевода в копейки
*
* @return array<array<float|null, int>>
*/
public function providerRublesToKopeks(): array
{
return [
[null, 0],
[0, 0],
[0.01, 1],
[0.12, 12],
[1.23, 123],
[12.34, 1234],
[123.45, 12345],
[-0.01, 1],
[-0.12, 12],
[-1.23, 123],
[-12.34, 1234],
[-123.45, 12345],
];
}
/**
* Провайдер для тестирования генерации рандомной строки
*
* @return array<array<int, int>>
*/
public function providerRandomStr(): array
{
return [
[0, 0],
[1, 1],
[5, 5],
[-1, 1],
[-5, 5],
];
}
//------------------------------------------------------------------------------------------------------------------
/**
* Тестирует перевод копеек в рубли
*
* @dataProvider providerKopeksToRubles
* @covers \AtolOnline\Helpers::KopToRub
*/
public function testKopeksToRubles(?int $kopeks, float $rubles): void
{
$result = Helpers::KopToRub($kopeks);
$this->assertIsFloat($result);
$this->assertEquals($result, $rubles);
}
/**
* Тестирует перевод копеек в рубли
*
* @dataProvider providerRublesToKopeks
* @covers \AtolOnline\Helpers::RubToKop
*/
public function testRublesToKopeks(?float $rubles, int $kopeks): void
{
$result = Helpers::RubToKop($rubles);
$this->assertIsInt($result);
$this->assertEquals($result, $kopeks);
}
/**
* Тестирует длину рандомной строки
*
* @param int $input
* @param int $output
* @dataProvider providerRandomStr
*/
public function testRandomString(int $input, int $output): void
{
$result = Helpers::randomStr($input);
$this->assertIsString($result);
$this->assertEquals($output, strlen($result));
// тестировать на наличие цифр быссмысленно
}
}