respect-validation/tests/unit/Rules/PunctTest.php
Henrique Moody c80524b457
Method assert() should not have a return value
One this method should throw an exception when the input is not valid,
returning `TRUE` when it succeeds is not really consistent.
2018-01-28 17:38:40 +01:00

104 lines
2.5 KiB
PHP

<?php
/*
* 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.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use PHPUnit\Framework\TestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Punct
* @covers \Respect\Validation\Exceptions\PunctException
*/
class PunctTest extends TestCase
{
/**
* @dataProvider providerForValidPunct
*/
public function testValidDataWithPunctShouldReturnTrue($validPunct, $additional = ''): void
{
$validator = new Punct($additional);
self::assertTrue($validator->validate($validPunct));
}
/**
* @dataProvider providerForInvalidPunct
* @expectedException \Respect\Validation\Exceptions\PunctException
*/
public function testInvalidPunctShouldFailAndThrowPunctException($invalidPunct, $additional = ''): void
{
$validator = new Punct($additional);
self::assertFalse($validator->validate($invalidPunct));
$validator->assert($invalidPunct);
}
/**
* @dataProvider providerForInvalidParams
* @expectedException \Respect\Validation\Exceptions\ComponentException
*/
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
{
$validator = new Punct($additional);
}
/**
* @dataProvider providerAdditionalChars
*/
public function testAdditionalCharsShouldBeRespected($additional, $query): void
{
$validator = new Punct($additional);
self::assertTrue($validator->validate($query));
}
public function providerAdditionalChars()
{
return [
['abc123 ', '!@#$%^&*(){} abc 123'],
["abc123 \t\n", "[]?+=/\\-_|\"',<>. \t \n abc 123"],
];
}
public function providerForInvalidParams()
{
return [
[new \stdClass()],
[[]],
[0x2],
];
}
public function providerForValidPunct()
{
return [
['.'],
[',;:'],
['-@#$*'],
['()[]{}'],
];
}
public function providerForInvalidPunct()
{
return [
[''],
['16-50'],
['a'],
[' '],
['Foo'],
['12.1'],
['-12'],
[-12],
['( )_{}'],
];
}
}