From 8a564678549a756f3e69f87c99ee0c8464120503 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Tue, 29 Mar 2016 00:35:40 +0200 Subject: [PATCH] Refactored usage of StringValidator Removed internal casting an extended String validation for objects Fixed unit tests --- CHANGELOG.md | 7 +- README.md | 5 + composer.json | 3 +- composer.lock | 7 +- src/FluidValidator.php | 82 ++++------ src/Validators/StringValidator.php | 149 ++++++++++-------- tests/Unit/Validators/FluidValidatorTest.php | 63 ++++---- tests/Unit/Validators/StringValidatorTest.php | 84 ++++------ 8 files changed, 192 insertions(+), 208 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 013d2bb..7f1c010 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ # CHANGELOG -## Changes in Version 1.3.1 +## Changes in Version 1.4.0 * Fixed issue #1 +* Fixed issue #2 +* Fixed issue #3 + +* Replaced [mbstring functions](http://php.net/manual/en/ref.mbstring.php) with [grapheme functions](http://php.net/manual/en/ref.intl.grapheme.php) +* Added test configuration for php7 ## Changes in Version 1.3.0 diff --git a/README.md b/README.md index 2ba2b90..b0622ba 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,11 @@ Validating data with a fluent interfaced class +## Requirements + +* PHP >= 5.5 +* [intl extension](http://php.net/manual/en/book.intl.php) + ## Installation ``` diff --git a/composer.json b/composer.json index a55fc00..951b2e5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "source": "https://github.com/hollodotme/fluid-validator" }, "require": { - "php": ">=5.5" + "php": ">=5.5", + "ext-intl": "*" }, "require-dev": { "satooshi/php-coveralls": "dev-master" diff --git a/composer.lock b/composer.lock index 4784317..ddce3aa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "28b901a5a29f7c0953bb69f98009658e", - "content-hash": "5fec01f7c6169b608e36d865cd0c4722", + "hash": "76d1fdfe5f9fdc584c55ae55be0d5a11", + "content-hash": "5d98309fe3a453992e698995c0bdd0cc", "packages": [], "packages-dev": [ { @@ -657,7 +657,8 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": ">=5.5" + "php": ">=5.5", + "ext-intl": "*" }, "platform-dev": [] } diff --git a/src/FluidValidator.php b/src/FluidValidator.php index 1400d25..635d99d 100644 --- a/src/FluidValidator.php +++ b/src/FluidValidator.php @@ -131,6 +131,9 @@ class FluidValidator /** @var CollectsMessages */ private $messageCollector; + /** @var StringValidator */ + private $stringValidator; + /** * @param int $mode * @param ProvidesValuesToValidate|null $dataProvider @@ -397,7 +400,20 @@ public function getValue( $var ) */ protected function checkIsString( $value ) { - return ( new StringValidator() )->isString( $this->getValue( $value ) ); + return $this->getStringValidator()->isString( $this->getValue( $value ) ); + } + + /** + * @return StringValidator + */ + private function getStringValidator() + { + if ( $this->stringValidator === null ) + { + $this->stringValidator = new StringValidator(); + } + + return $this->stringValidator; } /** @@ -407,7 +423,7 @@ protected function checkIsString( $value ) */ protected function checkIsNonEmptyString( $value ) { - return ( new StringValidator() )->isNonEmptyString( $this->getValue( $value ) ); + return $this->getStringValidator()->isNonEmptyString( $this->getValue( $value ) ); } /** @@ -437,7 +453,7 @@ protected function checkIsArray( $value ) */ protected function checkIsInt( $value ) { - return ( new StringValidator() )->isInt( $this->getValue( $value ) ); + return (is_int( $this->getValue( $value ) ) === true); } /** @@ -450,9 +466,7 @@ protected function checkIsIntInRange( $value, array $range ) { if ( $this->checkIsInt( $value ) ) { - $val = intval( strval( $this->getValue( $value ) ) ); - - return in_array( $val, $range, true ); + return in_array( $this->getValue( $value ), $range, true ); } else { @@ -470,9 +484,7 @@ protected function checkIsOneStringOf( $value, array $list ) { if ( $this->checkIsString( $value ) ) { - $val = strval( $this->getValue( $value ) ); - - return in_array( $val, $list, true ); + return in_array( $this->getValue( $value ), $list, true ); } else { @@ -507,7 +519,7 @@ protected function checkIsSubsetOf( $values, array $list ) */ protected function checkIsUuid( $value ) { - return ( new StringValidator() )->isUuid( $this->getValue( $value ) ); + return $this->getStringValidator()->isUuid( $this->getValue( $value ) ); } /** @@ -582,16 +594,7 @@ protected function checkIsNotNull( $value ) */ protected function checkMatchesRegex( $value, $regex ) { - if ( $this->checkIsString( $value ) ) - { - $val = strval( $this->getValue( $value ) ); - - return boolval( preg_match( $regex, $val ) ); - } - else - { - return false; - } + return $this->getStringValidator()->matchesRegex( $this->getValue( $value ), $regex ); } /** @@ -602,16 +605,7 @@ protected function checkMatchesRegex( $value, $regex ) */ protected function checkHasLength( $value, $length ) { - if ( $this->checkIsString( $value ) ) - { - $val = strval( $this->getValue( $value ) ); - - return (mb_strlen( $val, '8bit' ) == $length); - } - else - { - return false; - } + return $this->getStringValidator()->hasLength( $this->getValue( $value ), $length ); } /** @@ -622,16 +616,7 @@ protected function checkHasLength( $value, $length ) */ protected function checkHasMinLength( $value, $minLength ) { - if ( $this->checkIsString( $value ) ) - { - $val = strval( $this->getValue( $value ) ); - - return (mb_strlen( $val, '8bit' ) >= $minLength); - } - else - { - return false; - } + return $this->getStringValidator()->hasMinLength( $this->getValue( $value ), $minLength ); } /** @@ -642,16 +627,7 @@ protected function checkHasMinLength( $value, $minLength ) */ protected function checkHasMaxLength( $value, $maxLength ) { - if ( $this->checkIsString( $value ) ) - { - $val = strval( $this->getValue( $value ) ); - - return (mb_strlen( $val, '8bit' ) <= $maxLength); - } - else - { - return false; - } + return $this->getStringValidator()->hasMaxLength( $this->getValue( $value ), $maxLength ); } /** @@ -679,7 +655,7 @@ protected function checkCounts( $value, $count ) */ protected function checkIsEmail( $value ) { - return ( new StringValidator() )->isEmail( $this->getValue( $value ) ); + return $this->getStringValidator()->isEmail( $this->getValue( $value ) ); } /** @@ -689,7 +665,7 @@ protected function checkIsEmail( $value ) */ protected function checkIsUrl( $value ) { - return ( new StringValidator() )->isUrl( $this->getValue( $value ) ); + return $this->getStringValidator()->isUrl( $this->getValue( $value ) ); } /** @@ -699,7 +675,7 @@ protected function checkIsUrl( $value ) */ protected function checkIsJson( $value ) { - return ( new StringValidator() )->isJson( $this->getValue( $value ) ); + return $this->getStringValidator()->isJson( $this->getValue( $value ) ); } /** diff --git a/src/Validators/StringValidator.php b/src/Validators/StringValidator.php index 1a5767c..427bab9 100644 --- a/src/Validators/StringValidator.php +++ b/src/Validators/StringValidator.php @@ -27,29 +27,7 @@ class StringValidator */ public function isString( $value ) { - if ( is_object( $value ) ) - { - if ( !is_callable( [ $value, '__toString' ] ) ) - { - return false; - } - else - { - return true; - } - } - elseif ( !is_scalar( $value ) ) - { - return false; - } - elseif ( is_bool( $value ) ) - { - return false; - } - else - { - return true; - } + return (is_string( $value ) === true); } /** @@ -61,16 +39,7 @@ public function isNonEmptyString( $value ) { if ( $this->isString( $value ) ) { - $val = trim( strval( $value ) ); - - if ( $val === '' ) - { - return false; - } - else - { - return true; - } + return !empty($value); } else { @@ -83,13 +52,15 @@ public function isNonEmptyString( $value ) * * @return bool */ - public function isInt( $value ) + public function isUuid( $value ) { - if ( $this->isString( $value ) ) + if ( $this->isNonEmptyString( $value ) ) { - $val = strval( $value ); - - if ( is_numeric( $val ) && intval( $val ) == $val ) + if ( $value == self::UUID_NIL ) + { + return true; + } + elseif ( preg_match( "#" . self::UUID_VALID_PATTERN . "#", $value ) ) { return true; } @@ -109,17 +80,11 @@ public function isInt( $value ) * * @return bool */ - public function isUuid( $value ) + public function isEmail( $value ) { if ( $this->isNonEmptyString( $value ) ) { - $val = strval( $value ); - - if ( $val == self::UUID_NIL ) - { - return true; - } - elseif ( preg_match( "#" . self::UUID_VALID_PATTERN . "#", $val ) ) + if ( filter_var( $value, FILTER_VALIDATE_EMAIL ) ) { return true; } @@ -139,13 +104,28 @@ public function isUuid( $value ) * * @return bool */ - public function isEmail( $value ) + public function isUrl( $value ) { if ( $this->isNonEmptyString( $value ) ) { - $val = strval( $value ); + return boolval( filter_var( $value, FILTER_VALIDATE_URL ) ); + } + else + { + return false; + } + } - if ( filter_var( $val, FILTER_VALIDATE_EMAIL ) ) + /** + * @param mixed $value + * + * @return bool + */ + public function isJson( $value ) + { + if ( $this->isNonEmptyString( $value ) ) + { + if ( (json_decode( $value ) !== null) && json_last_error() === JSON_ERROR_NONE ) { return true; } @@ -161,17 +141,35 @@ public function isEmail( $value ) } /** - * @param mixed $value + * @param mixed $value + * @param string $regex * * @return bool */ - public function isUrl( $value ) + public function matchesRegex( $value, $regex ) { - if ( $this->isNonEmptyString( $value ) ) + if ( $this->isString( $value ) ) + { + return (bool)preg_match( $regex, $value ); + } + else { - $val = strval( $value ); + return false; + } + } - return boolval( filter_var( $val, FILTER_VALIDATE_URL ) ); + /** + * @param mixed $value + * @param int $length + + * +*@return bool + */ + public function hasLength( $value, $length ) + { + if ( $this->isString( $value ) ) + { + return ($this->getLength( $value ) == $length); } else { @@ -179,25 +177,46 @@ public function isUrl( $value ) } } + /** + * @param string $string + * + * @return int + */ + private function getLength( $string ) + { + return grapheme_strlen( $string ); + } + /** * @param mixed $value + * @param int $minLength * * @return bool */ - public function isJson( $value ) + public function hasMinLength( $value, $minLength ) { - if ( $this->isNonEmptyString( $value ) ) + if ( $this->isString( $value ) ) { - $val = strval( $value ); + return ($this->getLength( $value ) >= $minLength); + } + else + { + return false; + } + } - if ( (json_decode( $val ) !== null) && json_last_error() === JSON_ERROR_NONE ) - { - return true; - } - else - { - return false; - } + /** + * @param mixed $value + * @param int $maxLength + + * +*@return bool + */ + public function hasMaxLength( $value, $maxLength ) + { + if ( $this->isString( $value ) ) + { + return ($this->getLength( $value ) <= $maxLength); } else { diff --git a/tests/Unit/Validators/FluidValidatorTest.php b/tests/Unit/Validators/FluidValidatorTest.php index 803ad8e..cb5a3fb 100644 --- a/tests/Unit/Validators/FluidValidatorTest.php +++ b/tests/Unit/Validators/FluidValidatorTest.php @@ -130,21 +130,21 @@ public function isNonEmptyStringProvider() { return [ [ '', false, [ 'String is empty' ] ], - [ ' ', false, [ 'String is empty' ] ], - [ "\n", false, [ 'String is empty' ] ], - [ "\r", false, [ 'String is empty' ] ], - [ "\t", false, [ 'String is empty' ] ], - [ "\x0B", false, [ 'String is empty' ] ], - [ "\0", false, [ 'String is empty' ] ], + [ ' ', true, [ ] ], + [ "\n", true, [ ] ], + [ "\r", true, [ ] ], + [ "\t", true, [ ] ], + [ "\x0B", true, [ ] ], + [ "\0", true, [ ] ], [ "Unit-Test", true, [ ] ], [ "1", true, [ ] ], - [ "0", true, [ ] ], + [ "0", false, [ 'String is empty' ] ], [ "null", true, [ ] ], [ "1.23", true, [ ] ], - [ 12, true, [ ] ], - [ 12.3, true, [ ] ], + [ 12, false, [ 'String is empty' ] ], + [ 12.3, false, [ 'String is empty' ] ], [ new ValueObjects\ObjectWithToStringMethod( '' ), false, [ 'String is empty' ] ], - [ new ValueObjects\ObjectWithToStringMethod( 'Unit-Test' ), true, [ ] ], + [ new ValueObjects\ObjectWithToStringMethod( 'Unit-Test' ), false, [ 'String is empty' ] ], [ new ValueObjects\ObjectWithoutToStringMethod( 'Unit-Test' ), false, [ 'String is empty' ] ], [ new \stdClass(), false, [ 'String is empty' ] ], [ false, false, [ 'String is empty' ] ], @@ -252,16 +252,16 @@ public function isIntProvider() [ 0, true, [ ] ], [ 1, true, [ ] ], [ -1, true, [ ] ], - [ '-1', true, [ ] ], - [ '0', true, [ ] ], - [ '1', true, [ ] ], + [ '-1', false, [ 'Not an int' ] ], + [ '0', false, [ 'Not an int' ] ], + [ '1', false, [ 'Not an int' ] ], [ '13232345546548785456464121515454', false, [ 'Not an int' ] ], [ 13232345546548785456464121515454, false, [ 'Not an int' ] ], [ '12.3', false, [ 'Not an int' ] ], [ 12.3, false, [ 'Not an int' ] ], [ new \stdClass(), false, [ 'Not an int' ] ], [ new ValueObjects\ObjectWithToStringMethod( '' ), false, [ 'Not an int' ] ], - [ new ValueObjects\ObjectWithToStringMethod( '12345' ), true, [ ] ], + [ new ValueObjects\ObjectWithToStringMethod( '12345' ), false, [ 'Not an int' ] ], [ new ValueObjects\ObjectWithoutToStringMethod( '12345' ), false, [ 'Not an int' ] ], ]; } @@ -294,9 +294,9 @@ public function isIntInRangeProvider() [ -5, range( -5, +5 ), true, [ ] ], [ -6, range( -5, +5 ), false, [ 'Not in range' ] ], [ 6, range( -5, +5 ), false, [ 'Not in range' ] ], - [ '0', range( -5, +5 ), true, [ ] ], - [ '5', range( -5, +5 ), true, [ ] ], - [ '-5', range( -5, +5 ), true, [ ] ], + [ '0', range( -5, +5 ), false, [ 'Not in range' ] ], + [ '5', range( -5, +5 ), false, [ 'Not in range' ] ], + [ '-5', range( -5, +5 ), false, [ 'Not in range' ] ], [ '-6', range( -5, +5 ), false, [ 'Not in range' ] ], [ '6', range( -5, +5 ), false, [ 'Not in range' ] ], [ false, range( -5, +5 ), false, [ 'Not in range' ] ], @@ -304,7 +304,7 @@ public function isIntInRangeProvider() [ null, range( -5, +5 ), false, [ 'Not in range' ] ], [ new \stdClass(), range( -5, +5 ), false, [ 'Not in range' ] ], [ new ValueObjects\ObjectWithoutToStringMethod( '5' ), range( -5, +5 ), false, [ 'Not in range' ] ], - [ new ValueObjects\ObjectWithToStringMethod( '3' ), range( -5, +5 ), true, [ ] ], + [ new ValueObjects\ObjectWithToStringMethod( '3' ), range( -5, +5 ), false, [ 'Not in range' ] ], ]; } @@ -343,7 +343,7 @@ public function isOneStringOfProvider() new ValueObjects\ObjectWithoutToStringMethod( 'Yes' ), [ 'Yes', '', 'No' ], false, [ 'Not a string of' ], ], - [ new ValueObjects\ObjectWithToStringMethod( 'Yes' ), [ 'Yes', '', 'No' ], true, [ ] ], + [ new ValueObjects\ObjectWithToStringMethod( 'Yes' ), [ 'Yes', '', 'No' ], false, [ 'Not a string of' ] ], ]; } @@ -414,7 +414,10 @@ public function isUuidProvider() [ '01a2b3c4-D5F6-7a8b-9c0D-1E2f3a4B5c6D', true, [ ] ], [ 'AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE', true, [ ] ], [ '12345678-1234-5678-9101-121314151617', true, [ ] ], - [ new ValueObjects\ObjectWithToStringMethod( '12345678-1234-5678-9101-121314151617' ), true, [ ] ], + [ + new ValueObjects\ObjectWithToStringMethod( '12345678-1234-5678-9101-121314151617' ), false, + [ 'Not a uuid' ], + ], [ new ValueObjects\ObjectWithoutToStringMethod( '12345678-1234-5678-9101-121314151617' ), false, [ 'Not a uuid' ], @@ -756,10 +759,10 @@ public function lengthProvider() # Has length [ 'Unit', 4, true ], [ 'Unit-Test', 9, true ], - [ 123, 3, true ], - [ 'åèö', 6, true ], + [ 'åèö', 3, true ], # Has not length + [ 123, 3, false ], [ 'Unit', 3, false ], [ 123, 4, false ], [ null, 1, false ], @@ -792,10 +795,10 @@ public function minLengthProvider() [ 'Unit', 3, true ], [ 'Test', 2, true ], [ 'Unit-Test', 9, true ], - [ 'mœrely', 7, true ], - [ 1234, 3, true ], + [ 'mœrely', 6, true ], # Has not min length + [ 1234, 4, false ], [ 'Unit', 5, false ], [ 'Test', 6, false ], [ 'Unit-Test', 11, false ], @@ -831,14 +834,14 @@ public function maxLengthProvider() [ 'Unit', 5, true ], [ 'Test', 4, true ], [ 'Unit-Test', 10, true ], - [ 'åèö', 6, true ], - [ 123, 3, true ], + [ 'åèö', 3, true ], # Has not max length + [ 123, 3, false ], [ 'Unit', 3, false ], [ 'Test', 2, false ], [ 'Unit-Test', 8, false ], - [ 'åèö', 5, false ], + [ 'åèö', 2, false ], [ 123.1, 4, false ], [ null, 4, false ], [ new \stdClass(), 8, false ], @@ -914,9 +917,9 @@ public function emailProvider() [ 'email@example.museum', true ], [ 'email@example.co.jp', true ], [ 'firstname-lastname@example.com', true ], - [ new ValueObjects\ObjectWithToStringMethod( 'me@example.com' ), true ], # Invalid email addresses + [ new ValueObjects\ObjectWithToStringMethod( 'me@example.com' ), false ], [ '#@%^%#$@#$@#.com', false ], [ '@example.com', false ], [ 'Joe Smith ', false ], @@ -968,9 +971,9 @@ public function urlProvider() [ 'https://test.example.com', true ], [ 'ftp://test.example.com', true ], [ 'sftp://test.example.com', true ], - [ new ValueObjects\ObjectWithToStringMethod( 'sftp://test.example.com' ), true ], # Invalid URLs + [ new ValueObjects\ObjectWithToStringMethod( 'sftp://test.example.com' ), false ], [ '//example.com', false ], [ 'example.com', false ], [ 'test.example.com', false ], @@ -1003,13 +1006,13 @@ public function jsonProvider() return [ # Valid json [ '1234', true ], - [ 123.4, true ], [ '[]', true ], [ '{}', true ], [ '[123, 456, "Test"]', true ], [ '{"unit": "test"}', true ], # Invalid json + [ 123.4, false ], [ '', false ], [ '(1234)', false ], [ '("Unit-Test")', false ], diff --git a/tests/Unit/Validators/StringValidatorTest.php b/tests/Unit/Validators/StringValidatorTest.php index 7910bac..c5e0b6d 100644 --- a/tests/Unit/Validators/StringValidatorTest.php +++ b/tests/Unit/Validators/StringValidatorTest.php @@ -23,15 +23,18 @@ public function testValueIsString( $value, $expected ) public function isStringProvider() { return [ - [ 0, true ], - [ 1, true ], - [ 12345, true ], + # Yes + [ '', true ], + [ 'Test', true ], + # No + [ 0, false ], + [ 1, false ], + [ 12345, false ], [ null, false ], [ new \stdClass(), false ], [ new ValueObjects\ObjectWithoutToStringMethod( 'Test' ), false ], - [ new ValueObjects\ObjectWithToStringMethod( 'Test' ), true ], - [ 'Test', true ], - [ 1.234, true ], + [ new ValueObjects\ObjectWithToStringMethod( 'Test' ), false ], + [ 1.234, false ], [ true, false ], [ false, false ], ]; @@ -50,22 +53,24 @@ public function testValueIsNonEmptyString( $value, $expected ) public function isNonEmptyStringProvider() { return [ + # Yes [ '', false ], - [ ' ', false ], - [ "\n", false ], - [ "\r", false ], - [ "\t", false ], - [ "\x0B", false ], - [ "\0", false ], + [ ' ', true ], + [ "\n", true ], + [ "\r", true ], + [ "\t", true ], + [ "\x0B", true ], + [ "\0", true ], [ "Unit-Test", true ], [ "1", true ], - [ "0", true ], [ "null", true ], [ "1.23", true ], - [ 12, true ], - [ 12.3, true ], + # No + [ "0", false ], + [ 12, false ], + [ 12.3, false ], [ new ValueObjects\ObjectWithToStringMethod( '' ), false ], - [ new ValueObjects\ObjectWithToStringMethod( 'Unit-Test' ), true ], + [ new ValueObjects\ObjectWithToStringMethod( 'Unit-Test' ), false ], [ new ValueObjects\ObjectWithoutToStringMethod( 'Unit-Test' ), false ], [ new \stdClass(), false ], [ false, false ], @@ -74,39 +79,6 @@ public function isNonEmptyStringProvider() ]; } - /** - * @dataProvider isIntProvider - */ - public function testValueIsInt( $value, $expected ) - { - $result = ( new StringValidator() )->isInt( $value ); - - $this->assertSame( $expected, $result ); - } - - public function isIntProvider() - { - return [ - [ false, false ], - [ true, false ], - [ null, false ], - [ 0, true ], - [ 1, true ], - [ -1, true ], - [ '-1', true ], - [ '0', true ], - [ '1', true ], - [ '13232345546548785456464121515454', false ], - [ 13232345546548785456464121515454, false ], - [ '12.3', false ], - [ 12.3, false ], - [ new \stdClass(), false ], - [ new ValueObjects\ObjectWithToStringMethod( '' ), false ], - [ new ValueObjects\ObjectWithToStringMethod( '12345' ), true ], - [ new ValueObjects\ObjectWithoutToStringMethod( '12345' ), false ], - ]; - } - /** * @dataProvider isUuidProvider */ @@ -120,12 +92,14 @@ public function testValueIsAUuid( $value, $expected ) public function isUuidProvider() { return [ + # Yes [ '00000000-0000-0000-0000-000000000000', true ], [ '01a2b3c4-D5F6-7a8b-9c0D-1E2f3a4B5c6D', true ], [ 'AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE', true ], [ '12345678-1234-5678-9101-121314151617', true ], [ '12345678-1234-5678-9101-121314151617', true ], - [ new ValueObjects\ObjectWithToStringMethod( '12345678-1234-5678-9101-121314151617' ), true ], + # No + [ new ValueObjects\ObjectWithToStringMethod( '12345678-1234-5678-9101-121314151617' ), false ], [ new ValueObjects\ObjectWithoutToStringMethod( '12345678-1234-5678-9101-121314151617' ), false ], [ 'GGGGGGGG-HHHH-IIII-JJJJ-KKKKKKKKKKKK', false ], [ 0, false ], @@ -168,8 +142,8 @@ public function isEmailProvider() [ 'firstname-lastname@example.com', true ], [ 'much."more\ unusual"@example.com', true ], [ 'very.unusual."@".unusual.com@example.com', true ], - [ new ValueObjects\ObjectWithToStringMethod( 'me@example.com' ), true ], # Invalid addresses + [ new ValueObjects\ObjectWithToStringMethod( 'me@example.com' ), false ], [ 'email@123.123.123.123', false ], [ 'very."(),:;<>[]".VERY."very@\\ "very".unusual@strange.example.com', false ], [ 'me@-online.de', false ], @@ -224,13 +198,13 @@ public function isUrlProvider() [ new ValueObjects\ObjectWithoutToStringMethod( '//www.example.com' ), false ], [ 'http//www.example.com', false ], [ 'https//www.example.com', false ], + [ new ValueObjects\ObjectWithToStringMethod( '//www.example.com' ), false ], + [ '//www.example.com/cdn/images.png', false ], + [ '//www.example.com:8080/cdn/images.png', false ], # Valid urls [ 'ftp://www.example.com', true ], - [ new ValueObjects\ObjectWithToStringMethod( '//www.example.com' ), false ], [ 'http://www.example.com', true ], [ 'https://www.example.com', true ], - [ '//www.example.com/cdn/images.png', false ], - [ '//www.example.com:8080/cdn/images.png', false ], [ 'http://www.example.com:8080/cdn/images.png', true ], [ 'https://www.example.com:8080/cdn/images.png', true ], [ 'https://127.0.0.1:8080/', true ], @@ -261,7 +235,7 @@ public function isJsonProvider() [ '["Unit","Test",]', false ], [ '{"Unit":"Test"}', true ], [ '{"Unit":"Test",}', false ], - [ new ValueObjects\ObjectWithToStringMethod( '{"Unit":"Test"}' ), true ], + [ new ValueObjects\ObjectWithToStringMethod( '{"Unit":"Test"}' ), false ], [ new ValueObjects\ObjectWithoutToStringMethod( '{"Unit":"Test"}' ), false ], [ new \stdClass(), false ], ];