2020-10-04 13:56:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2020-10-04 13:56:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
2020-10-04 13:56:42 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
|
|
use stdClass;
|
|
|
|
|
|
|
|
use function acos;
|
|
|
|
use function sqrt;
|
|
|
|
|
|
|
|
use const NAN;
|
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
#[Group('rule')]
|
|
|
|
#[CoversClass(Decimal::class)]
|
2020-10-04 13:56:42 +02:00
|
|
|
final class DecimalTest extends RuleTestCase
|
|
|
|
{
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{Decimal, mixed}> */
|
|
|
|
public static function providerForValidInput(): iterable
|
2020-10-04 13:56:42 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[new Decimal(0), 1],
|
|
|
|
[new Decimal(1), 1.0],
|
|
|
|
[new Decimal(2), 1.00],
|
|
|
|
[new Decimal(3), 1.000],
|
|
|
|
[new Decimal(2), 1.000],
|
|
|
|
[new Decimal(1), 1.000],
|
|
|
|
[new Decimal(2), '27990.50'],
|
|
|
|
[new Decimal(1), 1.1],
|
|
|
|
[new Decimal(1), '1.3'],
|
|
|
|
[new Decimal(1), 1.50],
|
2022-06-29 22:00:44 +02:00
|
|
|
[new Decimal(1), 10.0],
|
|
|
|
[new Decimal(2), 10.00],
|
|
|
|
[new Decimal(1), 10.50],
|
|
|
|
[new Decimal(2), 10.50],
|
2020-10-04 13:56:42 +02:00
|
|
|
[new Decimal(3), '1.000'],
|
|
|
|
[new Decimal(3), 123456789.001],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{Decimal, mixed}> */
|
|
|
|
public static function providerForInvalidInput(): iterable
|
2020-10-04 13:56:42 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[new Decimal(1), '1.50'],
|
|
|
|
[new Decimal(1), '27990.50'],
|
|
|
|
[new Decimal(0), 2.0],
|
|
|
|
[new Decimal(0), acos(1.01)],
|
|
|
|
[new Decimal(0), sqrt(-1)],
|
|
|
|
[new Decimal(0), NAN],
|
|
|
|
[new Decimal(0), -NAN],
|
|
|
|
[new Decimal(0), false],
|
|
|
|
[new Decimal(0), true],
|
|
|
|
[new Decimal(0), []],
|
|
|
|
[new Decimal(0), new stdClass()],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|