Make data providers static

From PHPUnit 10, all data providers need to be static. This commit will
make migrating from version 9 to 10 a bit easier.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2023-04-02 16:00:37 +02:00
parent ebcf247187
commit 2ee7509c2e
No known key found for this signature in database
GPG key ID: 221E9281655813A6
151 changed files with 987 additions and 987 deletions

View file

@ -157,7 +157,7 @@ final class HelloWorldTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new HelloWorld();
@ -169,7 +169,7 @@ final class HelloWorldTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new HelloWorld();

View file

@ -21,7 +21,7 @@ trait UndefinedProvider
*
* @return mixed[][]
*/
public function providerForUndefined(): array
public static function providerForUndefined(): array
{
return [
[null],
@ -34,7 +34,7 @@ trait UndefinedProvider
*
* @return mixed[][]
*/
public function providerForNotUndefined(): array
public static function providerForNotUndefined(): array
{
return [
[0],

View file

@ -40,7 +40,7 @@ abstract class RuleTestCase extends TestCase
*
* @return mixed[][]
*/
abstract public function providerForValidInput(): array;
abstract public static function providerForValidInput(): array;
/**
* Data providers for invalid results.
@ -52,7 +52,7 @@ abstract class RuleTestCase extends TestCase
*
* @return mixed[][]
*/
abstract public function providerForInvalidInput(): array;
abstract public static function providerForInvalidInput(): array;
/**
* @test

View file

@ -27,10 +27,30 @@ use function sprintf;
*/
final class CheckExceptionsTest extends TestCase
{
/**
* @dataProvider provideListOfRuleNames
*
* @test
*/
public function ruleHasAnExceptionWhichHasValidApi(string $ruleName): void
{
$exceptionClass = 'Respect\\Validation\\Exceptions\\' . $ruleName . 'Exception';
self::assertTrue(
class_exists($exceptionClass),
sprintf('Expected exception class to exist: %s.', $ruleName)
);
$reflectionClass = new ReflectionClass($exceptionClass);
self::assertTrue(
$reflectionClass->isSubclassOf(ValidationException::class),
'Every Respect/Validation exception must extend ValidationException.'
);
}
/**
* @return string[][]
*/
public function provideListOfRuleNames(): array
public static function provideListOfRuleNames(): array
{
$rulesDirectory = 'library/Rules';
$rulesDirectoryIterator = new DirectoryIterator($rulesDirectory);
@ -60,24 +80,4 @@ final class CheckExceptionsTest extends TestCase
return $ruleNames;
}
/**
* @dataProvider provideListOfRuleNames
*
* @test
*/
public function ruleHasAnExceptionWhichHasValidApi(string $ruleName): void
{
$exceptionClass = 'Respect\\Validation\\Exceptions\\' . $ruleName . 'Exception';
self::assertTrue(
class_exists($exceptionClass),
sprintf('Expected exception class to exist: %s.', $ruleName)
);
$reflectionClass = new ReflectionClass($exceptionClass);
self::assertTrue(
$reflectionClass->isSubclassOf(ValidationException::class),
'Every Respect/Validation exception must extend ValidationException.'
);
}
}

View file

@ -22,10 +22,30 @@ final class CanValidateDateTimeTest extends TestCase
{
use CanValidateDateTime;
/**
* @test
*
* @dataProvider providerForValidDateTime
*/
public function shouldFindWhenValueIsDateTime(string $format, string $value): void
{
self::assertTrue($this->isDateTime($format, $value));
}
/**
* @test
*
* @dataProvider providerForInvalidDateTime
*/
public function shouldFindWhenValueIsNotDateTime(string $format, string $value): void
{
self::assertFalse($this->isDateTime($format, $value));
}
/**
* @return mixed[][]
*/
public function providerForValidDateTime(): array
public static function providerForValidDateTime(): array
{
return [
['Y-m-d', '2009-09-09'],
@ -39,20 +59,10 @@ final class CanValidateDateTimeTest extends TestCase
];
}
/**
* @test
*
* @dataProvider providerForValidDateTime
*/
public function shouldFindWhenValueIsDateTime(string $format, string $value): void
{
self::assertTrue($this->isDateTime($format, $value));
}
/**
* @return mixed[][]
*/
public function providerForInvalidDateTime(): array
public static function providerForInvalidDateTime(): array
{
return [
['Y-m-d', '0000-01-01'],
@ -63,14 +73,4 @@ final class CanValidateDateTimeTest extends TestCase
['Y-m-d H:i:s', '1987-12-31'],
];
}
/**
* @test
*
* @dataProvider providerForInvalidDateTime
*/
public function shouldFindWhenValueIsNotDateTime(string $format, string $value): void
{
self::assertFalse($this->isDateTime($format, $value));
}
}

View file

@ -23,17 +23,6 @@ use Respect\Validation\Test\TestCase;
*/
final class AbstractRuleTest extends TestCase
{
/**
* @return bool[][]
*/
public function providerForTrueAndFalse(): array
{
return [
[true],
[false],
];
}
/**
* @dataProvider providerForTrueAndFalse
* @covers \Respect\Validation\Rules\AbstractRule::__invoke
@ -195,4 +184,15 @@ final class AbstractRuleTest extends TestCase
self::assertSame($name, $abstractRuleMock->getName());
}
/**
* @return bool[][]
*/
public static function providerForTrueAndFalse(): array
{
return [
[true],
[false],
];
}
}

View file

@ -118,7 +118,7 @@ final class AllOfTest extends TestCase
/**
* @return Validatable[][]
*/
public function providerStaticDummyRules(): array
public static function providerStaticDummyRules(): array
{
$theInvalidOne = new Callback(static function () {
return false;

View file

@ -30,7 +30,7 @@ final class AlnumTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Alnum(), 'alganet'],
@ -53,7 +53,7 @@ final class AlnumTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Alnum(), ''],

View file

@ -29,7 +29,7 @@ final class AlphaTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
'alphabetic' => [new Alpha(), 'alganet'],
@ -43,7 +43,7 @@ final class AlphaTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
'empty string' => [new Alpha(), ''],

View file

@ -23,10 +23,24 @@ use Respect\Validation\Test\TestCase;
*/
final class AlwaysInvalidTest extends TestCase
{
/**
* @test
*
* @dataProvider providerForInvalidInput
*
* @param mixed $input
*/
public function itShouldAlwaysBeInvalid($input): void
{
$rule = new AlwaysInvalid();
self::assertFalse($rule->validate($input));
}
/**
* @return mixed[][]
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[0],
@ -40,18 +54,4 @@ final class AlwaysInvalidTest extends TestCase
[['array_full']],
];
}
/**
* @test
*
* @dataProvider providerForInvalidInput
*
* @param mixed $input
*/
public function itShouldAlwaysBeInvalid($input): void
{
$rule = new AlwaysInvalid();
self::assertFalse($rule->validate($input));
}
}

View file

@ -23,10 +23,24 @@ use Respect\Validation\Test\TestCase;
*/
final class AlwaysValidTest extends TestCase
{
/**
* @test
*
* @dataProvider providerForValidInput
*
* @param mixed $input
*/
public function itAlwaysBeValid($input): void
{
$rule = new AlwaysValid();
self::assertTrue($rule->validate($input));
}
/**
* @return mixed[][]
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[0],
@ -40,18 +54,4 @@ final class AlwaysValidTest extends TestCase
[['array_full']],
];
}
/**
* @test
*
* @dataProvider providerForValidInput
*
* @param mixed $input
*/
public function itAlwaysBeValid($input): void
{
$rule = new AlwaysValid();
self::assertTrue($rule->validate($input));
}
}

View file

@ -26,7 +26,7 @@ final class ArrayTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new ArrayType();
@ -39,7 +39,7 @@ final class ArrayTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new ArrayType();

View file

@ -28,7 +28,7 @@ final class ArrayValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new ArrayVal();
@ -43,7 +43,7 @@ final class ArrayValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new ArrayVal();

View file

@ -35,7 +35,7 @@ final class AttributeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
'attribute is present without extra validator' => [new Attribute('public'), new WithProperties()],
@ -61,7 +61,7 @@ final class AttributeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
'attribute is absent without extra validator' => [new Attribute('barr'), new WithProperties()],

View file

@ -27,7 +27,7 @@ final class Base64Test extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Base64();
@ -59,7 +59,7 @@ final class Base64Test extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Base64();

View file

@ -26,7 +26,7 @@ final class BaseTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Base(2), '011010001'],
@ -44,7 +44,7 @@ final class BaseTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Base(2), ''],

View file

@ -26,42 +26,6 @@ use Respect\Validation\Test\Stubs\CountableStub;
*/
final class BetweenTest extends RuleTestCase
{
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
{
return [
[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')],
[new Between(new CountableStub(1), new CountableStub(10)), 5],
];
}
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
{
return [
[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')],
[new Between(new CountableStub(1), new CountableStub(10)), 11],
];
}
/**
* @test
*/
@ -81,4 +45,40 @@ final class BetweenTest extends RuleTestCase
new Between(5, 5);
}
/**
* {@inheritDoc}
*/
public static function providerForValidInput(): array
{
return [
[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')],
[new Between(new CountableStub(1), new CountableStub(10)), 5],
];
}
/**
* {@inheritDoc}
*/
public static function providerForInvalidInput(): array
{
return [
[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')],
[new Between(new CountableStub(1), new CountableStub(10)), 11],
];
}
}

View file

@ -26,7 +26,7 @@ final class BoolTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new BoolType();
@ -39,7 +39,7 @@ final class BoolTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new BoolType();

View file

@ -25,7 +25,7 @@ final class BoolValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new BoolVal();
@ -45,7 +45,7 @@ final class BoolValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new BoolVal();

View file

@ -26,7 +26,7 @@ final class BsnTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Bsn();
@ -47,7 +47,7 @@ final class BsnTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Bsn();

View file

@ -28,7 +28,7 @@ final class CallableTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new CallableType();
@ -43,7 +43,7 @@ final class CallableTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new CallableType();

View file

@ -28,7 +28,7 @@ final class CallbackTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Callback('is_a', 'stdClass'), new stdClass()],
@ -46,7 +46,7 @@ final class CallbackTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[

View file

@ -40,7 +40,7 @@ final class CharsetTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Charset('UTF-8'), ''],
@ -57,7 +57,7 @@ final class CharsetTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Charset('ASCII');

View file

@ -29,7 +29,7 @@ final class CnhTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Cnh();
@ -64,7 +64,7 @@ final class CnhTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Cnh();

View file

@ -27,7 +27,7 @@ final class CnpjTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Cnpj();
@ -49,7 +49,7 @@ final class CnpjTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Cnpj();

View file

@ -29,7 +29,7 @@ final class ConsonantTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$consonant = new Consonant();
@ -54,7 +54,7 @@ final class ConsonantTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$consonant = new Consonant();

View file

@ -24,7 +24,7 @@ final class ContainsAnyTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new ContainsAny(['Something', 'Else']), 'something else'],
@ -42,7 +42,7 @@ final class ContainsAnyTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new ContainsAny(['foo']), ['bar', 'baz']],

View file

@ -27,7 +27,7 @@ final class ContainsTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Contains('foo', false), ['bar', 'foo']],
@ -48,7 +48,7 @@ final class ContainsTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Contains('foo', false), ''],

View file

@ -29,7 +29,7 @@ final class ControlTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new Control();
@ -46,7 +46,7 @@ final class ControlTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new Control();

View file

@ -30,7 +30,7 @@ final class CountableTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Countable();
@ -44,7 +44,7 @@ final class CountableTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Countable();

View file

@ -40,7 +40,7 @@ final class CountryCodeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new CountryCode(CountryCode::ALPHA2), 'BR'],
@ -58,7 +58,7 @@ final class CountryCodeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new CountryCode(CountryCode::ALPHA2), 'USA'],

View file

@ -28,7 +28,7 @@ final class CpfTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Cpf();
@ -49,7 +49,7 @@ final class CpfTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Cpf();

View file

@ -42,7 +42,7 @@ final class CreditCardTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$general = new CreditCard();
$amex = new CreditCard(CreditCard::AMERICAN_EXPRESS);
@ -79,7 +79,7 @@ final class CreditCardTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$general = new CreditCard();
$amex = new CreditCard(CreditCard::AMERICAN_EXPRESS);

View file

@ -25,7 +25,7 @@ final class CurrencyCodeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new CurrencyCode();
@ -41,7 +41,7 @@ final class CurrencyCodeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new CurrencyCode();

View file

@ -24,58 +24,6 @@ use Respect\Validation\Test\RuleTestCase;
*/
final class DateTest extends RuleTestCase
{
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
{
return [
[new Date(), '2017-12-31'],
[new Date('m/d/y'), '12/31/17'],
[new Date('F jS, Y'), 'May 1st, 2017'],
[new Date('Ydm'), 20173112],
[new Date(), '2020-02-29'],
];
}
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
{
return [
[new Date(), 'not-a-date'],
[new Date(), []],
[new Date(), true],
[new Date(), false],
[new Date(), null],
[new Date(), ''],
[new Date(), '1988-02-30'],
[new Date('d/m/y'), '12/31/17'],
[new Date(), '2019-02-29'],
[new Date(), new DateTime()],
[new Date(), new DateTimeImmutable()],
[new Date(), ''],
[new Date('Y-m-d'), '2009-12-00'],
[new Date('Y-m-d'), '2018-02-29'],
[new Date(), '2014-99'],
[new Date('d'), 1],
[new Date('Y-m'), '2014-99'],
[new Date('m'), '99'],
];
}
/**
* @return string[][]
*/
public function validFormatsProvider(): array
{
return [
['Y-m-d H:i:s'],
['c'],
];
}
/**
* @test
*
@ -99,4 +47,56 @@ final class DateTest extends RuleTestCase
self::assertSame($format, $exception->getParam('format'));
}
/**
* @return string[][]
*/
public static function validFormatsProvider(): array
{
return [
['Y-m-d H:i:s'],
['c'],
];
}
/**
* {@inheritDoc}
*/
public static function providerForValidInput(): array
{
return [
[new Date(), '2017-12-31'],
[new Date('m/d/y'), '12/31/17'],
[new Date('F jS, Y'), 'May 1st, 2017'],
[new Date('Ydm'), 20173112],
[new Date(), '2020-02-29'],
];
}
/**
* {@inheritDoc}
*/
public static function providerForInvalidInput(): array
{
return [
[new Date(), 'not-a-date'],
[new Date(), []],
[new Date(), true],
[new Date(), false],
[new Date(), null],
[new Date(), ''],
[new Date(), '1988-02-30'],
[new Date('d/m/y'), '12/31/17'],
[new Date(), '2019-02-29'],
[new Date(), new DateTime()],
[new Date(), new DateTimeImmutable()],
[new Date(), ''],
[new Date('Y-m-d'), '2009-12-00'],
[new Date('Y-m-d'), '2018-02-29'],
[new Date(), '2014-99'],
[new Date('d'), 1],
[new Date('Y-m'), '2014-99'],
[new Date('m'), '99'],
];
}
}

View file

@ -29,10 +29,60 @@ use function date_default_timezone_set;
*/
final class DateTimeTest extends RuleTestCase
{
/**
* @test
*/
public function shouldPassFormatToParameterToException(): void
{
$format = 'F jS, Y';
$equals = new DateTime($format);
$exception = $equals->reportError('input');
self::assertSame($format, $exception->getParam('format'));
}
/**
* Datetime strings with timezone information are valid independent on the
* system's timezone setting.
*
* @test
*
* @dataProvider providerForDateTimeWithTimezone
*/
public function shouldValidateNoMatterTimezone(string $format, string $input, string $timezone): void
{
$currentTimezone = date_default_timezone_get();
date_default_timezone_set($timezone);
$rule = new DateTime($format);
self::assertTrue($rule->validate($input));
date_default_timezone_set($currentTimezone);
}
/**
* @return mixed[][]
*/
public static function providerForDateTimeWithTimezone(): array
{
return [
['c', '2004-02-12T15:19:21+00:00', 'Europe/Amsterdam'],
['c', '2004-02-12T15:19:21+00:00', 'UTC'],
['d/m/Y', '23/05/1987', 'Europe/Amsterdam'],
['d/m/Y', '23/05/1987', 'UTC'],
['r', 'Thu, 29 Dec 2005 01:02:03 +0000', 'Europe/Amsterdam'],
['r', 'Thu, 29 Dec 2005 01:02:03 +0000', 'UTC'],
['Ym', '202302', 'Europe/Amsterdam'],
['Ym', '202302', 'UTC'],
];
}
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new DateTime(), 'now'],
@ -58,7 +108,7 @@ final class DateTimeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new DateTime(), 'not-a-date'],
@ -75,54 +125,4 @@ final class DateTimeTest extends RuleTestCase
[new DateTime('Y-m-d H:i:s'), '21-3-123:12:01'],
];
}
/**
* @test
*/
public function shouldPassFormatToParameterToException(): void
{
$format = 'F jS, Y';
$equals = new DateTime($format);
$exception = $equals->reportError('input');
self::assertSame($format, $exception->getParam('format'));
}
/**
* @return mixed[][]
*/
public function providerForDateTimeWithTimezone(): array
{
return [
['c', '2004-02-12T15:19:21+00:00', 'Europe/Amsterdam'],
['c', '2004-02-12T15:19:21+00:00', 'UTC'],
['d/m/Y', '23/05/1987', 'Europe/Amsterdam'],
['d/m/Y', '23/05/1987', 'UTC'],
['r', 'Thu, 29 Dec 2005 01:02:03 +0000', 'Europe/Amsterdam'],
['r', 'Thu, 29 Dec 2005 01:02:03 +0000', 'UTC'],
['Ym', '202302', 'Europe/Amsterdam'],
['Ym', '202302', 'UTC'],
];
}
/**
* Datetime strings with timezone information are valid independent on the
* system's timezone setting.
*
* @test
*
* @dataProvider providerForDateTimeWithTimezone
*/
public function shouldValidateNoMatterTimezone(string $format, string $input, string $timezone): void
{
$currentTimezone = date_default_timezone_get();
date_default_timezone_set($timezone);
$rule = new DateTime($format);
self::assertTrue($rule->validate($input));
date_default_timezone_set($currentTimezone);
}
}

View file

@ -31,7 +31,7 @@ final class DecimalTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Decimal(0), 1],
@ -56,7 +56,7 @@ final class DecimalTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Decimal(1), '1.50'],

View file

@ -28,7 +28,7 @@ final class DigitTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
'positive integer' => [new Digit(), 165],
@ -47,7 +47,7 @@ final class DigitTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
'empty' => [new Digit(), ''],

View file

@ -30,7 +30,7 @@ final class DirectoryTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Directory();
@ -44,7 +44,7 @@ final class DirectoryTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Directory();

View file

@ -28,7 +28,7 @@ final class DomainTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Domain(false), '111111111111domain.local'],
@ -46,7 +46,7 @@ final class DomainTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Domain(), null],

View file

@ -30,40 +30,6 @@ use function range;
*/
final class EachTest extends RuleTestCase
{
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
{
$rule = new Each(new AlwaysValid());
return [
[$rule, []],
[$rule, [1, 2, 3, 4, 5]],
[$rule, $this->createTraversableInput(1, 5)],
[$rule, $this->createStdClassInput(1, 5)],
];
}
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
{
$rule = new Each(new AlwaysInvalid());
return [
[$rule, 123],
[$rule, ''],
[$rule, null],
[$rule, false],
[$rule, ['', 2, 3, 4, 5]],
[$rule, ['a', 2, 3, 4, 5]],
[$rule, $this->createTraversableInput(1, 5)],
[$rule, $this->createStdClassInput(1, 5)],
];
}
/**
* @test
*/
@ -114,10 +80,44 @@ final class EachTest extends RuleTestCase
}
}
/**
* {@inheritDoc}
*/
public static function providerForValidInput(): array
{
$rule = new Each(new AlwaysValid());
return [
[$rule, []],
[$rule, [1, 2, 3, 4, 5]],
[$rule, self::createTraversableInput(1, 5)],
[$rule, self::createStdClassInput(1, 5)],
];
}
/**
* {@inheritDoc}
*/
public static function providerForInvalidInput(): array
{
$rule = new Each(new AlwaysInvalid());
return [
[$rule, 123],
[$rule, ''],
[$rule, null],
[$rule, false],
[$rule, ['', 2, 3, 4, 5]],
[$rule, ['a', 2, 3, 4, 5]],
[$rule, self::createTraversableInput(1, 5)],
[$rule, self::createStdClassInput(1, 5)],
];
}
/**
* @return Traversable<int>
*/
private function createTraversableInput(int $firstValue, int $lastValue): Traversable
private static function createTraversableInput(int $firstValue, int $lastValue): Traversable
{
/** @var SplStack<int> */
$input = new SplStack();
@ -128,7 +128,7 @@ final class EachTest extends RuleTestCase
return $input;
}
private function createStdClassInput(int $firstValue, int $lastValue): stdClass
private static function createStdClassInput(int $firstValue, int $lastValue): stdClass
{
$input = [];
foreach (range($firstValue, $lastValue) as $value) {

View file

@ -54,9 +54,9 @@ final class EmailTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = $this->createSutWithoutEmailValidator();
$sut = self::sut();
return [
[$sut, 'test@test.com'],
@ -69,9 +69,9 @@ final class EmailTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = $this->createSutWithoutEmailValidator();
$sut = self::sut();
return [
[$sut, ''],
@ -94,7 +94,7 @@ final class EmailTest extends RuleTestCase
/**
* @throws ReflectionException
*/
private function createSutWithoutEmailValidator(): Email
private static function sut(): Email
{
$rule = new Email();

View file

@ -26,7 +26,7 @@ final class EndsWithTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new EndsWith('foo'), ['bar', 'foo']],
@ -42,7 +42,7 @@ final class EndsWithTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new EndsWith('foo'), ''],

View file

@ -22,10 +22,22 @@ use stdClass;
*/
final class EqualsTest extends RuleTestCase
{
/**
* @test
*/
public function shouldPassCompareToParameterToException(): void
{
$compareTo = new stdClass();
$equals = new Equals($compareTo);
$exception = $equals->reportError('input');
self::assertSame($compareTo, $exception->getParam('compareTo'));
}
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Equals('foo'), 'foo'],
@ -39,23 +51,11 @@ final class EqualsTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Equals('foo'), ''],
[new Equals('foo'), 'bar'],
];
}
/**
* @test
*/
public function shouldPassCompareToParameterToException(): void
{
$compareTo = new stdClass();
$equals = new Equals($compareTo);
$exception = $equals->reportError('input');
self::assertSame($compareTo, $exception->getParam('compareTo'));
}
}

View file

@ -24,7 +24,7 @@ final class EquivalentTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Equivalent(1), true],
@ -38,7 +38,7 @@ final class EquivalentTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Equivalent(1), false],

View file

@ -28,7 +28,7 @@ final class EvenTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Even(), 2],
@ -41,7 +41,7 @@ final class EvenTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Even(), ''],

View file

@ -28,7 +28,7 @@ final class ExecutableTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Executable();
@ -42,7 +42,7 @@ final class ExecutableTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Executable();

View file

@ -28,7 +28,7 @@ final class ExistsTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Exists();
@ -42,7 +42,7 @@ final class ExistsTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Exists();

View file

@ -25,7 +25,7 @@ final class ExtensionTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
'txt' => [new Extension('txt'), 'filename.txt'],
@ -42,7 +42,7 @@ final class ExtensionTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
'jpg' => [new Extension('jpg'), 'filename.txt'],

View file

@ -34,7 +34,7 @@ final class FactorTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
'1 is factor 1' => [new Factor(1), 1],
@ -69,7 +69,7 @@ final class FactorTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
'3 is not factor 2' => [new Factor(3), 2],

View file

@ -30,7 +30,7 @@ final class FalseValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new FalseVal();
@ -54,7 +54,7 @@ final class FalseValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new FalseVal();

View file

@ -25,7 +25,7 @@ final class FibonacciTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Fibonacci();
@ -49,7 +49,7 @@ final class FibonacciTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Fibonacci();

View file

@ -30,7 +30,7 @@ final class FileTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new File();
@ -44,7 +44,7 @@ final class FileTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new File();

View file

@ -47,7 +47,7 @@ final class FilterVarTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new FilterVar(FILTER_VALIDATE_INT), '12345'],
@ -63,7 +63,7 @@ final class FilterVarTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new FilterVar(FILTER_VALIDATE_INT), 1.4],

View file

@ -31,7 +31,7 @@ final class FiniteTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new Finite();
@ -49,7 +49,7 @@ final class FiniteTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new Finite();

View file

@ -26,7 +26,7 @@ final class FloatTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new FloatType();
@ -44,7 +44,7 @@ final class FloatTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new FloatType();

View file

@ -26,7 +26,7 @@ final class FloatValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new FloatVal();
@ -46,7 +46,7 @@ final class FloatValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new FloatVal();

View file

@ -28,7 +28,7 @@ final class GraphTest extends RuleTestCase
/**
* @inheritDoc
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$graph = new Graph();
@ -50,7 +50,7 @@ final class GraphTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$graph = new Graph();

View file

@ -26,7 +26,7 @@ final class GreaterThanTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new GreaterThan(10), 11],
@ -40,7 +40,7 @@ final class GreaterThanTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new GreaterThan(10), 9],

View file

@ -26,7 +26,7 @@ final class HexRgbColorTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new HexRgbColor();
@ -48,7 +48,7 @@ final class HexRgbColorTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new HexRgbColor();

View file

@ -26,7 +26,7 @@ final class IbanTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new Iban();
@ -48,7 +48,7 @@ final class IbanTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new Iban();

View file

@ -21,10 +21,22 @@ use stdClass;
*/
final class IdenticalTest extends RuleTestCase
{
/**
* @test
*/
public function shouldPassCompareToParameterToException(): void
{
$compareTo = new stdClass();
$rule = new Identical($compareTo);
$exception = $rule->reportError('input');
self::assertSame($compareTo, $exception->getParam('compareTo'));
}
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$object = new stdClass();
@ -40,7 +52,7 @@ final class IdenticalTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Identical(42), '42'],
@ -50,16 +62,4 @@ final class IdenticalTest extends RuleTestCase
[new Identical(10), 10.0],
];
}
/**
* @test
*/
public function shouldPassCompareToParameterToException(): void
{
$compareTo = new stdClass();
$rule = new Identical($compareTo);
$exception = $rule->reportError('input');
self::assertSame($compareTo, $exception->getParam('compareTo'));
}
}

View file

@ -25,38 +25,6 @@ use SplFileObject;
*/
final class ImageTest extends RuleTestCase
{
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
{
$rule = new Image();
return [
[$rule, self::fixture('valid-image.gif')],
[$rule, self::fixture('valid-image.jpg')],
[$rule, self::fixture('valid-image.png')],
[$rule, new SplFileInfo(self::fixture('valid-image.gif'))],
[$rule, new SplFileInfo(self::fixture('valid-image.jpg'))],
[$rule, new SplFileObject(self::fixture('valid-image.png'))],
];
}
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
{
$rule = new Image();
return [
[$rule, self::fixture('invalid-image.png')],
[$rule, 'asdf'],
[$rule, 1],
[$rule, true],
];
}
/**
* @test
*/
@ -75,4 +43,36 @@ final class ImageTest extends RuleTestCase
self::assertTrue($rule->validate($input));
}
/**
* {@inheritDoc}
*/
public static function providerForValidInput(): array
{
$rule = new Image();
return [
[$rule, self::fixture('valid-image.gif')],
[$rule, self::fixture('valid-image.jpg')],
[$rule, self::fixture('valid-image.png')],
[$rule, new SplFileInfo(self::fixture('valid-image.gif'))],
[$rule, new SplFileInfo(self::fixture('valid-image.jpg'))],
[$rule, new SplFileObject(self::fixture('valid-image.png'))],
];
}
/**
* {@inheritDoc}
*/
public static function providerForInvalidInput(): array
{
$rule = new Image();
return [
[$rule, self::fixture('invalid-image.png')],
[$rule, 'asdf'],
[$rule, 1],
[$rule, true],
];
}
}

View file

@ -26,7 +26,7 @@ final class ImeiTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Imei();
@ -45,7 +45,7 @@ final class ImeiTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Imei();

View file

@ -26,7 +26,7 @@ final class InTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new In(''), ''],
@ -45,7 +45,7 @@ final class InTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new In('0'), null],

View file

@ -29,7 +29,7 @@ final class InfiniteTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Infinite();
@ -42,7 +42,7 @@ final class InfiniteTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Infinite();

View file

@ -32,7 +32,7 @@ final class InstanceTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Instance(DateTime::class), new DateTime()],
@ -44,7 +44,7 @@ final class InstanceTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Instance(DateTime::class), ''],

View file

@ -26,7 +26,7 @@ final class IntTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new IntType();
@ -41,7 +41,7 @@ final class IntTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new IntType();

View file

@ -29,7 +29,7 @@ final class IntValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new IntVal();
@ -54,7 +54,7 @@ final class IntValTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new IntVal();

View file

@ -30,10 +30,40 @@ use const FILTER_FLAG_NO_PRIV_RANGE;
*/
final class IpTest extends RuleTestCase
{
/**
* @test
*
* @dataProvider providerForInvalidRanges
*
* @throws ComponentException
*/
public function invalidRangeShouldRaiseException(string $range): void
{
$this->expectException(ComponentException::class);
new Ip($range);
}
/**
* @return string[][]
*/
public static function providerForInvalidRanges(): array
{
return [
['192.168'],
['asd'],
['192.168.0.0-192.168.0.256'],
['192.168.0.0-192.168.0.1/4'],
['192.168.0/1'],
['192.168.2.0/256.256.256.256'],
['192.168.2.0/8.256.256.256'],
];
}
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Ip('127.*'), '127.0.0.1'],
@ -61,7 +91,7 @@ final class IpTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Ip('127.*'), '192.0.1.0'],
@ -84,36 +114,6 @@ final class IpTest extends RuleTestCase
];
}
/**
* @return string[][]
*/
public function providerForInvalidRanges(): array
{
return [
['192.168'],
['asd'],
['192.168.0.0-192.168.0.256'],
['192.168.0.0-192.168.0.1/4'],
['192.168.0/1'],
['192.168.2.0/256.256.256.256'],
['192.168.2.0/8.256.256.256'],
];
}
/**
* @test
*
* @dataProvider providerForInvalidRanges
*
* @throws ComponentException
*/
public function invalidRangeShouldRaiseException(string $range): void
{
$this->expectException(ComponentException::class);
new Ip($range);
}
/**
* {@inheritDoc}
*/

View file

@ -24,7 +24,7 @@ final class IsbnTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new Isbn();
@ -42,7 +42,7 @@ final class IsbnTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new Isbn();

View file

@ -26,7 +26,7 @@ final class IterableTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new IterableType();
@ -40,7 +40,7 @@ final class IterableTypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new IterableType();

View file

@ -28,7 +28,7 @@ final class JsonTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$json = new Json();
@ -48,7 +48,7 @@ final class JsonTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$json = new Json();

View file

@ -221,7 +221,7 @@ final class KeySetTest extends TestCase
/**
* @return mixed[][]
*/
public function providerForInvalidArguments(): array
public static function providerForInvalidArguments(): array
{
return [
[''],

View file

@ -24,7 +24,7 @@ final class KeyValueTest extends RuleTestCase
/**
* {@inheritdoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
'Equal values' => [new KeyValue('foo', 'equals', 'bar'), ['foo' => 42, 'bar' => 42]],
@ -42,7 +42,7 @@ final class KeyValueTest extends RuleTestCase
/**
* {@inheritdoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$keyValue = new KeyValue('foo', 'equals', 'bar');

View file

@ -24,10 +24,20 @@ use Respect\Validation\Test\RuleTestCase;
*/
final class LanguageCodeTest extends RuleTestCase
{
/**
* @test
*/
public function itShouldThrowAnExceptionWhenSetIsInvalid(): void
{
$this->expectExceptionObject(new ComponentException('"foo" is not a valid language set for ISO 639'));
new LanguageCode('foo');
}
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sutAlpha2 = new LanguageCode(LanguageCode::ALPHA2);
$sutAlpha3 = new LanguageCode(LanguageCode::ALPHA3);
@ -47,7 +57,7 @@ final class LanguageCodeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sutAlpha2 = new LanguageCode(LanguageCode::ALPHA2);
$sutAlpha3 = new LanguageCode(LanguageCode::ALPHA3);
@ -65,14 +75,4 @@ final class LanguageCodeTest extends RuleTestCase
'alpha-3: null' => [$sutAlpha3, ''],
];
}
/**
* @test
*/
public function itShouldThrowAnExceptionWhenSetIsInvalid(): void
{
$this->expectExceptionObject(new ComponentException('"foo" is not a valid language set for ISO 639'));
new LanguageCode('foo');
}
}

View file

@ -27,7 +27,7 @@ final class LeapDateTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new LeapDate('Y-m-d'), '1988-02-29'],
@ -40,7 +40,7 @@ final class LeapDateTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new LeapDate('Y-m-d'), '1989-02-29'],

View file

@ -26,7 +26,7 @@ final class LeapYearTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new LeapYear();
@ -42,7 +42,7 @@ final class LeapYearTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new LeapYear();

View file

@ -30,10 +30,21 @@ use function tmpfile;
*/
final class LengthTest extends RuleTestCase
{
/**
* @test
*/
public function isShouldNotNotAcceptInvalidLengths(): void
{
$this->expectException(ComponentException::class);
$this->expectExceptionMessage('10 cannot be less than 1 for validation');
new Length(10, 1);
}
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Length(1, 15), 'alganet'],
@ -56,7 +67,7 @@ final class LengthTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Length(1, 15), ''],
@ -72,15 +83,4 @@ final class LengthTest extends RuleTestCase
[new Length(1, 4), 12345],
];
}
/**
* @test
*/
public function isShouldNotNotAcceptInvalidLengths(): void
{
$this->expectException(ComponentException::class);
$this->expectExceptionMessage('10 cannot be less than 1 for validation');
new Length(10, 1);
}
}

View file

@ -26,7 +26,7 @@ final class LessThanTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new LessThan(10), 9],
@ -40,7 +40,7 @@ final class LessThanTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new LessThan(10), 10],

View file

@ -27,7 +27,7 @@ final class LowercaseTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Lowercase();
@ -48,7 +48,7 @@ final class LowercaseTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Lowercase();

View file

@ -26,7 +26,7 @@ final class LuhnTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Luhn();
@ -40,7 +40,7 @@ final class LuhnTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Luhn();

View file

@ -31,7 +31,7 @@ final class MacAddressTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new MacAddress();
@ -46,7 +46,7 @@ final class MacAddressTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new MacAddress();

View file

@ -31,7 +31,7 @@ final class MaxAgeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new MaxAge(30, 'Y-m-d'), date('Y-m-d', strtotime('30 years ago'))],
@ -44,7 +44,7 @@ final class MaxAgeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new MaxAge(30), new DateTime('30 years ago')],

View file

@ -30,7 +30,7 @@ final class MaxTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Max(10), 9],
@ -46,7 +46,7 @@ final class MaxTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Max(10), 11],

View file

@ -59,7 +59,7 @@ final class MimetypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
'image/png' => [new Mimetype('image/png'), 'tests/fixtures/valid-image.png'],
@ -74,7 +74,7 @@ final class MimetypeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
'invalid file' => [new Mimetype('image/png'), 'tests/fixtures/invalid-image.png'],

View file

@ -33,7 +33,7 @@ final class MinAgeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new MinAge(18, 'Y-m-d'), date('Y-m-d', strtotime('18 years ago'))],
@ -46,7 +46,7 @@ final class MinAgeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new MinAge(18), new DateTime('18 years ago')],

View file

@ -30,7 +30,7 @@ final class MinTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
// From documentation
@ -61,7 +61,7 @@ final class MinTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
// From documentation

View file

@ -26,7 +26,7 @@ final class MultipleTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
return [
[new Multiple(5), 20],
@ -44,7 +44,7 @@ final class MultipleTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
return [
[new Multiple(5), 11],

View file

@ -27,7 +27,7 @@ final class NegativeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Negative();
@ -41,7 +41,7 @@ final class NegativeTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Negative();

View file

@ -26,7 +26,7 @@ final class NfeAccessKeyTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$nfe = new NfeAccessKey();
@ -38,7 +38,7 @@ final class NfeAccessKeyTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$nfe = new NfeAccessKey();

View file

@ -27,7 +27,7 @@ final class NifTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Nif();
@ -59,7 +59,7 @@ final class NifTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Nif();

View file

@ -25,7 +25,7 @@ final class NipTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new Nip();
@ -39,7 +39,7 @@ final class NipTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new Nip();

View file

@ -31,63 +31,6 @@ final class NoTest extends RuleTestCase
*/
private $locale;
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
{
$sut = new No();
return [
[$sut, 'N'],
[$sut, 'Nay'],
[$sut, 'Nix'],
[$sut, 'No'],
[$sut, 'Nope'],
[$sut, 'Not'],
];
}
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
{
$sut = new No();
return [
[$sut, 'Donnot'],
[$sut, 'Never'],
[$sut, 'Niet'],
[$sut, 'Noooooooo'],
[$sut, 'Não'],
];
}
/**
* @return string[][]
*/
public function providerForValidInputWithLocale(): array
{
return [
'nl' => ['nl_NL.UTF-8', 'Nee'],
'pt' => ['pt_BR.UTF-8', 'Não'],
'ru' => ['ru_RU.UTF-8', 'нет'],
];
}
/**
* @return string[][]
*/
public function providerForInvalidInputWithLocale(): array
{
return [
'nl' => ['nl_NL.UTF-8', 'Ez'],
'pt' => ['pt_BR.UTF-8', 'нет'],
'ru' => ['pt_BR.UTF-8', 'Οχι'],
];
}
/**
* @test
*
@ -120,6 +63,63 @@ final class NoTest extends RuleTestCase
self::assertInvalidInput(new No(true), $input);
}
/**
* @return string[][]
*/
public static function providerForValidInputWithLocale(): array
{
return [
'nl' => ['nl_NL.UTF-8', 'Nee'],
'pt' => ['pt_BR.UTF-8', 'Não'],
'ru' => ['ru_RU.UTF-8', 'нет'],
];
}
/**
* @return string[][]
*/
public static function providerForInvalidInputWithLocale(): array
{
return [
'nl' => ['nl_NL.UTF-8', 'Ez'],
'pt' => ['pt_BR.UTF-8', 'нет'],
'ru' => ['pt_BR.UTF-8', 'Οχι'],
];
}
/**
* {@inheritDoc}
*/
public static function providerForValidInput(): array
{
$sut = new No();
return [
[$sut, 'N'],
[$sut, 'Nay'],
[$sut, 'Nix'],
[$sut, 'No'],
[$sut, 'Nope'],
[$sut, 'Not'],
];
}
/**
* {@inheritDoc}
*/
public static function providerForInvalidInput(): array
{
$sut = new No();
return [
[$sut, 'Donnot'],
[$sut, 'Never'],
[$sut, 'Niet'],
[$sut, 'Noooooooo'],
[$sut, 'Não'],
];
}
/**
* {@inheritDoc}
*/

View file

@ -27,7 +27,7 @@ final class NoWhitespaceTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new NoWhitespace();
@ -43,7 +43,7 @@ final class NoWhitespaceTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new NoWhitespace();

View file

@ -26,7 +26,7 @@ final class NotBlankTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$object = new stdClass();
$object->foo = true;
@ -45,7 +45,7 @@ final class NotBlankTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new NotBlank();

View file

@ -25,7 +25,7 @@ final class NotEmojiTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$sut = new NotEmoji();
@ -43,7 +43,7 @@ final class NotEmojiTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$sut = new NotEmoji();

View file

@ -26,7 +26,7 @@ final class NotEmptyTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new NotEmpty();
@ -42,7 +42,7 @@ final class NotEmptyTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new NotEmpty();

View file

@ -25,7 +25,7 @@ final class NotOptionalTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
public static function providerForValidInput(): array
{
$rule = new NotOptional();
@ -50,7 +50,7 @@ final class NotOptionalTest extends RuleTestCase
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
public static function providerForInvalidInput(): array
{
$rule = new NotOptional();

View file

@ -74,7 +74,7 @@ final class NotTest extends TestCase
/**
* @return mixed[][]
*/
public function providerForValidNot(): array
public static function providerForValidNot(): array
{
return [
[new IntVal(), ''],
@ -91,7 +91,7 @@ final class NotTest extends TestCase
/**
* @return mixed[][]
*/
public function providerForInvalidNot(): array
public static function providerForInvalidNot(): array
{
return [
[new IntVal(), 123],
@ -104,7 +104,7 @@ final class NotTest extends TestCase
/**
* @return Validatable[][]
*/
public function providerForSetName(): array
public static function providerForSetName(): array
{
return [
'non-allOf' => [new IntVal()],

Some files were not shown because too many files have changed in this diff Show more