diff --git a/README.md b/README.md index fbf9377..41d71df 100644 --- a/README.md +++ b/README.md @@ -71,55 +71,55 @@ public function isFalseOrNull( $value, $message ) : FluidValidator; ## Conditional methods ```php -public function when( $expression, $continue = 1 ) : FluidValidator; -public function whenIsString( $value, $continue = 1 ) : FluidValidator; -public function whenIsStringOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsNonEmptyString( $value, $continue = 1 ) : FluidValidator; -public function whenIsNonEmptyStringOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsNotEmpty( $value, $continue = 1 ) : FluidValidator; -public function whenIsNotEmptyOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsArray( $value, $continue = 1 ) : FluidValidator; -public function whenIsArrayOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsInt( $value, $continue = 1 ) : FluidValidator; -public function whenIsIntOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsIntInRange( $value, array $range, $continue = 1 ) : FluidValidator; -public function whenIsIntInRangeOrNull( $value, array $range, $continue = 1 ) : FluidValidator; -public function whenIsOneStringOf( $value, array $list, $continue = 1 ) : FluidValidator; -public function whenIsOneStringOfOrNull( $value, array $list, $continue = 1 ) : FluidValidator; -public function whenIsSubsetOf( $values, array $list, $continue = 1 ) : FluidValidator; -public function whenIsSubsetOfOrNull( $values, array $list, $continue = 1 ) : FluidValidator; -public function whenIsUuid( $value, $continue = 1 ) : FluidValidator; -public function whenIsUuidOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsEqual( $value1, $value2, $continue = 1 ) : FluidValidator; -public function whenIsNotEqual( $value1, $value2, $continue = 1 ) : FluidValidator; -public function whenIsSame( $value1, $value2, $continue = 1 ) : FluidValidator; -public function whenIsNotSame( $value1, $value2, $continue = 1 ) : FluidValidator; -public function whenIsNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsNotNull( $value, $continue = 1 ) : FluidValidator; -public function whenMatchesRegex( $value, $regex, $continue = 1 ) : FluidValidator; -public function whenMatchesRegexOrNull( $value, $regex, $continue = 1 ) : FluidValidator; -public function whenHasLength( $value, $length, $continue = 1 ) : FluidValidator; -public function whenHasLengthOrNull( $value, $length, $continue = 1 ) : FluidValidator; -public function whenHasMinLength( $value, $minLength, $continue = 1 ) : FluidValidator; -public function whenHasMinLengthOrNull( $value, $minLength, $continue = 1 ) : FluidValidator; -public function whenHasMaxLength( $value, $maxLength, $continue = 1 ) : FluidValidator; -public function whenHasMaxLengthOrNull( $value, $maxLength, $continue = 1 ) : FluidValidator; -public function whenCounts( $values, $count, $continue = 1 ) : FluidValidator; -public function whenCountsOrNull( $values, $count, $continue = 1 ) : FluidValidator; -public function whenIsEmail( $value, $continue = 1 ) : FluidValidator; -public function whenIsEmailOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsUrl( $value, $continue = 1 ) : FluidValidator; -public function whenIsUrlNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsJson( $value, $continue = 1 ) : FluidValidator; -public function whenIsJsonOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenHasKey( $values, $key, $continue = 1 ) : FluidValidator; -public function whenHasKeyOrNull( $values, $key, $continue = 1 ) : FluidValidator; -public function whenIsDate( $dateString, $format = 'Y-m-d', $continue = 1 ) : FluidValidator; -public function whenIsDateOrNull( $dateString, $format = 'Y-m-d', $continue = 1 ) : FluidValidator; -public function whenIsTrue( $value, $continue = 1 ) : FluidValidator; -public function whenIsTrueOrNull( $value, $continue = 1 ) : FluidValidator; -public function whenIsFalse( $value, $continue = 1 ) : FluidValidator; -public function whenIsFalseOrNull( $value, $continue = 1 ) : FluidValidator; +public function checkIf( $expression, $continue = 1 ) : FluidValidator; +public function ifIsString( $value, $continue = 1 ) : FluidValidator; +public function ifIsStringOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsNonEmptyString( $value, $continue = 1 ) : FluidValidator; +public function ifIsNonEmptyStringOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsNotEmpty( $value, $continue = 1 ) : FluidValidator; +public function ifIsNotEmptyOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsArray( $value, $continue = 1 ) : FluidValidator; +public function ifIsArrayOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsInt( $value, $continue = 1 ) : FluidValidator; +public function ifIsIntOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsIntInRange( $value, array $range, $continue = 1 ) : FluidValidator; +public function ifIsIntInRangeOrNull( $value, array $range, $continue = 1 ) : FluidValidator; +public function ifIsOneStringOf( $value, array $list, $continue = 1 ) : FluidValidator; +public function ifIsOneStringOfOrNull( $value, array $list, $continue = 1 ) : FluidValidator; +public function ifIsSubsetOf( $values, array $list, $continue = 1 ) : FluidValidator; +public function ifIsSubsetOfOrNull( $values, array $list, $continue = 1 ) : FluidValidator; +public function ifIsUuid( $value, $continue = 1 ) : FluidValidator; +public function ifIsUuidOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsEqual( $value1, $value2, $continue = 1 ) : FluidValidator; +public function ifIsNotEqual( $value1, $value2, $continue = 1 ) : FluidValidator; +public function ifIsSame( $value1, $value2, $continue = 1 ) : FluidValidator; +public function ifIsNotSame( $value1, $value2, $continue = 1 ) : FluidValidator; +public function ifIsNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsNotNull( $value, $continue = 1 ) : FluidValidator; +public function ifMatchesRegex( $value, $regex, $continue = 1 ) : FluidValidator; +public function ifMatchesRegexOrNull( $value, $regex, $continue = 1 ) : FluidValidator; +public function ifHasLength( $value, $length, $continue = 1 ) : FluidValidator; +public function ifHasLengthOrNull( $value, $length, $continue = 1 ) : FluidValidator; +public function ifHasMinLength( $value, $minLength, $continue = 1 ) : FluidValidator; +public function ifHasMinLengthOrNull( $value, $minLength, $continue = 1 ) : FluidValidator; +public function ifHasMaxLength( $value, $maxLength, $continue = 1 ) : FluidValidator; +public function ifHasMaxLengthOrNull( $value, $maxLength, $continue = 1 ) : FluidValidator; +public function ifCounts( $values, $count, $continue = 1 ) : FluidValidator; +public function ifCountsOrNull( $values, $count, $continue = 1 ) : FluidValidator; +public function ifIsEmail( $value, $continue = 1 ) : FluidValidator; +public function ifIsEmailOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsUrl( $value, $continue = 1 ) : FluidValidator; +public function ifIsUrlNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsJson( $value, $continue = 1 ) : FluidValidator; +public function ifIsJsonOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifHasKey( $values, $key, $continue = 1 ) : FluidValidator; +public function ifHasKeyOrNull( $values, $key, $continue = 1 ) : FluidValidator; +public function ifIsDate( $dateString, $format = 'Y-m-d', $continue = 1 ) : FluidValidator; +public function ifIsDateOrNull( $dateString, $format = 'Y-m-d', $continue = 1 ) : FluidValidator; +public function ifIsTrue( $value, $continue = 1 ) : FluidValidator; +public function ifIsTrueOrNull( $value, $continue = 1 ) : FluidValidator; +public function ifIsFalse( $value, $continue = 1 ) : FluidValidator; +public function ifIsFalseOrNull( $value, $continue = 1 ) : FluidValidator; ``` ## Non-validation methods diff --git a/composer.json b/composer.json index b34554f..a55fc00 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "hollodotme/fluid-validator", - "description": "Validating values with a fluid interfaced class", + "description": "Validating values with a fluent interfaced class", "minimum-stability": "dev", "prefer-stable": true, "license": "MIT", diff --git a/composer.lock b/composer.lock index 9568cf2..02ac1ec 100644 --- a/composer.lock +++ b/composer.lock @@ -331,16 +331,16 @@ }, { "name": "symfony/config", - "version": "v3.0.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "58680a6516a457a6c65044fe33586c4a81fdff01" + "reference": "8c83ff9a2ffbed1e606bc816db11ddc2385a16ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/58680a6516a457a6c65044fe33586c4a81fdff01", - "reference": "58680a6516a457a6c65044fe33586c4a81fdff01", + "url": "https://api.github.com/repos/symfony/config/zipball/8c83ff9a2ffbed1e606bc816db11ddc2385a16ee", + "reference": "8c83ff9a2ffbed1e606bc816db11ddc2385a16ee", "shasum": "" }, "require": { @@ -377,20 +377,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2015-12-26 13:39:53" + "time": "2016-01-21 09:38:31" }, { "name": "symfony/console", - "version": "v3.0.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "ebcdc507829df915f4ca23067bd59ee4ef61f6c3" + "reference": "5a02eaadaa285e2bb727eb6bbdfb8201fcd971b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/ebcdc507829df915f4ca23067bd59ee4ef61f6c3", - "reference": "ebcdc507829df915f4ca23067bd59ee4ef61f6c3", + "url": "https://api.github.com/repos/symfony/console/zipball/5a02eaadaa285e2bb727eb6bbdfb8201fcd971b0", + "reference": "5a02eaadaa285e2bb727eb6bbdfb8201fcd971b0", "shasum": "" }, "require": { @@ -437,20 +437,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2015-12-22 10:39:06" + "time": "2016-02-02 13:44:19" }, { "name": "symfony/filesystem", - "version": "v3.0.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "c2e59d11dccd135dc8f00ee97f34fe1de842e70c" + "reference": "064ac12afd2ceb8a2c1bfb7bed8e931c6dd1997f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/c2e59d11dccd135dc8f00ee97f34fe1de842e70c", - "reference": "c2e59d11dccd135dc8f00ee97f34fe1de842e70c", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/064ac12afd2ceb8a2c1bfb7bed8e931c6dd1997f", + "reference": "064ac12afd2ceb8a2c1bfb7bed8e931c6dd1997f", "shasum": "" }, "require": { @@ -486,7 +486,7 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2015-12-22 10:39:06" + "time": "2016-01-27 11:34:55" }, { "name": "symfony/polyfill-mbstring", @@ -549,16 +549,16 @@ }, { "name": "symfony/stopwatch", - "version": "v3.0.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "6aeac8907e3e1340a0033b0a9ec075f8e6524800" + "reference": "4a204804952ff267ace88cf499e0b4bb302a475e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/6aeac8907e3e1340a0033b0a9ec075f8e6524800", - "reference": "6aeac8907e3e1340a0033b0a9ec075f8e6524800", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/4a204804952ff267ace88cf499e0b4bb302a475e", + "reference": "4a204804952ff267ace88cf499e0b4bb302a475e", "shasum": "" }, "require": { @@ -594,20 +594,20 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2015-10-30 23:35:59" + "time": "2016-01-03 15:35:16" }, { "name": "symfony/yaml", - "version": "v3.0.1", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "3df409958a646dad2bc5046c3fb671ee24a1a691" + "reference": "3cf0709d7fe936e97bee9e954382e449003f1d9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/3df409958a646dad2bc5046c3fb671ee24a1a691", - "reference": "3df409958a646dad2bc5046c3fb671ee24a1a691", + "url": "https://api.github.com/repos/symfony/yaml/zipball/3cf0709d7fe936e97bee9e954382e449003f1d9a", + "reference": "3cf0709d7fe936e97bee9e954382e449003f1d9a", "shasum": "" }, "require": { @@ -643,7 +643,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-12-26 13:39:53" + "time": "2016-02-02 13:44:19" } ], "aliases": [], diff --git a/src/FluidValidator.php b/src/FluidValidator.php index f74767d..91b1a52 100644 --- a/src/FluidValidator.php +++ b/src/FluidValidator.php @@ -61,54 +61,54 @@ * @method FluidValidator isTrueOrNull($value, $message) * @method FluidValidator isFalse($value, $message) * @method FluidValidator isFalseOrNull($value, $message) - * @method FluidValidator whenIsString($value, $continue = 1) - * @method FluidValidator whenIsStringOrNull($value, $continue = 1) - * @method FluidValidator whenIsNonEmptyString($value, $continue = 1) - * @method FluidValidator whenIsNonEmptyStringOrNull($value, $continue = 1) - * @method FluidValidator whenIsNotEmpty($value, $continue = 1) - * @method FluidValidator whenIsNotEmptyOrNull($value, $continue = 1) - * @method FluidValidator whenIsArray($value, $continue = 1) - * @method FluidValidator whenIsArrayOrNull($value, $continue = 1) - * @method FluidValidator whenIsInt($value, $continue = 1) - * @method FluidValidator whenIsIntOrNull($value, $continue = 1) - * @method FluidValidator whenIsIntInRange($value, array $range, $continue = 1) - * @method FluidValidator whenIsIntInRangeOrNull($value, array $range, $continue = 1) - * @method FluidValidator whenIsOneStringOf($value, array $list, $continue = 1) - * @method FluidValidator whenIsOneStringOfOrNull($value, array $list, $continue = 1) - * @method FluidValidator whenIsSubsetOf($values, array $list, $continue = 1) - * @method FluidValidator whenIsSubsetOfOrNull($values, array $list, $continue = 1) - * @method FluidValidator whenIsUuid($value, $continue = 1) - * @method FluidValidator whenIsUuidOrNull($value, $continue = 1) - * @method FluidValidator whenIsEqual($value1, $value2, $continue = 1) - * @method FluidValidator whenIsNotEqual($value1, $value2, $continue = 1) - * @method FluidValidator whenIsSame($value1, $value2, $continue = 1) - * @method FluidValidator whenIsNotSame($value1, $value2, $continue = 1) - * @method FluidValidator whenIsNull($value, $continue = 1) - * @method FluidValidator whenIsNotNull($value, $continue = 1) - * @method FluidValidator whenMatchesRegex($value, $regex, $continue = 1) - * @method FluidValidator whenMatchesRegexOrNull($value, $regex, $continue = 1) - * @method FluidValidator whenHasLength($value, $length, $continue = 1) - * @method FluidValidator whenHasLengthOrNull($value, $length, $continue = 1) - * @method FluidValidator whenHasMinLength($value, $minLength, $continue = 1) - * @method FluidValidator whenHasMinLengthOrNull($value, $minLength, $continue = 1) - * @method FluidValidator whenHasMaxLength($value, $maxLength, $continue = 1) - * @method FluidValidator whenHasMaxLengthOrNull($value, $maxLength, $continue = 1) - * @method FluidValidator whenCounts($values, $count, $continue = 1) - * @method FluidValidator whenCountsOrNull($values, $count, $continue = 1) - * @method FluidValidator whenIsEmail($value, $continue = 1) - * @method FluidValidator whenIsEmailOrNull($value, $continue = 1) - * @method FluidValidator whenIsUrl($value, $continue = 1) - * @method FluidValidator whenIsUrlNull($value, $continue = 1) - * @method FluidValidator whenIsJson($value, $continue = 1) - * @method FluidValidator whenIsJsonOrNull($value, $continue = 1) - * @method FluidValidator whenHasKey($values, $key, $continue = 1) - * @method FluidValidator whenHasKeyOrNull($values, $key, $continue = 1) - * @method FluidValidator whenIsDate($dateString, $format = 'Y-m-d', $continue = 1) - * @method FluidValidator whenIsDateOrNull($dateString, $format = 'Y-m-d', $continue = 1) - * @method FluidValidator whenIsTrue($value, $continue = 1) - * @method FluidValidator whenIsTrueOrNull($value, $continue = 1) - * @method FluidValidator whenIsFalse($value, $continue = 1) - * @method FluidValidator whenIsFalseOrNull($value, $continue = 1) + * @method FluidValidator ifIsString($value, $continue) + * @method FluidValidator ifIsStringOrNull($value, $continue) + * @method FluidValidator ifIsNonEmptyString($value, $continue) + * @method FluidValidator ifIsNonEmptyStringOrNull($value, $continue) + * @method FluidValidator ifIsNotEmpty($value, $continue) + * @method FluidValidator ifIsNotEmptyOrNull($value, $continue) + * @method FluidValidator ifIsArray($value, $continue) + * @method FluidValidator ifIsArrayOrNull($value, $continue) + * @method FluidValidator ifIsInt($value, $continue) + * @method FluidValidator ifIsIntOrNull($value, $continue) + * @method FluidValidator ifIsIntInRange($value, array $range, $continue) + * @method FluidValidator ifIsIntInRangeOrNull($value, array $range, $continue) + * @method FluidValidator ifIsOneStringOf($value, array $list, $continue) + * @method FluidValidator ifIsOneStringOfOrNull($value, array $list, $continue) + * @method FluidValidator ifIsSubsetOf($values, array $list, $continue) + * @method FluidValidator ifIsSubsetOfOrNull($values, array $list, $continue) + * @method FluidValidator ifIsUuid($value, $continue) + * @method FluidValidator ifIsUuidOrNull($value, $continue) + * @method FluidValidator ifIsEqual($value1, $value2, $continue) + * @method FluidValidator ifIsNotEqual($value1, $value2, $continue) + * @method FluidValidator ifIsSame($value1, $value2, $continue) + * @method FluidValidator ifIsNotSame($value1, $value2, $continue) + * @method FluidValidator ifIsNull($value, $continue) + * @method FluidValidator ifIsNotNull($value, $continue) + * @method FluidValidator ifMatchesRegex($value, $regex, $continue) + * @method FluidValidator ifMatchesRegexOrNull($value, $regex, $continue) + * @method FluidValidator ifHasLength($value, $length, $continue) + * @method FluidValidator ifHasLengthOrNull($value, $length, $continue) + * @method FluidValidator ifHasMinLength($value, $minLength, $continue) + * @method FluidValidator ifHasMinLengthOrNull($value, $minLength, $continue) + * @method FluidValidator ifHasMaxLength($value, $maxLength, $continue) + * @method FluidValidator ifHasMaxLengthOrNull($value, $maxLength, $continue) + * @method FluidValidator ifCounts($values, $count, $continue) + * @method FluidValidator ifCountsOrNull($values, $count, $continue) + * @method FluidValidator ifIsEmail($value, $continue) + * @method FluidValidator ifIsEmailOrNull($value, $continue) + * @method FluidValidator ifIsUrl($value, $continue) + * @method FluidValidator ifIsUrlNull($value, $continue) + * @method FluidValidator ifIsJson($value, $continue) + * @method FluidValidator ifIsJsonOrNull($value, $continue) + * @method FluidValidator ifHasKey($values, $key, $continue) + * @method FluidValidator ifHasKeyOrNull($values, $key, $continue) + * @method FluidValidator ifIsDate($dateString, $format = 'Y-m-d', $continue) + * @method FluidValidator ifIsDateOrNull($dateString, $format = 'Y-m-d', $continue) + * @method FluidValidator ifIsTrue($value, $continue) + * @method FluidValidator ifIsTrueOrNull($value, $continue) + * @method FluidValidator ifIsFalse($value, $continue) + * @method FluidValidator ifIsFalseOrNull($value, $continue) * METHODEND */ class FluidValidator @@ -157,7 +157,7 @@ public function reset() * * @return $this */ - public function when( $expression, $continue = 1 ) + public function checkIf( $expression, $continue ) { if ( $this->skipCounter > 0 ) { @@ -207,11 +207,11 @@ public function getMessages() */ public function __call( $name, array $arguments ) { - if ( substr( $name, 0, 4 ) == 'when' ) + if ( substr( $name, 0, 2 ) == 'if' ) { - $methodName = substr( $name, 4 ); + $methodName = substr( $name, 2 ); - return $this->handleWhenMethods( $methodName, $arguments ); + return $this->handleIfMethods( $methodName, $arguments ); } else { @@ -226,20 +226,21 @@ public function __call( $name, array $arguments ) * @throws CheckMethodNotCallable * @return FluidValidator */ - private function handleWhenMethods( $methodName, array $arguments ) + private function handleIfMethods( $methodName, array $arguments ) { $checkMethod = 'check' . ucfirst( preg_replace( "#OrNull$#", '', $methodName ) ); $this->guardCheckMethodIsCallable( $checkMethod ); - $continue = array_pop( $arguments ); - $checkResult = call_user_func_array( [ $this, $checkMethod ], $arguments ); + $continue = array_pop( $arguments ); + $checkArguments = $arguments + [ '' ]; + $checkResult = call_user_func_array( [ $this, $checkMethod ], $checkArguments ); if ( $this->checkNullCondition( $methodName, $arguments[0] ) ) { $checkResult = true; } - return $this->when( $checkResult, $continue ); + return $this->checkIf( $checkResult, $continue ); } /** diff --git a/tests/Unit/Validators/FluidValidatorTest.php b/tests/Unit/Validators/FluidValidatorTest.php index c03f6e4..11b2f56 100644 --- a/tests/Unit/Validators/FluidValidatorTest.php +++ b/tests/Unit/Validators/FluidValidatorTest.php @@ -1168,7 +1168,7 @@ public function testCheckMethodNotFoundExceptionCarriesMethodName() } } - public function testWhenExcutesFollowingChecksIfConditionIsTrue() + public function testCheckIfExcutesFollowingChecksIfConditionIsTrue() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1179,7 +1179,7 @@ public function testWhenExcutesFollowingChecksIfConditionIsTrue() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( true, 2 ) + ->checkIf( true, 2 ) ->isNonEmptyString( '', 'Empty string 2' ) ->isNonEmptyString( '', 'Empty string 3' ) ->isArray( false, 'Not an array' ); @@ -1188,7 +1188,7 @@ public function testWhenExcutesFollowingChecksIfConditionIsTrue() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testWhenSkipsFollowingChecksIfConditionIsFalse() + public function testCheckIfSkipsFollowingChecksIfConditionIsFalse() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1197,7 +1197,7 @@ public function testWhenSkipsFollowingChecksIfConditionIsFalse() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( false, 2 ) + ->checkIf( false, 2 ) ->isNonEmptyString( '', 'Empty string 2' ) ->isNonEmptyString( '', 'Empty string 3' ) ->isArray( false, 'Not an array' ); @@ -1206,7 +1206,7 @@ public function testWhenSkipsFollowingChecksIfConditionIsFalse() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testDirectChainedWhenMethods1() + public function testDirectChainedCheckIfMethods1() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1216,8 +1216,8 @@ public function testDirectChainedWhenMethods1() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( true, 2 ) - ->when( false, 2 ) + ->checkIf( true, 2 ) + ->checkIf( false, 2 ) ->isNonEmptyString( '', 'Empty string 2.1' ) ->isNonEmptyString( '', 'Empty string 2.2' ) ->isNonEmptyString( '', 'Empty string 3' ) @@ -1227,7 +1227,7 @@ public function testDirectChainedWhenMethods1() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testDirectChainedWhenMethods2() + public function testDirectChainedCheckIfMethods2() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1236,8 +1236,8 @@ public function testDirectChainedWhenMethods2() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( false, 2 ) - ->when( true, 2 ) + ->checkIf( false, 2 ) + ->checkIf( true, 2 ) ->isNonEmptyString( '', 'Empty string 2.1' ) ->isNonEmptyString( '', 'Empty string 2.2' ) ->isNonEmptyString( '', 'Empty string 3' ) @@ -1247,7 +1247,7 @@ public function testDirectChainedWhenMethods2() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testDirectChainedWhenMethods3() + public function testDirectChainedCheckIfMethods3() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1256,8 +1256,8 @@ public function testDirectChainedWhenMethods3() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( false, 2 ) - ->when( false, 2 ) + ->checkIf( false, 2 ) + ->checkIf( false, 2 ) ->isNonEmptyString( '', 'Empty string 2.1' ) ->isNonEmptyString( '', 'Empty string 2.2' ) ->isNonEmptyString( '', 'Empty string 3' ) @@ -1267,7 +1267,7 @@ public function testDirectChainedWhenMethods3() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testDirectChainedWhenMethods4() + public function testDirectChainedCheckIfMethods4() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1279,8 +1279,8 @@ public function testDirectChainedWhenMethods4() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( true, 2 ) - ->when( true, 2 ) + ->checkIf( true, 2 ) + ->checkIf( true, 2 ) ->isNonEmptyString( '', 'Empty string 2.1' ) ->isNonEmptyString( '', 'Empty string 2.2' ) ->isNonEmptyString( '', 'Empty string 3' ) @@ -1290,7 +1290,7 @@ public function testDirectChainedWhenMethods4() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testIndirectChainedWhenMethods1() + public function testIndirectChainedCheckIfMethods1() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1301,9 +1301,9 @@ public function testIndirectChainedWhenMethods1() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( true, 3 ) + ->checkIf( true, 3 ) ->isNonEmptyString( '', 'Empty string 2' ) - ->when( false, 2 ) + ->checkIf( false, 2 ) ->isNonEmptyString( '', 'Empty string 2.1' ) ->isNonEmptyString( '', 'Empty string 2.2' ) ->isNonEmptyString( '', 'Empty string 3' ) @@ -1313,7 +1313,7 @@ public function testIndirectChainedWhenMethods1() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testIndirectChainedWhenMethods2() + public function testIndirectChainedCheckIfMethods2() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1322,9 +1322,9 @@ public function testIndirectChainedWhenMethods2() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( false, 3 ) + ->checkIf( false, 3 ) ->isNonEmptyString( '', 'Empty string 2' ) - ->when( true, 2 ) + ->checkIf( true, 2 ) ->isNonEmptyString( '', 'Empty string 2.1' ) ->isNonEmptyString( '', 'Empty string 2.2' ) ->isNonEmptyString( '', 'Empty string 3' ) @@ -1334,7 +1334,7 @@ public function testIndirectChainedWhenMethods2() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testIndirectChainedWhenMethods3() + public function testIndirectChainedCheckIfMethods3() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1343,9 +1343,9 @@ public function testIndirectChainedWhenMethods3() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( false, 3 ) + ->checkIf( false, 3 ) ->isNonEmptyString( '', 'Empty string 2' ) - ->when( false, 2 ) + ->checkIf( false, 2 ) ->isNonEmptyString( '', 'Empty string 2.1' ) ->isNonEmptyString( '', 'Empty string 2.2' ) ->isNonEmptyString( '', 'Empty string 3' ) @@ -1355,7 +1355,7 @@ public function testIndirectChainedWhenMethods3() $this->assertEquals( $expectedMessages, $validator->getMessages() ); } - public function testIndirectChainedWhenMethods4() + public function testIndirectChainedCheckIfMethods4() { $validator = new FluidValidator(); $expectedMessages = [ @@ -1368,9 +1368,9 @@ public function testIndirectChainedWhenMethods4() ]; $validator->isNonEmptyString( '', 'Empty string 1' ) - ->when( true, 3 ) + ->checkIf( true, 3 ) ->isNonEmptyString( '', 'Empty string 2' ) - ->when( true, 2 ) + ->checkIf( true, 2 ) ->isNonEmptyString( '', 'Empty string 2.1' ) ->isNonEmptyString( '', 'Empty string 2.2' ) ->isNonEmptyString( '', 'Empty string 3' ) @@ -1379,4 +1379,45 @@ public function testIndirectChainedWhenMethods4() $this->assertTrue( $validator->failed() ); $this->assertEquals( $expectedMessages, $validator->getMessages() ); } + + public function testIfMethods() + { + $validator = new FluidValidator(); + + $expectedMessages = [ + 'Empty string 2', + 'Is not one string of 1', + 'Is not one string of 2', + 'Not an array 1', + 'Is not equal 1', + 'Is not same 1', + 'Invalid date 1', + 'Not an URL 1', + 'Empty string 4', + 'Too long 1', + ]; + + $validator->isNonEmptyString( 'unit-test', 'Empty string 1' ) + ->ifIsNonEmptyString( 'unit-test', 1 ) + ->isNonEmptyString( '', 'Empty string 2' ) + ->ifCounts( [ 1, 2 ], 2, 2 ) + ->isOneStringOf( '3', [ '1', '2' ], 'Is not one string of 1' ) + ->isOneStringOfOrNull( '4', [ '1', '2' ], 'Is not one string of 2' ) + ->ifHasKey( [ 'unit' => 'test' ], 'test', 1 ) + ->counts( [ 1, 2 ], 3, 'Count is wrong' ) + ->isArray( 'no-array', 'Not an array 1' ) + ->ifHasLengthOrNull( null, 3, 2 ) + ->isEqual( 1, 2, 'Is not equal 1' ) + ->isSame( 1, 2, 'Is not same 1' ) + ->isDate( '1970-0101', 'Y-m-d', 'Invalid date 1' ) + ->ifHasLengthOrNull( null, 5, 2 ) + ->checkIf( true, 2 ) + ->isUrl( 'no-url', 'Not an URL 1' ) + ->isNonEmptyString( 'unit-test', 'Empty string 3' ) + ->isNonEmptyString( '', 'Empty string 4' ) + ->hasMaxLength( 'four', 3, 'Too long 1' ); + + $this->assertTrue( $validator->failed() ); + $this->assertEquals( $expectedMessages, $validator->getMessages() ); + } }