respect-validation/tests/unit/Rules/FilterVarTest.php

70 lines
1.8 KiB
PHP
Raw Normal View History

2015-01-26 13:10:54 +01:00
<?php
2015-06-08 16:47:14 +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.
*/
declare(strict_types=1);
2015-01-26 13:10:54 +01:00
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use const FILTER_FLAG_QUERY_REQUIRED;
use const FILTER_VALIDATE_BOOLEAN;
use const FILTER_VALIDATE_EMAIL;
use const FILTER_VALIDATE_FLOAT;
use const FILTER_VALIDATE_INT;
use const FILTER_VALIDATE_URL;
2017-11-04 11:21:40 +01:00
2015-01-26 13:10:54 +01:00
/**
* @group rule
*
2017-02-04 14:01:14 +01:00
* @covers \Respect\Validation\Rules\FilterVar
*
* @author Gabriel Caruso <carusogabriel34@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
2015-01-26 13:10:54 +01:00
*/
final class FilterVarTest extends RuleTestCase
2015-01-26 13:10:54 +01:00
{
/**
* @test
*
2017-02-04 14:01:14 +01:00
* @expectedException \Respect\Validation\Exceptions\ComponentException
2015-01-26 13:10:54 +01:00
* @expectedExceptionMessage Cannot accept the given filter
*/
public function itShouldThrowsExceptionWhenFilterIsNotValid(): void
2015-01-26 13:10:54 +01:00
{
new FilterVar(FILTER_SANITIZE_EMAIL);
}
/**
* {@inheritdoc}
*/
public function providerForValidInput(): array
2015-01-26 13:10:54 +01:00
{
return [
[new FilterVar(FILTER_VALIDATE_INT), '12345'],
[new FilterVar(FILTER_VALIDATE_EMAIL), 'example@example.com'],
[new FilterVar(FILTER_VALIDATE_FLOAT), 1.5],
[new FilterVar(FILTER_VALIDATE_BOOLEAN), 'On'],
[new FilterVar(FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED), 'http://example.com?foo=bar'],
];
2015-01-26 13:10:54 +01:00
}
/**
* {@inheritdoc}
*/
public function providerForInvalidInput(): array
2015-01-26 13:10:54 +01:00
{
return [
[new FilterVar(FILTER_VALIDATE_INT), 1.4],
[new FilterVar(FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED), 'http://example.com'],
];
2015-01-26 13:10:54 +01:00
}
}