2010-10-18 06:26:02 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2010-10-18 06:26:02 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2015-06-08 16:47:14 +02:00
|
|
|
use DateTime;
|
2020-08-26 09:47:59 +02:00
|
|
|
use Respect\Validation\Exceptions\ComponentException;
|
2018-02-27 09:04:23 +01:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2018-05-31 11:37:23 +02:00
|
|
|
use Respect\Validation\Test\Stubs\CountableStub;
|
2010-10-18 06:26:02 +02:00
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
2018-03-22 19:47:48 +01:00
|
|
|
* @group rule
|
|
|
|
*
|
2018-11-25 15:26:03 +01:00
|
|
|
* @covers \Respect\Validation\Rules\AbstractEnvelope
|
2017-02-04 14:01:14 +01:00
|
|
|
* @covers \Respect\Validation\Rules\Between
|
2018-11-25 17:56:04 +01:00
|
|
|
*
|
2023-02-13 05:59:06 +01:00
|
|
|
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
|
2018-11-25 17:56:04 +01:00
|
|
|
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2018-02-27 09:04:23 +01:00
|
|
|
final class BetweenTest extends RuleTestCase
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2023-04-02 16:00:37 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function minimumValueShouldNotBeGreaterThanMaximumValue(): void
|
|
|
|
{
|
|
|
|
$this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum'));
|
|
|
|
|
|
|
|
new Between(10, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function minimumValueShouldNotBeEqualsToMaximumValue(): void
|
|
|
|
{
|
|
|
|
$this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum'));
|
|
|
|
|
|
|
|
new Between(5, 5);
|
|
|
|
}
|
|
|
|
|
2018-02-27 09:04:23 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-02-27 09:04:23 +01:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2018-05-31 15:04:28 +02:00
|
|
|
[new Between(0, 1), 1],
|
|
|
|
[new Between(0, 1), 0],
|
|
|
|
[new Between(10, 20), 15],
|
|
|
|
[new Between(10, 20), 20],
|
|
|
|
[new Between(-10, 20), -5],
|
|
|
|
[new Between(-10, 20), 0],
|
|
|
|
[new Between('a', 'z'), 'j'],
|
|
|
|
[new Between(new DateTime('yesterday'), new DateTime('tomorrow')), new DateTime('now')],
|
2018-05-31 11:37:23 +02:00
|
|
|
[new Between(new CountableStub(1), new CountableStub(10)), 5],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2010-10-18 06:26:02 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2018-02-27 09:04:23 +01:00
|
|
|
return [
|
2018-05-31 15:04:28 +02:00
|
|
|
[new Between(10, 20), ''],
|
|
|
|
[new Between(10, 20), ''],
|
|
|
|
[new Between(0, 1), 2],
|
|
|
|
[new Between(0, 1), -1],
|
|
|
|
[new Between(10, 20), 999],
|
|
|
|
[new Between(-10, 20), -11],
|
|
|
|
[new Between('a', 'j'), 'z'],
|
|
|
|
[new Between(new DateTime('yesterday'), new DateTime('now')), new DateTime('tomorrow')],
|
2018-05-31 11:37:23 +02:00
|
|
|
[new Between(new CountableStub(1), new CountableStub(10)), 11],
|
2018-02-27 09:04:23 +01:00
|
|
|
];
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
}
|