2010-10-18 06:26:02 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2010-10-18 06:26:02 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-09-06 21:57:57 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2017-11-04 11:21:40 +01:00
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
2018-09-06 21:57:57 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2018-09-24 21:48:41 +02:00
|
|
|
* @covers \Respect\Validation\Rules\AbstractFilterRule
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\Digit
|
2018-09-06 21:57:57 +02:00
|
|
|
*
|
2023-02-13 05:59:06 +01:00
|
|
|
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
|
2018-09-06 21:57:57 +02:00
|
|
|
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
* @author Nick Lombard <github@jigsoft.co.za>
|
|
|
|
* @author Pascal Borreli <pascal@borreli.com>
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2018-09-06 21:57:57 +02:00
|
|
|
final class DigitTest extends RuleTestCase
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2018-09-06 21:57:57 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-09-06 21:57:57 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2018-09-06 21:57:57 +02:00
|
|
|
'positive integer' => [new Digit(), 165],
|
|
|
|
'positive string-integer' => [new Digit(), '01650'],
|
|
|
|
'positive string-integer with one exception' => [new Digit('-'), '16-50'],
|
|
|
|
'positive string-integer with multiple exceptions' => [new Digit('.-'), '16-5.0'],
|
|
|
|
'only exceptions' => [new Digit('!@#$%^&*(){}'), '!@#$%^&*(){}'],
|
2018-09-24 21:48:41 +02:00
|
|
|
'multiple exceptions' => [new Digit('.', '-'), '012.071.070-69'],
|
2018-09-06 21:57:57 +02:00
|
|
|
'float' => [new Digit(), 1.0],
|
|
|
|
'boolean true' => [new Digit(), true],
|
|
|
|
'octal' => [new Digit(), 01],
|
|
|
|
'string-octal' => [new Digit(), '01'],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
|
|
|
|
2018-09-06 21:57:57 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-09-06 21:57:57 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2018-09-06 21:57:57 +02:00
|
|
|
'empty' => [new Digit(), ''],
|
|
|
|
'with spaces' => [new Digit(), '16 50'],
|
|
|
|
'with tabs' => [new Digit(), "1\t1"],
|
|
|
|
'with newlines' => [new Digit(), "1\n1"],
|
|
|
|
'null' => [new Digit(), null],
|
|
|
|
'with non-numeric' => [new Digit(), '16-50'],
|
|
|
|
'alphabetic' => [new Digit(), 'a'],
|
|
|
|
'alphanumeric' => [new Digit(), 'a1'],
|
|
|
|
'negative integer' => [new Digit(), -12],
|
|
|
|
'negative string-integer' => [new Digit(), '-12'],
|
|
|
|
'float-string' => [new Digit(), '1.0'],
|
|
|
|
'negative float' => [new Digit(), -1.1],
|
|
|
|
'negative string-float' => [new Digit(), '-1.1'],
|
|
|
|
'boolean false' => [new Digit(), false],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
2011-02-10 21:49:48 +01:00
|
|
|
}
|