2021-11-18 04:24:30 +00:00
|
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
* @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));
|
|
|
|
|
// тестировать на наличие цифр быссмысленно
|
|
|
|
|
}
|
2021-11-23 17:30:54 +00:00
|
|
|
|
}
|