Apply contribution guidelines to "AlwaysInvalid" rule

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
William Espindola 2018-06-01 13:00:28 -03:00 committed by Henrique Moody
parent 49131c87a7
commit 36be04c520
No known key found for this signature in database
GPG key ID: 221E9281655813A6
7 changed files with 57 additions and 42 deletions

View file

@ -2,7 +2,7 @@
- `AlwaysInvalid()`
Always return false.
Validates any input as invalid.
```php
v::alwaysInvalid()->validate($whatever); // false

View file

@ -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',

View file

@ -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;

View 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

View file

@ -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

View file

@ -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

View file

@ -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();