respect-validation/tests/unit/Validators/FactorTest.php
Alexandre Gomes Gaigalas d9cdc118b2 Introduce REUSE compliance
This commit introduces REUSE compliance by annotating all files
with SPDX information and placing the reused licences in the
LICENSES folder.

We additionally removed the docheader tool which is made obsolete
by this change.

The main LICENSE and copyright text of the project is now not under
my personal name anymore, and it belongs to "The Respect Project
Contributors" instead.

This change restores author names to several files, giving the
appropriate attribution for contributions.
2026-01-21 06:28:11 +00:00

108 lines
4.9 KiB
PHP

<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-FileContributor: Danilo Correa <danilosilva87@gmail.com>
* SPDX-FileContributor: David Meister <thedavidmeister@gmail.com>
* SPDX-FileContributor: Gabriel Caruso <carusogabriel34@gmail.com>
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
namespace Respect\Validation\Validators;
use DateTime;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
use function mt_getrandmax;
use function mt_rand;
use function uniqid;
use const PHP_INT_MAX;
#[Group('validator')]
#[CoversClass(Factor::class)]
final class FactorTest extends RuleTestCase
{
/** @return iterable<array{Factor, mixed}> */
public static function providerForValidInput(): iterable
{
return [
'1 is factor 1' => [new Factor(1), 1],
'1 is factor 2' => [new Factor(2), 1],
'3 is factor 3' => [new Factor(3), 3],
'4 is factor 2' => [new Factor(4), 2],
'4 is factor 4' => [new Factor(4), 4],
'5 is factor 1' => [new Factor(5), 1],
'5 is factor 5' => [new Factor(5), 5],
'6 is factor 1' => [new Factor(6), 1],
'6 is factor 2' => [new Factor(6), 2],
'0 is factor 0' => [new Factor(0), 0],
'0 is factor 1' => [new Factor(0), 1],
'0 is factor mt_rand()' => [new Factor(0), mt_rand()],
'-0 is factor 1' => [new Factor(-0), 1],
'-6 is factor 2' => [new Factor(-6), 2],
'-3 is factor 3' => [new Factor(-3), 3],
'-5 is factor 1' => [new Factor(-5), 1],
'-0 is factor mt_rand' => [new Factor(-0), mt_rand()],
'-5 is factor -1' => [new Factor(-5), -1],
'-6 is factor -1' => [new Factor(-6), -1],
'-3 is factor -3' => [new Factor(-3), -3],
'-0 is factor -mt_rand()' => [new Factor(-0), -mt_rand()],
'6 is factor \'1\'' => [new Factor(6), '1'],
'6 is factor \'2\'' => [new Factor(6), '2'],
'4 is factor 2.00' => [new Factor(4), 2.0],
'-0 is factor -5.000000' => [new Factor(-0), -5.000000],
'-0 is factor (float) - mt_rand()' => [new Factor(-0), (float) -mt_rand()],
];
}
/** @return iterable<array{Factor, mixed}> */
public static function providerForInvalidInput(): iterable
{
return [
'3 is not factor 2' => [new Factor(3), 2],
'4 is not factor 3' => [new Factor(4), 3],
'5 is not factor 2' => [new Factor(5), 2],
'5 is not factor 3' => [new Factor(5), 3],
'5 is not factor 4' => [new Factor(5), 4],
'1 is not factor 0' => [new Factor(1), 0],
'2 is not factor 0' => [new Factor(2), 0],
'-2 is not factor 0' => [new Factor(-2), 0],
'-5 is not factor 4' => [new Factor(-5), 4],
'-4 is not factor 3' => [new Factor(-4), 3],
'-3 is not factor -2' => [new Factor(-3), -2],
'-5 is not factor -2' => [new Factor(-5), -2],
'-2 is not factor -0' => [new Factor(-2), -0],
'-2 is not factor \'-0.0000\'' => [new Factor(-2), '-0.0000'],
'-2 is not factor 0.00' => [new Factor(-2), 0.00],
'3 is not factor 2.0' => [new Factor(3), 2.0],
'5 is not factor 2.000000' => [new Factor(5), 2.000000],
'mt_rand is not factor 0.5' => [new Factor(mt_rand()), 0.5],
'mt_rand is not factor 1.5' => [new Factor(mt_rand()), 1.5],
'mt_rand is not factor -0.5' => [new Factor(mt_rand()), -0.5],
'mt_rand is not factor -1.5' => [new Factor(mt_rand()), -1.5],
'mt_rand is not factor PHP_INT_MAX + 1' => [new Factor(mt_rand()), PHP_INT_MAX + 1],
'mt_rand is not factor calc' => [new Factor(mt_rand()), mt_rand(1, mt_getrandmax() - 1) / mt_getrandmax()],
'mt_rand is not factor -calc' => [
new Factor(mt_rand()),
-(mt_rand(1, mt_getrandmax() - 1) / mt_getrandmax()),
],
'mt_rand is not factor \'a\'' => [new Factor(mt_rand()), 'a'],
'mt_rand is not factor \'foo\'' => [new Factor(mt_rand()), 'foo'],
'mt_rand is not factor uniqid(\'a\')' => [new Factor(mt_rand()), uniqid('a')],
'mt_rand is not factor []' => [new Factor(mt_rand()), []],
'mt_rand is not factor stdClass' => [new Factor(mt_rand()), new stdClass()],
'mt_rand is not factor Datetime' => [new Factor(mt_rand()), new DateTime()],
'mt_rand is not factor null' => [new Factor(mt_rand()), null],
'mt_rand is not factor true' => [new Factor(mt_rand()), true],
'mt_rand is not factor false' => [new Factor(mt_rand()), false],
];
}
}