mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 03:42:25 +02:00
Apply contribution guidelines to "Fibonacci" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
4200704bdc
commit
69a01249da
|
@ -13,8 +13,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class FibonacciException extends ValidationException
|
||||
/**
|
||||
* @author Danilo Correa <danilosilva87@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author Samuel Heinzmann <samuel.heinzmann@swisscom.com>
|
||||
*/
|
||||
final class FibonacciException extends ValidationException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::STANDARD => '{{name}} must be a valid Fibonacci number',
|
||||
|
|
|
@ -13,10 +13,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use function is_numeric;
|
||||
|
||||
/**
|
||||
* @author Samuel Heinzmann <samuel.heinzman@swisscom.com>
|
||||
* Validates whether the input follows the Fibonacci integer sequence.
|
||||
*
|
||||
* @author Danilo Correa <danilosilva87@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author Samuel Heinzmann <samuel.heinzmann@swisscom.com>
|
||||
*/
|
||||
class Fibonacci extends AbstractRule
|
||||
final class Fibonacci extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
37
tests/integration/rules/fibonacci.phpt
Normal file
37
tests/integration/rules/fibonacci.phpt
Normal file
|
@ -0,0 +1,37 @@
|
|||
--FILE--
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\FibonacciException;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::fibonacci()->check(4);
|
||||
} catch (FibonacciException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::fibonacci())->check(5);
|
||||
} catch (FibonacciException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::fibonacci()->assert(16);
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::fibonacci())->assert(21);
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
4 must be a valid Fibonacci number
|
||||
5 must not be a valid Fibonacci number
|
||||
- 16 must be a valid Fibonacci number
|
||||
- 21 must not be a valid Fibonacci number
|
|
@ -16,11 +16,19 @@ namespace Respect\Validation\Rules;
|
|||
use Respect\Validation\Test\RuleTestCase;
|
||||
|
||||
/**
|
||||
* @group rule
|
||||
* @group rule
|
||||
*
|
||||
* @covers \Respect\Validation\Rules\Fibonacci
|
||||
*
|
||||
* @author Danilo Correa <danilosilva87@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author Samuel Heinzmann <samuel.heinzmann@swisscom.com>
|
||||
*/
|
||||
class FibonacciTest extends RuleTestCase
|
||||
final class FibonacciTest extends RuleTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerForValidInput(): array
|
||||
{
|
||||
$rule = new Fibonacci();
|
||||
|
@ -42,6 +50,9 @@ class FibonacciTest extends RuleTestCase
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerForInvalidInput(): array
|
||||
{
|
||||
$rule = new Fibonacci();
|
||||
|
|
Loading…
Reference in a new issue