2021-11-18 04:24:30 +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)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2021-11-23 17:30:54 +00:00
|
|
|
|
namespace AtolOnline\Tests;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
|
|
|
|
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
|
2021-11-27 16:58:05 +00:00
|
|
|
|
* @covers \AtolOnline\Helpers::toRub
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testKopeksToRubles(?int $kopeks, float $rubles): void
|
|
|
|
|
{
|
2021-11-27 16:58:05 +00:00
|
|
|
|
$result = Helpers::toRub($kopeks);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->assertIsFloat($result);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($result, $rubles);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует перевод копеек в рубли
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider providerRublesToKopeks
|
2021-11-27 16:58:05 +00:00
|
|
|
|
* @covers \AtolOnline\Helpers::toKop
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testRublesToKopeks(?float $rubles, int $kopeks): void
|
|
|
|
|
{
|
2021-11-27 16:58:05 +00:00
|
|
|
|
$result = Helpers::toKop($rubles);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->assertIsInt($result);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($result, $kopeks);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует длину рандомной строки
|
|
|
|
|
*
|
|
|
|
|
* @param int $input
|
|
|
|
|
* @param int $output
|
|
|
|
|
* @dataProvider providerRandomStr
|
|
|
|
|
*/
|
|
|
|
|
public function testRandomString(int $input, int $output): void
|
|
|
|
|
{
|
|
|
|
|
$result = Helpers::randomStr($input);
|
|
|
|
|
$this->assertIsString($result);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($output, strlen($result));
|
2021-11-18 04:24:30 +00:00
|
|
|
|
// тестировать на наличие цифр быссмысленно
|
|
|
|
|
}
|
2021-11-23 17:30:54 +00:00
|
|
|
|
}
|