2012-07-22 15:17:31 +02:00
|
|
|
<?php
|
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Respect/Validation.
|
|
|
|
*
|
|
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-06-08 16:47:14 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
2012-07-22 15:17:31 +02:00
|
|
|
|
2017-11-04 11:21:40 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
|
|
|
* @group rule
|
2017-02-04 14:01:14 +01:00
|
|
|
* @covers \Respect\Validation\Rules\Base
|
|
|
|
* @covers \Respect\Validation\Exceptions\BaseException
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2017-11-04 11:21:40 +01:00
|
|
|
class BaseTest extends TestCase
|
2012-07-22 15:17:31 +02:00
|
|
|
{
|
|
|
|
protected $object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForBase
|
|
|
|
*/
|
2017-11-19 19:01:31 +01:00
|
|
|
public function testBase($base, $input): void
|
2012-07-22 15:17:31 +02:00
|
|
|
{
|
|
|
|
$object = new Base($base);
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertTrue($object->__invoke($input));
|
|
|
|
self::assertTrue($object->check($input));
|
|
|
|
self::assertTrue($object->assert($input));
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForInvalidBase
|
|
|
|
*/
|
2017-11-19 19:01:31 +01:00
|
|
|
public function testInvalidBase($base, $input): void
|
2012-07-22 15:17:31 +02:00
|
|
|
{
|
|
|
|
$object = new Base($base);
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertFalse($object->__invoke($input));
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForExceptionBase
|
2017-02-04 14:01:14 +01:00
|
|
|
* @expectedException \Respect\Validation\Exceptions\BaseException
|
2012-07-22 15:17:31 +02:00
|
|
|
*/
|
2017-11-19 19:01:31 +01:00
|
|
|
public function testExceptionBase($base, $input): void
|
2012-07-22 15:17:31 +02:00
|
|
|
{
|
|
|
|
$object = new Base($base);
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertTrue($object->__invoke($input));
|
|
|
|
self::assertTrue($object->assert($input));
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForCustomBase
|
|
|
|
*/
|
2017-11-19 19:01:31 +01:00
|
|
|
public function testCustomBase($base, $custom, $input): void
|
2012-07-22 15:17:31 +02:00
|
|
|
{
|
|
|
|
$object = new Base($base, $custom);
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertTrue($object->__invoke($input));
|
|
|
|
self::assertTrue($object->check($input));
|
|
|
|
self::assertTrue($object->assert($input));
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForBase()
|
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
[2, '011010001'],
|
|
|
|
[3, '0120122001'],
|
|
|
|
[8, '01234567520'],
|
|
|
|
[16, '012a34f5675c20d'],
|
|
|
|
[20, '012ah34f5675hic20dj'],
|
|
|
|
[50, '012ah34f56A75FGhic20dj'],
|
|
|
|
[62, 'Z01xSsg5675hic20dj'],
|
|
|
|
];
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForInvalidBase()
|
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
[2, ''],
|
|
|
|
[3, ''],
|
|
|
|
[8, ''],
|
|
|
|
[16, ''],
|
|
|
|
[20, ''],
|
|
|
|
[50, ''],
|
|
|
|
[62, ''],
|
|
|
|
[2, '01210103001'],
|
|
|
|
[3, '0120125f2001'],
|
|
|
|
[8, '01234dfZ567520'],
|
|
|
|
[16, '012aXS34f5675c20d'],
|
|
|
|
[20, '012ahZX34f5675hic20dj'],
|
|
|
|
[50, '012ahGZ34f56A75FGhic20dj'],
|
|
|
|
[61, 'Z01xSsg5675hic20dj'],
|
|
|
|
];
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForCustomBase()
|
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
[2, 'xy', 'xyyxyxxy'],
|
|
|
|
[3, 'pfg', 'gfpffp'],
|
|
|
|
];
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForExceptionBase()
|
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
[63, '01210103001'],
|
|
|
|
[125, '0120125f2001'],
|
|
|
|
];
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
}
|