2017-08-18 13:47:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2017-08-18 13:47:36 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-08-18 13:47:36 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-01-07 14:12:55 +01:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2018-09-19 02:07:24 +02:00
|
|
|
use stdClass;
|
2018-01-07 14:12:55 +01:00
|
|
|
|
2017-08-18 13:47:36 +02:00
|
|
|
/**
|
2018-09-19 02:07:24 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2017-08-18 13:47:36 +02:00
|
|
|
* @covers \Respect\Validation\Rules\Luhn
|
2018-09-19 02:07:24 +02:00
|
|
|
*
|
|
|
|
* @author Alexander Gorshkov <mazanax@yandex.ru>
|
|
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2017-08-18 13:47:36 +02:00
|
|
|
*/
|
2018-09-19 02:07:24 +02:00
|
|
|
final class LuhnTest extends RuleTestCase
|
2017-08-18 13:47:36 +02:00
|
|
|
{
|
2018-09-19 02:07:24 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-09-19 02:07:24 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2017-08-18 13:47:36 +02:00
|
|
|
{
|
|
|
|
$rule = new Luhn();
|
|
|
|
|
|
|
|
return [
|
2018-09-19 02:07:24 +02:00
|
|
|
'17 digits string' => [$rule, '2222400041240011'],
|
|
|
|
'16 digits string' => [$rule, '340316193809364'],
|
|
|
|
'integer' => [$rule, 6011000990139424],
|
2017-08-18 13:47:36 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:07:24 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-09-19 02:07:24 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2017-08-18 13:47:36 +02:00
|
|
|
{
|
|
|
|
$rule = new Luhn();
|
|
|
|
|
|
|
|
return [
|
2018-09-19 02:07:24 +02:00
|
|
|
'invalid string' => [$rule, '2222400041240021'],
|
|
|
|
'invalid integer' => [$rule, 340316193809334],
|
|
|
|
'float' => [$rule, 222240004124001.1],
|
|
|
|
'boolean true' => [$rule, true],
|
|
|
|
'boolean false' => [$rule, false],
|
|
|
|
'empty' => [$rule, ''],
|
|
|
|
'object' => [$rule, new stdClass()],
|
|
|
|
'array' => [$rule, [2222400041240011]],
|
2017-08-18 13:47:36 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|