diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0cb5c2f8..a760063c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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(); diff --git a/tests/library/DataProvider/UndefinedProvider.php b/tests/library/DataProvider/UndefinedProvider.php index 3aca0f6e..51496cd8 100644 --- a/tests/library/DataProvider/UndefinedProvider.php +++ b/tests/library/DataProvider/UndefinedProvider.php @@ -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], diff --git a/tests/library/RuleTestCase.php b/tests/library/RuleTestCase.php index 3e279c99..bdd95139 100644 --- a/tests/library/RuleTestCase.php +++ b/tests/library/RuleTestCase.php @@ -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 diff --git a/tests/unit/Exceptions/CheckExceptionsTest.php b/tests/unit/Exceptions/CheckExceptionsTest.php index 3701f95e..4db25c4c 100644 --- a/tests/unit/Exceptions/CheckExceptionsTest.php +++ b/tests/unit/Exceptions/CheckExceptionsTest.php @@ -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.' - ); - } } diff --git a/tests/unit/Helpers/CanValidateDateTimeTest.php b/tests/unit/Helpers/CanValidateDateTimeTest.php index f21f4fa4..c707f09c 100644 --- a/tests/unit/Helpers/CanValidateDateTimeTest.php +++ b/tests/unit/Helpers/CanValidateDateTimeTest.php @@ -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)); - } } diff --git a/tests/unit/Rules/AbstractRuleTest.php b/tests/unit/Rules/AbstractRuleTest.php index 4bfbbb07..43ae9d55 100644 --- a/tests/unit/Rules/AbstractRuleTest.php +++ b/tests/unit/Rules/AbstractRuleTest.php @@ -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], + ]; + } } diff --git a/tests/unit/Rules/AllOfTest.php b/tests/unit/Rules/AllOfTest.php index c582631f..abb1b9f3 100644 --- a/tests/unit/Rules/AllOfTest.php +++ b/tests/unit/Rules/AllOfTest.php @@ -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; diff --git a/tests/unit/Rules/AlnumTest.php b/tests/unit/Rules/AlnumTest.php index d29d0751..d6870ed0 100644 --- a/tests/unit/Rules/AlnumTest.php +++ b/tests/unit/Rules/AlnumTest.php @@ -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(), ''], diff --git a/tests/unit/Rules/AlphaTest.php b/tests/unit/Rules/AlphaTest.php index 3312eb0e..bdf72368 100644 --- a/tests/unit/Rules/AlphaTest.php +++ b/tests/unit/Rules/AlphaTest.php @@ -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(), ''], diff --git a/tests/unit/Rules/AlwaysInvalidTest.php b/tests/unit/Rules/AlwaysInvalidTest.php index 8d0f11ca..ae051ec4 100644 --- a/tests/unit/Rules/AlwaysInvalidTest.php +++ b/tests/unit/Rules/AlwaysInvalidTest.php @@ -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)); - } } diff --git a/tests/unit/Rules/AlwaysValidTest.php b/tests/unit/Rules/AlwaysValidTest.php index 29f06e5a..e56c04ee 100644 --- a/tests/unit/Rules/AlwaysValidTest.php +++ b/tests/unit/Rules/AlwaysValidTest.php @@ -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)); - } } diff --git a/tests/unit/Rules/ArrayTypeTest.php b/tests/unit/Rules/ArrayTypeTest.php index d468ef32..863a11d4 100644 --- a/tests/unit/Rules/ArrayTypeTest.php +++ b/tests/unit/Rules/ArrayTypeTest.php @@ -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(); diff --git a/tests/unit/Rules/ArrayValTest.php b/tests/unit/Rules/ArrayValTest.php index 11526bb2..aeed1726 100644 --- a/tests/unit/Rules/ArrayValTest.php +++ b/tests/unit/Rules/ArrayValTest.php @@ -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(); diff --git a/tests/unit/Rules/AttributeTest.php b/tests/unit/Rules/AttributeTest.php index e6e3132e..8d4dd74e 100644 --- a/tests/unit/Rules/AttributeTest.php +++ b/tests/unit/Rules/AttributeTest.php @@ -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()], diff --git a/tests/unit/Rules/Base64Test.php b/tests/unit/Rules/Base64Test.php index b01143ef..0c7ad3eb 100644 --- a/tests/unit/Rules/Base64Test.php +++ b/tests/unit/Rules/Base64Test.php @@ -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(); diff --git a/tests/unit/Rules/BaseTest.php b/tests/unit/Rules/BaseTest.php index 0c71b2e3..667949c3 100644 --- a/tests/unit/Rules/BaseTest.php +++ b/tests/unit/Rules/BaseTest.php @@ -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), ''], diff --git a/tests/unit/Rules/BetweenTest.php b/tests/unit/Rules/BetweenTest.php index 04378d42..f8ae08b7 100644 --- a/tests/unit/Rules/BetweenTest.php +++ b/tests/unit/Rules/BetweenTest.php @@ -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], + ]; + } } diff --git a/tests/unit/Rules/BoolTypeTest.php b/tests/unit/Rules/BoolTypeTest.php index 234639ee..a35c98e7 100644 --- a/tests/unit/Rules/BoolTypeTest.php +++ b/tests/unit/Rules/BoolTypeTest.php @@ -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(); diff --git a/tests/unit/Rules/BoolValTest.php b/tests/unit/Rules/BoolValTest.php index 9890c477..f763f469 100644 --- a/tests/unit/Rules/BoolValTest.php +++ b/tests/unit/Rules/BoolValTest.php @@ -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(); diff --git a/tests/unit/Rules/BsnTest.php b/tests/unit/Rules/BsnTest.php index 2dfc47d3..fb9faf46 100644 --- a/tests/unit/Rules/BsnTest.php +++ b/tests/unit/Rules/BsnTest.php @@ -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(); diff --git a/tests/unit/Rules/CallableTypeTest.php b/tests/unit/Rules/CallableTypeTest.php index b4035d40..7b2a6cf2 100644 --- a/tests/unit/Rules/CallableTypeTest.php +++ b/tests/unit/Rules/CallableTypeTest.php @@ -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(); diff --git a/tests/unit/Rules/CallbackTest.php b/tests/unit/Rules/CallbackTest.php index 440150fe..d85459d4 100644 --- a/tests/unit/Rules/CallbackTest.php +++ b/tests/unit/Rules/CallbackTest.php @@ -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 [ [ diff --git a/tests/unit/Rules/CharsetTest.php b/tests/unit/Rules/CharsetTest.php index adf7eb7b..609ac8e7 100644 --- a/tests/unit/Rules/CharsetTest.php +++ b/tests/unit/Rules/CharsetTest.php @@ -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'); diff --git a/tests/unit/Rules/CnhTest.php b/tests/unit/Rules/CnhTest.php index 340d73c1..6362d629 100644 --- a/tests/unit/Rules/CnhTest.php +++ b/tests/unit/Rules/CnhTest.php @@ -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(); diff --git a/tests/unit/Rules/CnpjTest.php b/tests/unit/Rules/CnpjTest.php index 83e1adf0..d2000f75 100644 --- a/tests/unit/Rules/CnpjTest.php +++ b/tests/unit/Rules/CnpjTest.php @@ -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(); diff --git a/tests/unit/Rules/ConsonantTest.php b/tests/unit/Rules/ConsonantTest.php index 90e6ef75..d4414c0a 100644 --- a/tests/unit/Rules/ConsonantTest.php +++ b/tests/unit/Rules/ConsonantTest.php @@ -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(); diff --git a/tests/unit/Rules/ContainsAnyTest.php b/tests/unit/Rules/ContainsAnyTest.php index b1327de5..1fdf37df 100644 --- a/tests/unit/Rules/ContainsAnyTest.php +++ b/tests/unit/Rules/ContainsAnyTest.php @@ -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']], diff --git a/tests/unit/Rules/ContainsTest.php b/tests/unit/Rules/ContainsTest.php index 1077ae2e..1d2dbe3b 100644 --- a/tests/unit/Rules/ContainsTest.php +++ b/tests/unit/Rules/ContainsTest.php @@ -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), ''], diff --git a/tests/unit/Rules/ControlTest.php b/tests/unit/Rules/ControlTest.php index c5d01838..519afe36 100644 --- a/tests/unit/Rules/ControlTest.php +++ b/tests/unit/Rules/ControlTest.php @@ -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(); diff --git a/tests/unit/Rules/CountableTest.php b/tests/unit/Rules/CountableTest.php index 18bf4572..624e4afc 100644 --- a/tests/unit/Rules/CountableTest.php +++ b/tests/unit/Rules/CountableTest.php @@ -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(); diff --git a/tests/unit/Rules/CountryCodeTest.php b/tests/unit/Rules/CountryCodeTest.php index 53c41cb0..408ef324 100644 --- a/tests/unit/Rules/CountryCodeTest.php +++ b/tests/unit/Rules/CountryCodeTest.php @@ -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'], diff --git a/tests/unit/Rules/CpfTest.php b/tests/unit/Rules/CpfTest.php index b753a141..4bd83422 100644 --- a/tests/unit/Rules/CpfTest.php +++ b/tests/unit/Rules/CpfTest.php @@ -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(); diff --git a/tests/unit/Rules/CreditCardTest.php b/tests/unit/Rules/CreditCardTest.php index 7e5a5029..f6d8f6af 100644 --- a/tests/unit/Rules/CreditCardTest.php +++ b/tests/unit/Rules/CreditCardTest.php @@ -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); diff --git a/tests/unit/Rules/CurrencyCodeTest.php b/tests/unit/Rules/CurrencyCodeTest.php index fbb2245c..2fae9d53 100644 --- a/tests/unit/Rules/CurrencyCodeTest.php +++ b/tests/unit/Rules/CurrencyCodeTest.php @@ -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(); diff --git a/tests/unit/Rules/DateTest.php b/tests/unit/Rules/DateTest.php index 87f8b19b..bd7ba103 100644 --- a/tests/unit/Rules/DateTest.php +++ b/tests/unit/Rules/DateTest.php @@ -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'], + ]; + } } diff --git a/tests/unit/Rules/DateTimeTest.php b/tests/unit/Rules/DateTimeTest.php index bb9a1361..10f34fb8 100644 --- a/tests/unit/Rules/DateTimeTest.php +++ b/tests/unit/Rules/DateTimeTest.php @@ -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); - } } diff --git a/tests/unit/Rules/DecimalTest.php b/tests/unit/Rules/DecimalTest.php index 7e715013..1535c3bc 100644 --- a/tests/unit/Rules/DecimalTest.php +++ b/tests/unit/Rules/DecimalTest.php @@ -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'], diff --git a/tests/unit/Rules/DigitTest.php b/tests/unit/Rules/DigitTest.php index 00ebaabf..45a2c77e 100644 --- a/tests/unit/Rules/DigitTest.php +++ b/tests/unit/Rules/DigitTest.php @@ -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(), ''], diff --git a/tests/unit/Rules/DirectoryTest.php b/tests/unit/Rules/DirectoryTest.php index 1b17a743..2e7836a5 100644 --- a/tests/unit/Rules/DirectoryTest.php +++ b/tests/unit/Rules/DirectoryTest.php @@ -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(); diff --git a/tests/unit/Rules/DomainTest.php b/tests/unit/Rules/DomainTest.php index 5f6563ce..fc22cf4c 100644 --- a/tests/unit/Rules/DomainTest.php +++ b/tests/unit/Rules/DomainTest.php @@ -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], diff --git a/tests/unit/Rules/EachTest.php b/tests/unit/Rules/EachTest.php index da4ded8e..e22edb22 100644 --- a/tests/unit/Rules/EachTest.php +++ b/tests/unit/Rules/EachTest.php @@ -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 */ - private function createTraversableInput(int $firstValue, int $lastValue): Traversable + private static function createTraversableInput(int $firstValue, int $lastValue): Traversable { /** @var SplStack */ $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) { diff --git a/tests/unit/Rules/EmailTest.php b/tests/unit/Rules/EmailTest.php index 7936c4c7..6f2fbeda 100644 --- a/tests/unit/Rules/EmailTest.php +++ b/tests/unit/Rules/EmailTest.php @@ -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(); diff --git a/tests/unit/Rules/EndsWithTest.php b/tests/unit/Rules/EndsWithTest.php index 1cb7ebea..d967d8f4 100644 --- a/tests/unit/Rules/EndsWithTest.php +++ b/tests/unit/Rules/EndsWithTest.php @@ -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'), ''], diff --git a/tests/unit/Rules/EqualsTest.php b/tests/unit/Rules/EqualsTest.php index 36f3a3ab..f07f56c4 100644 --- a/tests/unit/Rules/EqualsTest.php +++ b/tests/unit/Rules/EqualsTest.php @@ -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')); - } } diff --git a/tests/unit/Rules/EquivalentTest.php b/tests/unit/Rules/EquivalentTest.php index 7c713588..0ea5c2db 100644 --- a/tests/unit/Rules/EquivalentTest.php +++ b/tests/unit/Rules/EquivalentTest.php @@ -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], diff --git a/tests/unit/Rules/EvenTest.php b/tests/unit/Rules/EvenTest.php index fbd6405b..20627678 100644 --- a/tests/unit/Rules/EvenTest.php +++ b/tests/unit/Rules/EvenTest.php @@ -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(), ''], diff --git a/tests/unit/Rules/ExecutableTest.php b/tests/unit/Rules/ExecutableTest.php index 9212c9a6..406f78a2 100644 --- a/tests/unit/Rules/ExecutableTest.php +++ b/tests/unit/Rules/ExecutableTest.php @@ -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(); diff --git a/tests/unit/Rules/ExistsTest.php b/tests/unit/Rules/ExistsTest.php index 7534988e..2be3a6cd 100644 --- a/tests/unit/Rules/ExistsTest.php +++ b/tests/unit/Rules/ExistsTest.php @@ -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(); diff --git a/tests/unit/Rules/ExtensionTest.php b/tests/unit/Rules/ExtensionTest.php index f9de66bc..eb212354 100644 --- a/tests/unit/Rules/ExtensionTest.php +++ b/tests/unit/Rules/ExtensionTest.php @@ -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'], diff --git a/tests/unit/Rules/FactorTest.php b/tests/unit/Rules/FactorTest.php index 79771f54..78a1c37f 100644 --- a/tests/unit/Rules/FactorTest.php +++ b/tests/unit/Rules/FactorTest.php @@ -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], diff --git a/tests/unit/Rules/FalseValTest.php b/tests/unit/Rules/FalseValTest.php index 1cf71ba4..fa08b9c1 100644 --- a/tests/unit/Rules/FalseValTest.php +++ b/tests/unit/Rules/FalseValTest.php @@ -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(); diff --git a/tests/unit/Rules/FibonacciTest.php b/tests/unit/Rules/FibonacciTest.php index ad877a13..089ef626 100644 --- a/tests/unit/Rules/FibonacciTest.php +++ b/tests/unit/Rules/FibonacciTest.php @@ -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(); diff --git a/tests/unit/Rules/FileTest.php b/tests/unit/Rules/FileTest.php index 119da027..59cf1d63 100644 --- a/tests/unit/Rules/FileTest.php +++ b/tests/unit/Rules/FileTest.php @@ -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(); diff --git a/tests/unit/Rules/FilterVarTest.php b/tests/unit/Rules/FilterVarTest.php index 614d84e0..b5a22e6e 100644 --- a/tests/unit/Rules/FilterVarTest.php +++ b/tests/unit/Rules/FilterVarTest.php @@ -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], diff --git a/tests/unit/Rules/FiniteTest.php b/tests/unit/Rules/FiniteTest.php index 3346c9fe..84414ca9 100644 --- a/tests/unit/Rules/FiniteTest.php +++ b/tests/unit/Rules/FiniteTest.php @@ -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(); diff --git a/tests/unit/Rules/FloatTypeTest.php b/tests/unit/Rules/FloatTypeTest.php index cc88434d..206cd689 100644 --- a/tests/unit/Rules/FloatTypeTest.php +++ b/tests/unit/Rules/FloatTypeTest.php @@ -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(); diff --git a/tests/unit/Rules/FloatValTest.php b/tests/unit/Rules/FloatValTest.php index af7bfbd4..18569b90 100644 --- a/tests/unit/Rules/FloatValTest.php +++ b/tests/unit/Rules/FloatValTest.php @@ -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(); diff --git a/tests/unit/Rules/GraphTest.php b/tests/unit/Rules/GraphTest.php index fa4bd063..661ff9b5 100644 --- a/tests/unit/Rules/GraphTest.php +++ b/tests/unit/Rules/GraphTest.php @@ -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(); diff --git a/tests/unit/Rules/GreaterThanTest.php b/tests/unit/Rules/GreaterThanTest.php index 527452a2..2f91f07e 100644 --- a/tests/unit/Rules/GreaterThanTest.php +++ b/tests/unit/Rules/GreaterThanTest.php @@ -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], diff --git a/tests/unit/Rules/HexRgbColorTest.php b/tests/unit/Rules/HexRgbColorTest.php index f10692f7..1930df06 100644 --- a/tests/unit/Rules/HexRgbColorTest.php +++ b/tests/unit/Rules/HexRgbColorTest.php @@ -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(); diff --git a/tests/unit/Rules/IbanTest.php b/tests/unit/Rules/IbanTest.php index 7456f865..3fb392d4 100644 --- a/tests/unit/Rules/IbanTest.php +++ b/tests/unit/Rules/IbanTest.php @@ -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(); diff --git a/tests/unit/Rules/IdenticalTest.php b/tests/unit/Rules/IdenticalTest.php index d4938baf..19ef96e8 100644 --- a/tests/unit/Rules/IdenticalTest.php +++ b/tests/unit/Rules/IdenticalTest.php @@ -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')); - } } diff --git a/tests/unit/Rules/ImageTest.php b/tests/unit/Rules/ImageTest.php index 0d711fd9..b8b5a289 100644 --- a/tests/unit/Rules/ImageTest.php +++ b/tests/unit/Rules/ImageTest.php @@ -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], + ]; + } } diff --git a/tests/unit/Rules/ImeiTest.php b/tests/unit/Rules/ImeiTest.php index da821597..c4589d0e 100644 --- a/tests/unit/Rules/ImeiTest.php +++ b/tests/unit/Rules/ImeiTest.php @@ -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(); diff --git a/tests/unit/Rules/InTest.php b/tests/unit/Rules/InTest.php index b98a8a8b..27511aa3 100644 --- a/tests/unit/Rules/InTest.php +++ b/tests/unit/Rules/InTest.php @@ -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], diff --git a/tests/unit/Rules/InfiniteTest.php b/tests/unit/Rules/InfiniteTest.php index ef1232a5..8cb8a55a 100644 --- a/tests/unit/Rules/InfiniteTest.php +++ b/tests/unit/Rules/InfiniteTest.php @@ -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(); diff --git a/tests/unit/Rules/InstanceTest.php b/tests/unit/Rules/InstanceTest.php index 4deaba45..c695b9ef 100644 --- a/tests/unit/Rules/InstanceTest.php +++ b/tests/unit/Rules/InstanceTest.php @@ -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), ''], diff --git a/tests/unit/Rules/IntTypeTest.php b/tests/unit/Rules/IntTypeTest.php index 646ae05c..c378179a 100644 --- a/tests/unit/Rules/IntTypeTest.php +++ b/tests/unit/Rules/IntTypeTest.php @@ -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(); diff --git a/tests/unit/Rules/IntValTest.php b/tests/unit/Rules/IntValTest.php index 5229f483..83331170 100644 --- a/tests/unit/Rules/IntValTest.php +++ b/tests/unit/Rules/IntValTest.php @@ -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(); diff --git a/tests/unit/Rules/IpTest.php b/tests/unit/Rules/IpTest.php index d78cc8cf..ac3b368b 100644 --- a/tests/unit/Rules/IpTest.php +++ b/tests/unit/Rules/IpTest.php @@ -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} */ diff --git a/tests/unit/Rules/IsbnTest.php b/tests/unit/Rules/IsbnTest.php index 2e54dfb8..326c2026 100644 --- a/tests/unit/Rules/IsbnTest.php +++ b/tests/unit/Rules/IsbnTest.php @@ -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(); diff --git a/tests/unit/Rules/IterableTypeTest.php b/tests/unit/Rules/IterableTypeTest.php index 1c884381..e9fe766d 100644 --- a/tests/unit/Rules/IterableTypeTest.php +++ b/tests/unit/Rules/IterableTypeTest.php @@ -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(); diff --git a/tests/unit/Rules/JsonTest.php b/tests/unit/Rules/JsonTest.php index d5d85ebe..cc184f5d 100644 --- a/tests/unit/Rules/JsonTest.php +++ b/tests/unit/Rules/JsonTest.php @@ -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(); diff --git a/tests/unit/Rules/KeySetTest.php b/tests/unit/Rules/KeySetTest.php index 4e677c88..f7322181 100644 --- a/tests/unit/Rules/KeySetTest.php +++ b/tests/unit/Rules/KeySetTest.php @@ -221,7 +221,7 @@ final class KeySetTest extends TestCase /** * @return mixed[][] */ - public function providerForInvalidArguments(): array + public static function providerForInvalidArguments(): array { return [ [''], diff --git a/tests/unit/Rules/KeyValueTest.php b/tests/unit/Rules/KeyValueTest.php index 86ec61de..0177b4fc 100644 --- a/tests/unit/Rules/KeyValueTest.php +++ b/tests/unit/Rules/KeyValueTest.php @@ -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'); diff --git a/tests/unit/Rules/LanguageCodeTest.php b/tests/unit/Rules/LanguageCodeTest.php index aa5fd306..d442903a 100644 --- a/tests/unit/Rules/LanguageCodeTest.php +++ b/tests/unit/Rules/LanguageCodeTest.php @@ -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'); - } } diff --git a/tests/unit/Rules/LeapDateTest.php b/tests/unit/Rules/LeapDateTest.php index 44b2c0a1..27ca10c7 100644 --- a/tests/unit/Rules/LeapDateTest.php +++ b/tests/unit/Rules/LeapDateTest.php @@ -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'], diff --git a/tests/unit/Rules/LeapYearTest.php b/tests/unit/Rules/LeapYearTest.php index dfe1d37f..511382cb 100644 --- a/tests/unit/Rules/LeapYearTest.php +++ b/tests/unit/Rules/LeapYearTest.php @@ -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(); diff --git a/tests/unit/Rules/LengthTest.php b/tests/unit/Rules/LengthTest.php index c19b436f..f49f26b8 100644 --- a/tests/unit/Rules/LengthTest.php +++ b/tests/unit/Rules/LengthTest.php @@ -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); - } } diff --git a/tests/unit/Rules/LessThanTest.php b/tests/unit/Rules/LessThanTest.php index 6d04cfc9..ce8d32ac 100644 --- a/tests/unit/Rules/LessThanTest.php +++ b/tests/unit/Rules/LessThanTest.php @@ -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], diff --git a/tests/unit/Rules/LowercaseTest.php b/tests/unit/Rules/LowercaseTest.php index e99d4ca6..0cbc0722 100644 --- a/tests/unit/Rules/LowercaseTest.php +++ b/tests/unit/Rules/LowercaseTest.php @@ -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(); diff --git a/tests/unit/Rules/LuhnTest.php b/tests/unit/Rules/LuhnTest.php index 1411b187..6e0e2b48 100644 --- a/tests/unit/Rules/LuhnTest.php +++ b/tests/unit/Rules/LuhnTest.php @@ -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(); diff --git a/tests/unit/Rules/MacAddressTest.php b/tests/unit/Rules/MacAddressTest.php index 37950190..c2d241fd 100644 --- a/tests/unit/Rules/MacAddressTest.php +++ b/tests/unit/Rules/MacAddressTest.php @@ -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(); diff --git a/tests/unit/Rules/MaxAgeTest.php b/tests/unit/Rules/MaxAgeTest.php index 3293fe86..3155932d 100644 --- a/tests/unit/Rules/MaxAgeTest.php +++ b/tests/unit/Rules/MaxAgeTest.php @@ -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')], diff --git a/tests/unit/Rules/MaxTest.php b/tests/unit/Rules/MaxTest.php index 63cc4550..2b4e8dbd 100644 --- a/tests/unit/Rules/MaxTest.php +++ b/tests/unit/Rules/MaxTest.php @@ -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], diff --git a/tests/unit/Rules/MimetypeTest.php b/tests/unit/Rules/MimetypeTest.php index 5370e50e..d1570112 100644 --- a/tests/unit/Rules/MimetypeTest.php +++ b/tests/unit/Rules/MimetypeTest.php @@ -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'], diff --git a/tests/unit/Rules/MinAgeTest.php b/tests/unit/Rules/MinAgeTest.php index 5a5b9b0f..5d8f2e7b 100644 --- a/tests/unit/Rules/MinAgeTest.php +++ b/tests/unit/Rules/MinAgeTest.php @@ -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')], diff --git a/tests/unit/Rules/MinTest.php b/tests/unit/Rules/MinTest.php index 2d0418fa..f78a8510 100644 --- a/tests/unit/Rules/MinTest.php +++ b/tests/unit/Rules/MinTest.php @@ -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 diff --git a/tests/unit/Rules/MultipleTest.php b/tests/unit/Rules/MultipleTest.php index 81aec39e..c2cdf462 100644 --- a/tests/unit/Rules/MultipleTest.php +++ b/tests/unit/Rules/MultipleTest.php @@ -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], diff --git a/tests/unit/Rules/NegativeTest.php b/tests/unit/Rules/NegativeTest.php index 26952a95..3504b937 100644 --- a/tests/unit/Rules/NegativeTest.php +++ b/tests/unit/Rules/NegativeTest.php @@ -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(); diff --git a/tests/unit/Rules/NfeAccessKeyTest.php b/tests/unit/Rules/NfeAccessKeyTest.php index 8f7fbd85..b62c3d32 100644 --- a/tests/unit/Rules/NfeAccessKeyTest.php +++ b/tests/unit/Rules/NfeAccessKeyTest.php @@ -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(); diff --git a/tests/unit/Rules/NifTest.php b/tests/unit/Rules/NifTest.php index c69d3e80..82062b9d 100644 --- a/tests/unit/Rules/NifTest.php +++ b/tests/unit/Rules/NifTest.php @@ -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(); diff --git a/tests/unit/Rules/NipTest.php b/tests/unit/Rules/NipTest.php index 5e0527d5..93671503 100644 --- a/tests/unit/Rules/NipTest.php +++ b/tests/unit/Rules/NipTest.php @@ -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(); diff --git a/tests/unit/Rules/NoTest.php b/tests/unit/Rules/NoTest.php index 8992c8c5..0f3b4e4d 100644 --- a/tests/unit/Rules/NoTest.php +++ b/tests/unit/Rules/NoTest.php @@ -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} */ diff --git a/tests/unit/Rules/NoWhitespaceTest.php b/tests/unit/Rules/NoWhitespaceTest.php index 69488dc9..fc7409d4 100644 --- a/tests/unit/Rules/NoWhitespaceTest.php +++ b/tests/unit/Rules/NoWhitespaceTest.php @@ -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(); diff --git a/tests/unit/Rules/NotBlankTest.php b/tests/unit/Rules/NotBlankTest.php index 63431d52..6412e9d3 100644 --- a/tests/unit/Rules/NotBlankTest.php +++ b/tests/unit/Rules/NotBlankTest.php @@ -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(); diff --git a/tests/unit/Rules/NotEmojiTest.php b/tests/unit/Rules/NotEmojiTest.php index 53400f19..6827cd9b 100644 --- a/tests/unit/Rules/NotEmojiTest.php +++ b/tests/unit/Rules/NotEmojiTest.php @@ -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(); diff --git a/tests/unit/Rules/NotEmptyTest.php b/tests/unit/Rules/NotEmptyTest.php index e7f651fd..0a2866ac 100644 --- a/tests/unit/Rules/NotEmptyTest.php +++ b/tests/unit/Rules/NotEmptyTest.php @@ -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(); diff --git a/tests/unit/Rules/NotOptionalTest.php b/tests/unit/Rules/NotOptionalTest.php index 6d8e6595..6a0f95b4 100644 --- a/tests/unit/Rules/NotOptionalTest.php +++ b/tests/unit/Rules/NotOptionalTest.php @@ -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(); diff --git a/tests/unit/Rules/NotTest.php b/tests/unit/Rules/NotTest.php index c0ad4826..8706416c 100644 --- a/tests/unit/Rules/NotTest.php +++ b/tests/unit/Rules/NotTest.php @@ -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()], diff --git a/tests/unit/Rules/NullTypeTest.php b/tests/unit/Rules/NullTypeTest.php index cd485c95..9970984a 100644 --- a/tests/unit/Rules/NullTypeTest.php +++ b/tests/unit/Rules/NullTypeTest.php @@ -26,7 +26,7 @@ final class NullTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new NullType(); @@ -38,7 +38,7 @@ final class NullTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new NullType(); diff --git a/tests/unit/Rules/NullableTest.php b/tests/unit/Rules/NullableTest.php index 3f00a989..66144d04 100644 --- a/tests/unit/Rules/NullableTest.php +++ b/tests/unit/Rules/NullableTest.php @@ -23,33 +23,6 @@ use stdClass; */ final class NullableTest extends TestCase { - /** - * Data provider for not nullable values. - * - * @return mixed[][] - */ - public function providerForNotNullable(): array - { - return [ - [''], - [1], - [[]], - [' '], - [0], - ['0'], - [0], - ['0.0'], - [false], - [['']], - [[' ']], - [[0]], - [['0']], - [[false]], - [[[''], [0]]], - [new stdClass()], - ]; - } - /** * @test */ @@ -153,4 +126,31 @@ final class NullableTest extends TestCase $rule = new Nullable($validatable); $rule->check($input); } + + /** + * Data provider for not nullable values. + * + * @return mixed[][] + */ + public static function providerForNotNullable(): array + { + return [ + [''], + [1], + [[]], + [' '], + [0], + ['0'], + [0], + ['0.0'], + [false], + [['']], + [[' ']], + [[0]], + [['0']], + [[false]], + [[[''], [0]]], + [new stdClass()], + ]; + } } diff --git a/tests/unit/Rules/NumberTest.php b/tests/unit/Rules/NumberTest.php index 549bfcd8..89abd89d 100644 --- a/tests/unit/Rules/NumberTest.php +++ b/tests/unit/Rules/NumberTest.php @@ -33,7 +33,7 @@ final class NumberTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Number(); @@ -52,7 +52,7 @@ final class NumberTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Number(); diff --git a/tests/unit/Rules/NumericValTest.php b/tests/unit/Rules/NumericValTest.php index 65110041..87d06a1f 100644 --- a/tests/unit/Rules/NumericValTest.php +++ b/tests/unit/Rules/NumericValTest.php @@ -27,7 +27,7 @@ final class NumericValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $numericVal = new NumericVal(); @@ -44,7 +44,7 @@ final class NumericValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $numericVal = new NumericVal(); diff --git a/tests/unit/Rules/ObjectTypeTest.php b/tests/unit/Rules/ObjectTypeTest.php index a36133a8..00898fa8 100644 --- a/tests/unit/Rules/ObjectTypeTest.php +++ b/tests/unit/Rules/ObjectTypeTest.php @@ -27,7 +27,7 @@ final class ObjectTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new ObjectType(); @@ -40,7 +40,7 @@ final class ObjectTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new ObjectType(); diff --git a/tests/unit/Rules/OddTest.php b/tests/unit/Rules/OddTest.php index ecc48bdc..3519210b 100644 --- a/tests/unit/Rules/OddTest.php +++ b/tests/unit/Rules/OddTest.php @@ -28,7 +28,7 @@ final class OddTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Odd(); @@ -43,7 +43,7 @@ final class OddTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Odd(); diff --git a/tests/unit/Rules/OptionalTest.php b/tests/unit/Rules/OptionalTest.php index a5173387..c44fa2cd 100644 --- a/tests/unit/Rules/OptionalTest.php +++ b/tests/unit/Rules/OptionalTest.php @@ -23,41 +23,6 @@ use stdClass; */ final class OptionalTest extends TestCase { - /** - * @return mixed[][] - */ - public function providerForOptional(): array - { - return [ - [null], - [''], - ]; - } - - /** - * @return mixed[][] - */ - public function providerForNotOptional(): array - { - return [ - [1], - [[]], - [' '], - [0], - ['0'], - [0], - ['0.0'], - [false], - [['']], - [[' ']], - [[0]], - [['0']], - [[false]], - [[[''], [0]]], - [new stdClass()], - ]; - } - /** * @dataProvider providerForOptional * @@ -165,4 +130,39 @@ final class OptionalTest extends TestCase $rule->check($input); } + + /** + * @return mixed[][] + */ + public static function providerForOptional(): array + { + return [ + [null], + [''], + ]; + } + + /** + * @return mixed[][] + */ + public static function providerForNotOptional(): array + { + return [ + [1], + [[]], + [' '], + [0], + ['0'], + [0], + ['0.0'], + [false], + [['']], + [[' ']], + [[0]], + [['0']], + [[false]], + [[[''], [0]]], + [new stdClass()], + ]; + } } diff --git a/tests/unit/Rules/PerfectSquareTest.php b/tests/unit/Rules/PerfectSquareTest.php index 8fa11590..9baf049e 100644 --- a/tests/unit/Rules/PerfectSquareTest.php +++ b/tests/unit/Rules/PerfectSquareTest.php @@ -26,7 +26,7 @@ final class PerfectSquareTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PerfectSquare(); @@ -47,7 +47,7 @@ final class PerfectSquareTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PerfectSquare(); diff --git a/tests/unit/Rules/PeselTest.php b/tests/unit/Rules/PeselTest.php index 6c77a353..5d2ff823 100644 --- a/tests/unit/Rules/PeselTest.php +++ b/tests/unit/Rules/PeselTest.php @@ -25,7 +25,7 @@ final class PeselTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Pesel(); @@ -44,7 +44,7 @@ final class PeselTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Pesel(); diff --git a/tests/unit/Rules/PhoneTest.php b/tests/unit/Rules/PhoneTest.php index 7b6b6e9a..bc749766 100644 --- a/tests/unit/Rules/PhoneTest.php +++ b/tests/unit/Rules/PhoneTest.php @@ -25,34 +25,6 @@ use Respect\Validation\Test\RuleTestCase; */ final class PhoneTest extends RuleTestCase { - /** - * {@inheritDoc} - */ - public function providerForValidInput(): array - { - return [ - [new Phone(), '+1 650 253 00 00'], - [new Phone(), '+7 (999) 999-99-99'], - [new Phone(), '+7(999)999-99-99'], - [new Phone(), '+7(999)999-9999'], - [new Phone('BR'), '+55 11 91111 1111'], - [new Phone('BR'), '11 91111 1111'], // no international prefix - [new Phone('BR'), '+5511911111111'], // no whitespace - [new Phone('BR'), '11911111111'], // no prefix, no whitespace - ]; - } - - /** - * {@inheritDoc} - */ - public function providerForInvalidInput(): array - { - return [ - [new Phone(), '+1-650-253-00-0'], - [new Phone('BR'), '+1 11 91111 1111'], // invalid + code for BR - ]; - } - public function testThrowsExceptionWithCountryName(): void { $phoneValidator = new Phone('BR'); @@ -72,4 +44,32 @@ final class PhoneTest extends RuleTestCase $phoneValidator->assert('abc'); } + + /** + * {@inheritDoc} + */ + public static function providerForValidInput(): array + { + return [ + [new Phone(), '+1 650 253 00 00'], + [new Phone(), '+7 (999) 999-99-99'], + [new Phone(), '+7(999)999-99-99'], + [new Phone(), '+7(999)999-9999'], + [new Phone('BR'), '+55 11 91111 1111'], + [new Phone('BR'), '11 91111 1111'], // no international prefix + [new Phone('BR'), '+5511911111111'], // no whitespace + [new Phone('BR'), '11911111111'], // no prefix, no whitespace + ]; + } + + /** + * {@inheritDoc} + */ + public static function providerForInvalidInput(): array + { + return [ + [new Phone(), '+1-650-253-00-0'], + [new Phone('BR'), '+1 11 91111 1111'], // invalid + code for BR + ]; + } } diff --git a/tests/unit/Rules/PhpLabelTest.php b/tests/unit/Rules/PhpLabelTest.php index 493f2be0..35e9d140 100644 --- a/tests/unit/Rules/PhpLabelTest.php +++ b/tests/unit/Rules/PhpLabelTest.php @@ -32,7 +32,7 @@ final class PhpLabelTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PhpLabel(); @@ -50,7 +50,7 @@ final class PhpLabelTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PhpLabel(); diff --git a/tests/unit/Rules/PisTest.php b/tests/unit/Rules/PisTest.php index 4f57aab2..7ba733a9 100644 --- a/tests/unit/Rules/PisTest.php +++ b/tests/unit/Rules/PisTest.php @@ -26,7 +26,7 @@ final class PisTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Pis(); @@ -48,7 +48,7 @@ final class PisTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Pis(); diff --git a/tests/unit/Rules/PolishIdCardTest.php b/tests/unit/Rules/PolishIdCardTest.php index c2d8bfdc..2c991b3e 100644 --- a/tests/unit/Rules/PolishIdCardTest.php +++ b/tests/unit/Rules/PolishIdCardTest.php @@ -23,7 +23,7 @@ final class PolishIdCardTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PolishIdCard(); @@ -37,7 +37,7 @@ final class PolishIdCardTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PolishIdCard(); diff --git a/tests/unit/Rules/PortugueseNifTest.php b/tests/unit/Rules/PortugueseNifTest.php index dfc4b12f..1f3f2002 100644 --- a/tests/unit/Rules/PortugueseNifTest.php +++ b/tests/unit/Rules/PortugueseNifTest.php @@ -19,7 +19,7 @@ final class PortugueseNifTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PortugueseNif(); @@ -49,7 +49,7 @@ final class PortugueseNifTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PortugueseNif(); diff --git a/tests/unit/Rules/PositiveTest.php b/tests/unit/Rules/PositiveTest.php index ae97ee62..cc8b388c 100644 --- a/tests/unit/Rules/PositiveTest.php +++ b/tests/unit/Rules/PositiveTest.php @@ -27,7 +27,7 @@ final class PositiveTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Positive(); @@ -42,7 +42,7 @@ final class PositiveTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Positive(); diff --git a/tests/unit/Rules/PostalCodeTest.php b/tests/unit/Rules/PostalCodeTest.php index 94244fd4..70362bfe 100644 --- a/tests/unit/Rules/PostalCodeTest.php +++ b/tests/unit/Rules/PostalCodeTest.php @@ -58,7 +58,7 @@ final class PostalCodeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new PostalCode('BR'), '02179-000'], @@ -98,7 +98,7 @@ final class PostalCodeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new PostalCode('BR'), '02179'], diff --git a/tests/unit/Rules/PrimeNumberTest.php b/tests/unit/Rules/PrimeNumberTest.php index fa2ee82f..b96199f4 100644 --- a/tests/unit/Rules/PrimeNumberTest.php +++ b/tests/unit/Rules/PrimeNumberTest.php @@ -26,7 +26,7 @@ final class PrimeNumberTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PrimeNumber(); @@ -43,7 +43,7 @@ final class PrimeNumberTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PrimeNumber(); diff --git a/tests/unit/Rules/PrintableTest.php b/tests/unit/Rules/PrintableTest.php index 3ee0b5f1..802f0efe 100644 --- a/tests/unit/Rules/PrintableTest.php +++ b/tests/unit/Rules/PrintableTest.php @@ -27,7 +27,7 @@ final class PrintableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Printable(); @@ -47,7 +47,7 @@ final class PrintableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Printable(); diff --git a/tests/unit/Rules/PublicDomainSuffixTest.php b/tests/unit/Rules/PublicDomainSuffixTest.php index 748c16f4..487e5967 100644 --- a/tests/unit/Rules/PublicDomainSuffixTest.php +++ b/tests/unit/Rules/PublicDomainSuffixTest.php @@ -22,7 +22,7 @@ final class PublicDomainSuffixTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new PublicDomainSuffix(); @@ -36,7 +36,7 @@ final class PublicDomainSuffixTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new PublicDomainSuffix(); diff --git a/tests/unit/Rules/PunctTest.php b/tests/unit/Rules/PunctTest.php index 599c056d..125a2ea3 100644 --- a/tests/unit/Rules/PunctTest.php +++ b/tests/unit/Rules/PunctTest.php @@ -29,7 +29,7 @@ final class PunctTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Punct(); @@ -46,7 +46,7 @@ final class PunctTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Punct(); diff --git a/tests/unit/Rules/ReadableTest.php b/tests/unit/Rules/ReadableTest.php index 1a275575..dec77290 100644 --- a/tests/unit/Rules/ReadableTest.php +++ b/tests/unit/Rules/ReadableTest.php @@ -27,7 +27,7 @@ final class ReadableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $file = self::fixture('valid-image.gif'); $rule = new Readable(); @@ -42,7 +42,7 @@ final class ReadableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $file = self::fixture('invalid-image.gif'); $rule = new Readable(); diff --git a/tests/unit/Rules/RegexTest.php b/tests/unit/Rules/RegexTest.php index f382a7ae..06fc0caa 100644 --- a/tests/unit/Rules/RegexTest.php +++ b/tests/unit/Rules/RegexTest.php @@ -25,7 +25,7 @@ final class RegexTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Regex('/^[a-z]+$/'), 'wpoiur'], @@ -37,7 +37,7 @@ final class RegexTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Regex('/^w+$/'), 'w poiur'], diff --git a/tests/unit/Rules/ResourceTypeTest.php b/tests/unit/Rules/ResourceTypeTest.php index 15f23c5b..f066267c 100644 --- a/tests/unit/Rules/ResourceTypeTest.php +++ b/tests/unit/Rules/ResourceTypeTest.php @@ -28,7 +28,7 @@ final class ResourceTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new ResourceType(); @@ -41,7 +41,7 @@ final class ResourceTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new ResourceType(); diff --git a/tests/unit/Rules/RomanTest.php b/tests/unit/Rules/RomanTest.php index efd81d95..ced85e80 100644 --- a/tests/unit/Rules/RomanTest.php +++ b/tests/unit/Rules/RomanTest.php @@ -25,7 +25,7 @@ final class RomanTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Roman(); @@ -48,7 +48,7 @@ final class RomanTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Roman(); diff --git a/tests/unit/Rules/ScalarValTest.php b/tests/unit/Rules/ScalarValTest.php index 6cfb0279..6773dde0 100644 --- a/tests/unit/Rules/ScalarValTest.php +++ b/tests/unit/Rules/ScalarValTest.php @@ -27,7 +27,7 @@ final class ScalarValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new ScalarVal(); @@ -44,7 +44,7 @@ final class ScalarValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new ScalarVal(); diff --git a/tests/unit/Rules/SizeTest.php b/tests/unit/Rules/SizeTest.php index 197ba906..e11e205a 100644 --- a/tests/unit/Rules/SizeTest.php +++ b/tests/unit/Rules/SizeTest.php @@ -28,10 +28,21 @@ use SplFileInfo; */ final class SizeTest extends RuleTestCase { + /** + * @test + */ + public function shouldThrowsAnExceptionWhenSizeIsNotValid(): void + { + $this->expectException(ComponentException::class); + $this->expectExceptionMessage('"42jb" is not a recognized file size'); + + new Size('42jb'); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $root = vfsStream::setup(); $file2Kb = vfsStream::newFile('2kb.txt') @@ -61,7 +72,7 @@ final class SizeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $root = vfsStream::setup(); $file2Kb = vfsStream::newFile('2kb.txt') @@ -85,15 +96,4 @@ final class SizeTest extends RuleTestCase 'PSR-7 UploadedFile' => [new Size('1MB', '1.1MB'), UploadedFileStub::createWithSize(1024)], ]; } - - /** - * @test - */ - public function shouldThrowsAnExceptionWhenSizeIsNotValid(): void - { - $this->expectException(ComponentException::class); - $this->expectExceptionMessage('"42jb" is not a recognized file size'); - - new Size('42jb'); - } } diff --git a/tests/unit/Rules/SlugTest.php b/tests/unit/Rules/SlugTest.php index af92df72..e6bd451c 100644 --- a/tests/unit/Rules/SlugTest.php +++ b/tests/unit/Rules/SlugTest.php @@ -28,7 +28,7 @@ final class SlugTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Slug(); @@ -43,7 +43,7 @@ final class SlugTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Slug(); diff --git a/tests/unit/Rules/SortedTest.php b/tests/unit/Rules/SortedTest.php index 76bc1d34..0ea0c46c 100644 --- a/tests/unit/Rules/SortedTest.php +++ b/tests/unit/Rules/SortedTest.php @@ -24,10 +24,20 @@ use stdClass; */ final class SortedTest extends RuleTestCase { + /** + * @test + */ + public function itShouldNotAcceptWrongSortingDirection(): void + { + $this->expectExceptionObject(new ComponentException('Direction should be either "ASC" or "DESC"')); + + new Sorted('something'); + } + /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'empty' => [new Sorted('ASC'), []], @@ -44,7 +54,7 @@ final class SortedTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'duplicate' => [new Sorted('ASC'), [1, 1, 1]], @@ -62,14 +72,4 @@ final class SortedTest extends RuleTestCase 'unsupported value (object)' => [new Sorted('DESC'), new stdClass() ], ]; } - - /** - * @test - */ - public function itShouldNotAcceptWrongSortingDirection(): void - { - $this->expectExceptionObject(new ComponentException('Direction should be either "ASC" or "DESC"')); - - new Sorted('something'); - } } diff --git a/tests/unit/Rules/SpaceTest.php b/tests/unit/Rules/SpaceTest.php index 6bee7e42..e06da45d 100644 --- a/tests/unit/Rules/SpaceTest.php +++ b/tests/unit/Rules/SpaceTest.php @@ -29,7 +29,7 @@ final class SpaceTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Space(); @@ -47,7 +47,7 @@ final class SpaceTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Space(); diff --git a/tests/unit/Rules/StartsWithTest.php b/tests/unit/Rules/StartsWithTest.php index 4b9b079b..3cbc3d49 100644 --- a/tests/unit/Rules/StartsWithTest.php +++ b/tests/unit/Rules/StartsWithTest.php @@ -26,7 +26,7 @@ final class StartsWithTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new StartsWith('foo'), ['foo', 'bar']], @@ -41,7 +41,7 @@ final class StartsWithTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new StartsWith('foo'), ''], diff --git a/tests/unit/Rules/StringTypeTest.php b/tests/unit/Rules/StringTypeTest.php index 17568823..51654011 100644 --- a/tests/unit/Rules/StringTypeTest.php +++ b/tests/unit/Rules/StringTypeTest.php @@ -27,7 +27,7 @@ final class StringTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new StringType(); @@ -40,7 +40,7 @@ final class StringTypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new StringType(); diff --git a/tests/unit/Rules/StringValTest.php b/tests/unit/Rules/StringValTest.php index 5db24809..85e6da55 100644 --- a/tests/unit/Rules/StringValTest.php +++ b/tests/unit/Rules/StringValTest.php @@ -28,7 +28,7 @@ final class StringValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new StringVal(); @@ -46,7 +46,7 @@ final class StringValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new StringVal(); diff --git a/tests/unit/Rules/SubdivisionCodeTest.php b/tests/unit/Rules/SubdivisionCodeTest.php index 341d3814..583c4a54 100644 --- a/tests/unit/Rules/SubdivisionCodeTest.php +++ b/tests/unit/Rules/SubdivisionCodeTest.php @@ -47,20 +47,6 @@ final class SubdivisionCodeTest extends TestCase new SubdivisionCode('JK'); } - /** - * @return mixed[][] - */ - public function providerForValidSubdivisionCodeInformation(): array - { - return [ - ['AQ', null], - ['BR', 'SP'], - ['MV', '00'], - ['US', 'CA'], - ['YT', ''], - ]; - } - /** * @dataProvider providerForValidSubdivisionCodeInformation * @@ -73,18 +59,6 @@ final class SubdivisionCodeTest extends TestCase self::assertTrue($countrySubdivision->validate($input)); } - /** - * @return mixed[][] - */ - public function providerForInvalidSubdivisionCodeInformation(): array - { - return [ - ['BR', 'CA'], - ['MV', 0], - ['US', 'CE'], - ]; - } - /** * @dataProvider providerForInvalidSubdivisionCodeInformation * @@ -111,4 +85,30 @@ final class SubdivisionCodeTest extends TestCase $countrySubdivision->assert('CA'); } + + /** + * @return mixed[][] + */ + public static function providerForValidSubdivisionCodeInformation(): array + { + return [ + ['AQ', null], + ['BR', 'SP'], + ['MV', '00'], + ['US', 'CA'], + ['YT', ''], + ]; + } + + /** + * @return mixed[][] + */ + public static function providerForInvalidSubdivisionCodeInformation(): array + { + return [ + ['BR', 'CA'], + ['MV', 0], + ['US', 'CE'], + ]; + } } diff --git a/tests/unit/Rules/SubsetTest.php b/tests/unit/Rules/SubsetTest.php index 8c1741a6..78eecd52 100644 --- a/tests/unit/Rules/SubsetTest.php +++ b/tests/unit/Rules/SubsetTest.php @@ -24,7 +24,7 @@ final class SubsetTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Subset([]), []], @@ -40,7 +40,7 @@ final class SubsetTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Subset([]), [1]], diff --git a/tests/unit/Rules/SymbolicLinkTest.php b/tests/unit/Rules/SymbolicLinkTest.php index 4e6c7c40..ec4f7971 100644 --- a/tests/unit/Rules/SymbolicLinkTest.php +++ b/tests/unit/Rules/SymbolicLinkTest.php @@ -29,7 +29,7 @@ final class SymbolicLinkTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new SymbolicLink(); @@ -43,7 +43,7 @@ final class SymbolicLinkTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new SymbolicLink(); diff --git a/tests/unit/Rules/TimeTest.php b/tests/unit/Rules/TimeTest.php index d877fb5a..08ed224e 100644 --- a/tests/unit/Rules/TimeTest.php +++ b/tests/unit/Rules/TimeTest.php @@ -23,49 +23,6 @@ use Respect\Validation\Test\RuleTestCase; */ final class TimeTest extends RuleTestCase { - /** - * {@inheritDoc} - */ - public function providerForValidInput(): array - { - return [ - [new Time(), '00:00:00'], - [new Time(), '23:20:59'], - [new Time('H:i'), '23:59'], - [new Time('g:i A'), '8:13 AM'], - [new Time('His'), 232059], - [new Time('H:i:s.u'), '08:16:01.000000'], - [new Time('ga'), '3am'], - ]; - } - - /** - * {@inheritDoc} - */ - public function providerForInvalidInput(): array - { - return [ - [new Time(), '00:00:60'], - [new Time(), '00:60:00'], - [new Time(), '24:00:00'], - [new Time(), '00:00'], - [new Time(), new DateTime()], - [new Time(), new DateTimeImmutable()], - [new Time(), ''], - ]; - } - - /** - * @return mixed[][] - */ - public function invalidFormatsProvider(): array - { - return [ - ['Y-m-d H:i:s'], - ['M g:i A'], - ]; - } - /** * @test * @@ -89,4 +46,47 @@ final class TimeTest extends RuleTestCase self::assertSame($format, $exception->getParam('format')); } + + /** + * @return mixed[][] + */ + public static function invalidFormatsProvider(): array + { + return [ + ['Y-m-d H:i:s'], + ['M g:i A'], + ]; + } + + /** + * {@inheritDoc} + */ + public static function providerForValidInput(): array + { + return [ + [new Time(), '00:00:00'], + [new Time(), '23:20:59'], + [new Time('H:i'), '23:59'], + [new Time('g:i A'), '8:13 AM'], + [new Time('His'), 232059], + [new Time('H:i:s.u'), '08:16:01.000000'], + [new Time('ga'), '3am'], + ]; + } + + /** + * {@inheritDoc} + */ + public static function providerForInvalidInput(): array + { + return [ + [new Time(), '00:00:60'], + [new Time(), '00:60:00'], + [new Time(), '24:00:00'], + [new Time(), '00:00'], + [new Time(), new DateTime()], + [new Time(), new DateTimeImmutable()], + [new Time(), ''], + ]; + } } diff --git a/tests/unit/Rules/TldTest.php b/tests/unit/Rules/TldTest.php index 3dbb7dfa..fe16be14 100644 --- a/tests/unit/Rules/TldTest.php +++ b/tests/unit/Rules/TldTest.php @@ -28,7 +28,7 @@ final class TldTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Tld(); @@ -46,7 +46,7 @@ final class TldTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Tld(); diff --git a/tests/unit/Rules/TrueValTest.php b/tests/unit/Rules/TrueValTest.php index 4d847649..fa00d4b3 100644 --- a/tests/unit/Rules/TrueValTest.php +++ b/tests/unit/Rules/TrueValTest.php @@ -25,7 +25,7 @@ final class TrueValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new TrueVal(); @@ -48,7 +48,7 @@ final class TrueValTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new TrueVal(); diff --git a/tests/unit/Rules/TypeTest.php b/tests/unit/Rules/TypeTest.php index 950406a7..0923b81c 100644 --- a/tests/unit/Rules/TypeTest.php +++ b/tests/unit/Rules/TypeTest.php @@ -39,7 +39,7 @@ final class TypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Type('array'), []], @@ -64,7 +64,7 @@ final class TypeTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Type('int'), '1'], diff --git a/tests/unit/Rules/UniqueTest.php b/tests/unit/Rules/UniqueTest.php index c2e4fb55..15ce9f51 100644 --- a/tests/unit/Rules/UniqueTest.php +++ b/tests/unit/Rules/UniqueTest.php @@ -25,7 +25,7 @@ final class UniqueTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Unique(); @@ -43,7 +43,7 @@ final class UniqueTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Unique(); diff --git a/tests/unit/Rules/UploadedTest.php b/tests/unit/Rules/UploadedTest.php index 892bb0b7..7e4ea794 100644 --- a/tests/unit/Rules/UploadedTest.php +++ b/tests/unit/Rules/UploadedTest.php @@ -34,7 +34,7 @@ final class UploadedTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Uploaded(); @@ -48,7 +48,7 @@ final class UploadedTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Uploaded(); diff --git a/tests/unit/Rules/UppercaseTest.php b/tests/unit/Rules/UppercaseTest.php index ba9cd601..253c83e1 100644 --- a/tests/unit/Rules/UppercaseTest.php +++ b/tests/unit/Rules/UppercaseTest.php @@ -27,7 +27,7 @@ final class UppercaseTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Uppercase(); @@ -49,7 +49,7 @@ final class UppercaseTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Uppercase(); diff --git a/tests/unit/Rules/UrlTest.php b/tests/unit/Rules/UrlTest.php index 8371a337..a7102bba 100644 --- a/tests/unit/Rules/UrlTest.php +++ b/tests/unit/Rules/UrlTest.php @@ -25,7 +25,7 @@ final class UrlTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $rule = new Url(); @@ -48,7 +48,7 @@ final class UrlTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Url(); diff --git a/tests/unit/Rules/UuidTest.php b/tests/unit/Rules/UuidTest.php index e9ecd008..159cf4a0 100644 --- a/tests/unit/Rules/UuidTest.php +++ b/tests/unit/Rules/UuidTest.php @@ -34,61 +34,6 @@ final class UuidTest extends RuleTestCase private const UUID_VERSION_4 = '25769c6c-d34d-4bfe-ba98-e0ee856f3e7a'; private const UUID_VERSION_5 = 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62'; - /** - * {@inheritDoc} - */ - public function providerForValidInput(): array - { - $sut = new Uuid(); - - return [ - 'any version with version 1' => [$sut, self::UUID_VERSION_1], - 'any version with version 3' => [$sut, self::UUID_VERSION_3], - 'any version with version 4' => [$sut, self::UUID_VERSION_4], - 'any version with version 5' => [$sut, self::UUID_VERSION_5], - 'version 1 with version 1' => [new Uuid(1), self::UUID_VERSION_1], - 'version 3 with version 3' => [new Uuid(3), self::UUID_VERSION_3], - 'version 4 with version 4' => [new Uuid(4), self::UUID_VERSION_4], - 'version 5 with version 5' => [new Uuid(5), self::UUID_VERSION_5], - ]; - } - - /** - * {@inheritDoc} - */ - public function providerForInvalidInput(): array - { - $sut = new Uuid(); - $sutVersion1 = new Uuid(1); - $sutVersion3 = new Uuid(3); - $sutVersion4 = new Uuid(4); - $sutVersion5 = new Uuid(5); - - return [ - 'empty' => [$sut, ''], - 'nil/empty' => [$sut, '00000000-0000-0000-0000-000000000000'], - 'not UUID' => [$sut, 'Not an UUID'], - 'invalid UUID' => [$sut, 'g71a18f4-3a13-11e7-a919-92ebcb67fe33'], - 'invalid format' => [$sut, 'a71a18f43a1311e7a91992ebcb67fe33'], - 'version 1 with version 3' => [$sutVersion1, self::UUID_VERSION_3], - 'version 1 with version 4' => [$sutVersion1, self::UUID_VERSION_4], - 'version 1 with version 5' => [$sutVersion1, self::UUID_VERSION_5], - 'version 3 with version 1' => [$sutVersion3, self::UUID_VERSION_1], - 'version 3 with version 4' => [$sutVersion3, self::UUID_VERSION_4], - 'version 3 with version 5' => [$sutVersion3, self::UUID_VERSION_5], - 'version 4 with version 1' => [$sutVersion4, self::UUID_VERSION_1], - 'version 4 with version 3' => [$sutVersion4, self::UUID_VERSION_3], - 'version 4 with version 5' => [$sutVersion4, self::UUID_VERSION_5], - 'version 5 with version 1' => [$sutVersion5, self::UUID_VERSION_1], - 'version 5 with version 3' => [$sutVersion5, self::UUID_VERSION_3], - 'version 5 with version 4' => [$sutVersion5, self::UUID_VERSION_4], - 'array' => [$sut, []], - 'boolean true' => [$sut, true], - 'boolean false' => [$sut, false], - 'object' => [$sut, new stdClass()], - ]; - } - /** * @test */ @@ -125,4 +70,59 @@ final class UuidTest extends RuleTestCase new Uuid($version); } + + /** + * {@inheritDoc} + */ + public static function providerForValidInput(): array + { + $sut = new Uuid(); + + return [ + 'any version with version 1' => [$sut, self::UUID_VERSION_1], + 'any version with version 3' => [$sut, self::UUID_VERSION_3], + 'any version with version 4' => [$sut, self::UUID_VERSION_4], + 'any version with version 5' => [$sut, self::UUID_VERSION_5], + 'version 1 with version 1' => [new Uuid(1), self::UUID_VERSION_1], + 'version 3 with version 3' => [new Uuid(3), self::UUID_VERSION_3], + 'version 4 with version 4' => [new Uuid(4), self::UUID_VERSION_4], + 'version 5 with version 5' => [new Uuid(5), self::UUID_VERSION_5], + ]; + } + + /** + * {@inheritDoc} + */ + public static function providerForInvalidInput(): array + { + $sut = new Uuid(); + $sutVersion1 = new Uuid(1); + $sutVersion3 = new Uuid(3); + $sutVersion4 = new Uuid(4); + $sutVersion5 = new Uuid(5); + + return [ + 'empty' => [$sut, ''], + 'nil/empty' => [$sut, '00000000-0000-0000-0000-000000000000'], + 'not UUID' => [$sut, 'Not an UUID'], + 'invalid UUID' => [$sut, 'g71a18f4-3a13-11e7-a919-92ebcb67fe33'], + 'invalid format' => [$sut, 'a71a18f43a1311e7a91992ebcb67fe33'], + 'version 1 with version 3' => [$sutVersion1, self::UUID_VERSION_3], + 'version 1 with version 4' => [$sutVersion1, self::UUID_VERSION_4], + 'version 1 with version 5' => [$sutVersion1, self::UUID_VERSION_5], + 'version 3 with version 1' => [$sutVersion3, self::UUID_VERSION_1], + 'version 3 with version 4' => [$sutVersion3, self::UUID_VERSION_4], + 'version 3 with version 5' => [$sutVersion3, self::UUID_VERSION_5], + 'version 4 with version 1' => [$sutVersion4, self::UUID_VERSION_1], + 'version 4 with version 3' => [$sutVersion4, self::UUID_VERSION_3], + 'version 4 with version 5' => [$sutVersion4, self::UUID_VERSION_5], + 'version 5 with version 1' => [$sutVersion5, self::UUID_VERSION_1], + 'version 5 with version 3' => [$sutVersion5, self::UUID_VERSION_3], + 'version 5 with version 4' => [$sutVersion5, self::UUID_VERSION_4], + 'array' => [$sut, []], + 'boolean true' => [$sut, true], + 'boolean false' => [$sut, false], + 'object' => [$sut, new stdClass()], + ]; + } } diff --git a/tests/unit/Rules/VersionTest.php b/tests/unit/Rules/VersionTest.php index e82af404..46166500 100644 --- a/tests/unit/Rules/VersionTest.php +++ b/tests/unit/Rules/VersionTest.php @@ -27,7 +27,7 @@ final class VersionTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Version(); @@ -45,7 +45,7 @@ final class VersionTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Version(); diff --git a/tests/unit/Rules/VideoUrlTest.php b/tests/unit/Rules/VideoUrlTest.php index 28b2e6bd..9d77172f 100644 --- a/tests/unit/Rules/VideoUrlTest.php +++ b/tests/unit/Rules/VideoUrlTest.php @@ -26,7 +26,7 @@ final class VideoUrlTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'vimeo service with subdomain' => [new VideoUrl('vimeo'), 'https://player.vimeo.com/video/71787467'], @@ -47,7 +47,7 @@ final class VideoUrlTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'vimeo service with youtube url' => [new VideoUrl('vimeo'), 'https://www.youtube.com/watch?v=netHLn9TScY'], diff --git a/tests/unit/Rules/VowelTest.php b/tests/unit/Rules/VowelTest.php index c33978cc..22ec3b02 100644 --- a/tests/unit/Rules/VowelTest.php +++ b/tests/unit/Rules/VowelTest.php @@ -28,7 +28,7 @@ final class VowelTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Vowel(); @@ -48,7 +48,7 @@ final class VowelTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $sut = new Vowel(); diff --git a/tests/unit/Rules/WhenTest.php b/tests/unit/Rules/WhenTest.php index ece1f0f9..7fa60957 100644 --- a/tests/unit/Rules/WhenTest.php +++ b/tests/unit/Rules/WhenTest.php @@ -26,7 +26,7 @@ final class WhenTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ 'all true' => [ @@ -75,7 +75,7 @@ final class WhenTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ 'bool (when = true, then = false, else = false)' => [ diff --git a/tests/unit/Rules/WritableTest.php b/tests/unit/Rules/WritableTest.php index d84431dd..cf4fefa1 100644 --- a/tests/unit/Rules/WritableTest.php +++ b/tests/unit/Rules/WritableTest.php @@ -31,7 +31,7 @@ final class WritableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { $sut = new Writable(); $filename = self::fixture('valid-image.png'); @@ -52,7 +52,7 @@ final class WritableTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { $rule = new Writable(); $filename = self::fixture('non-writable'); diff --git a/tests/unit/Rules/XdigitTest.php b/tests/unit/Rules/XdigitTest.php index 4fd47b91..e5ffa384 100644 --- a/tests/unit/Rules/XdigitTest.php +++ b/tests/unit/Rules/XdigitTest.php @@ -28,7 +28,7 @@ final class XdigitTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForValidInput(): array + public static function providerForValidInput(): array { return [ [new Xdigit(), 'FFF'], @@ -45,7 +45,7 @@ final class XdigitTest extends RuleTestCase /** * {@inheritDoc} */ - public function providerForInvalidInput(): array + public static function providerForInvalidInput(): array { return [ [new Xdigit(), ''], diff --git a/tests/unit/Rules/YesTest.php b/tests/unit/Rules/YesTest.php index df2a2288..3ea051a4 100644 --- a/tests/unit/Rules/YesTest.php +++ b/tests/unit/Rules/YesTest.php @@ -35,66 +35,6 @@ final class YesTest extends RuleTestCase */ private $locale; - /** - * {@inheritDoc} - */ - public function providerForValidInput(): array - { - $sut = new Yes(); - - return [ - 'Y' => [$sut, 'Y'], - 'Yea' => [$sut, 'Yea'], - 'Yeah' => [$sut, 'Yeah'], - 'Yep' => [$sut, 'Yep'], - 'Yes' => [$sut, 'Yes'], - 'with locale + starting with "Y"' => [new Yes(true), 'Yydoesnotmatter'], - ]; - } - - /** - * {@inheritDoc} - */ - public function providerForInvalidInput(): array - { - $sut = new Yes(); - - return [ - 'spanish' => [$sut, 'Si'], - 'portuguese' => [$sut, 'Sim'], - 'starting with "Y"' => [$sut, 'Yoo'], - 'boolean true' => [$sut, true], - 'array' => [$sut, ['Yes']], - 'object' => [$sut, new stdClass()], - 'int' => [$sut, random_int(1, PHP_INT_MAX)], - 'float' => [$sut, random_int(1, 9) / 10], - ]; - } - - /** - * @return string[][] - */ - public function providerForValidInputWithLocale(): array - { - return [ - 'nl' => ['nl_NL.UTF-8', 'Ja'], - 'pt' => ['pt_BR.UTF-8', 'Sim'], - 'ru' => ['ru_RU.UTF-8', 'да'], - ]; - } - - /** - * @return string[][] - */ - public function providerForInvalidInputWithLocale(): array - { - return [ - 'nl' => ['nl_NL.UTF-8', 'Sim'], - 'pt' => ['pt_BR.UTF-8', 'да'], - 'ru' => ['ru_RU.UTF-8', 'Ja'], - ]; - } - /** * @test * @@ -127,6 +67,66 @@ final class YesTest extends RuleTestCase self::assertInvalidInput(new Yes(true), $input); } + /** + * @return string[][] + */ + public static function providerForValidInputWithLocale(): array + { + return [ + 'nl' => ['nl_NL.UTF-8', 'Ja'], + 'pt' => ['pt_BR.UTF-8', 'Sim'], + 'ru' => ['ru_RU.UTF-8', 'да'], + ]; + } + + /** + * @return string[][] + */ + public static function providerForInvalidInputWithLocale(): array + { + return [ + 'nl' => ['nl_NL.UTF-8', 'Sim'], + 'pt' => ['pt_BR.UTF-8', 'да'], + 'ru' => ['ru_RU.UTF-8', 'Ja'], + ]; + } + + /** + * {@inheritDoc} + */ + public static function providerForValidInput(): array + { + $sut = new Yes(); + + return [ + 'Y' => [$sut, 'Y'], + 'Yea' => [$sut, 'Yea'], + 'Yeah' => [$sut, 'Yeah'], + 'Yep' => [$sut, 'Yep'], + 'Yes' => [$sut, 'Yes'], + 'with locale + starting with "Y"' => [new Yes(true), 'Yydoesnotmatter'], + ]; + } + + /** + * {@inheritDoc} + */ + public static function providerForInvalidInput(): array + { + $sut = new Yes(); + + return [ + 'spanish' => [$sut, 'Si'], + 'portuguese' => [$sut, 'Sim'], + 'starting with "Y"' => [$sut, 'Yoo'], + 'boolean true' => [$sut, true], + 'array' => [$sut, ['Yes']], + 'object' => [$sut, new stdClass()], + 'int' => [$sut, random_int(1, PHP_INT_MAX)], + 'float' => [$sut, random_int(1, 9) / 10], + ]; + } + /** * {@inheritDoc} */