mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 14:52:17 +02:00
Apply contribution guidelines to "AlwaysInvalid" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
49131c87a7
commit
36be04c520
|
@ -2,7 +2,7 @@
|
|||
|
||||
- `AlwaysInvalid()`
|
||||
|
||||
Always return false.
|
||||
Validates any input as invalid.
|
||||
|
||||
```php
|
||||
v::alwaysInvalid()->validate($whatever); // false
|
||||
|
|
|
@ -13,10 +13,18 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class AlwaysInvalidException extends ValidationException
|
||||
/**
|
||||
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author William Espindola <oi@williamespindola.com.br>
|
||||
*/
|
||||
final class AlwaysInvalidException extends ValidationException
|
||||
{
|
||||
public const SIMPLE = 'simple';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::STANDARD => '{{name}} is always invalid',
|
||||
|
|
|
@ -13,8 +13,18 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class AlwaysInvalid extends AbstractRule
|
||||
/**
|
||||
* Validates any input as invalid.
|
||||
*
|
||||
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author William Espindola <oi@williamespindola.com.br>
|
||||
*/
|
||||
final class AlwaysInvalid extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($input): bool
|
||||
{
|
||||
return false;
|
||||
|
|
23
tests/integration/rules/alwaysInvalid.phpt
Normal file
23
tests/integration/rules/alwaysInvalid.phpt
Normal file
|
@ -0,0 +1,23 @@
|
|||
--FILE--
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AlwaysInvalidException;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::alwaysInvalid()->check('whatever');
|
||||
} catch (AlwaysInvalidException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::alwaysInvalid()->assert('');
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
"whatever" is always invalid
|
||||
- "" is always invalid
|
|
@ -1,17 +0,0 @@
|
|||
--TEST--
|
||||
alwaysInvalid()
|
||||
--FILE--
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AlwaysInvalidException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
Validator::alwaysInvalid()->check('whatever');
|
||||
} catch (AlwaysInvalidException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
"whatever" is always invalid
|
|
@ -1,17 +0,0 @@
|
|||
--TEST--
|
||||
alwaysInvalid()
|
||||
--FILE--
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AllOfException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
Validator::alwaysInvalid()->assert('');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage();
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
- "" is always invalid
|
|
@ -16,12 +16,18 @@ namespace Respect\Validation\Rules;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @group rule
|
||||
* @group rule
|
||||
*
|
||||
* @covers \Respect\Validation\Rules\AlwaysInvalid
|
||||
*
|
||||
* @author Andreas Wolf <dev@a-w.io>
|
||||
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author William Espindola <oi@williamespindola.com.br>
|
||||
*/
|
||||
class AlwaysInvalidTest extends TestCase
|
||||
final class AlwaysInvalidTest extends TestCase
|
||||
{
|
||||
public function providerForValidAlwaysInvalid()
|
||||
public function providerForInvalidInput(): array
|
||||
{
|
||||
return [
|
||||
[0],
|
||||
|
@ -37,9 +43,11 @@ class AlwaysInvalidTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForValidAlwaysInvalid
|
||||
* @test
|
||||
*
|
||||
* @dataProvider providerForInvalidInput
|
||||
*/
|
||||
public function testShouldValidateInputWhenItIsAValidAlwaysInvalid($input): void
|
||||
public function itShouldValidateInputWhenItIsAValidAlwaysInvalid($input): void
|
||||
{
|
||||
$rule = new AlwaysInvalid();
|
||||
|
||||
|
|
Loading…
Reference in a new issue