-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new validation rules for schema files and implement error handlin…
…g for invalid schema data. Add tests to verify the behavior.
- Loading branch information
Denis Smet
committed
Mar 10, 2024
1 parent
61a92e7
commit 2d6ffef
Showing
5 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,9 @@ public function testIsBool(): void | |
'"is_bool" at line 0, column "prop". Value "1" is not allowed. Allowed values: ["true", "false"].', | ||
(string)$rule->validate('1'), | ||
); | ||
|
||
$rule = new IsBool('prop', false); | ||
isSame(null, $rule->validate('1')); | ||
} | ||
|
||
public function testIsDomain(): void | ||
|
@@ -139,12 +142,15 @@ public function testIsDomain(): void | |
isSame(null, $rule->validate('sub-sub-example.qwerty')); | ||
isSame( | ||
'"is_domain" at line 0, column "prop". Value "example" is not a valid domain.', | ||
(string)(string)$rule->validate('example'), | ||
(string)$rule->validate('example'), | ||
); | ||
isSame( | ||
'"is_domain" at line 0, column "prop". Value "" is not a valid domain.', | ||
(string)$rule->validate(''), | ||
); | ||
|
||
$rule = new IsDomain('prop', false); | ||
isSame(null, $rule->validate('example')); | ||
} | ||
|
||
public function testIsEmail(): void | ||
|
@@ -154,8 +160,11 @@ public function testIsEmail(): void | |
isSame(null, $rule->validate('[email protected]')); | ||
isSame( | ||
'"is_email" at line 0, column "prop". Value "user:[email protected]" is not a valid email.', | ||
(string)(string)$rule->validate('user:[email protected]'), | ||
(string)$rule->validate('user:[email protected]'), | ||
); | ||
|
||
$rule = new IsEmail('prop', false); | ||
isSame(null, $rule->validate('user:[email protected]')); | ||
} | ||
|
||
public function testIsFloat(): void | ||
|
@@ -179,6 +188,9 @@ public function testIsFloat(): void | |
'"is_float" at line 0, column "prop". Value " 1" is not a float number.', | ||
(string)$rule->validate(' 1'), | ||
); | ||
|
||
$rule = new IsFloat('prop', false); | ||
isSame(null, $rule->validate(' 1')); | ||
} | ||
|
||
public function testIsInt(): void | ||
|
@@ -195,7 +207,7 @@ public function testIsInt(): void | |
); | ||
isSame( | ||
'"is_int" at line 0, column "prop". Value "1.1" is not an integer.', | ||
(string)(string)$rule->validate('1.1'), | ||
(string)$rule->validate('1.1'), | ||
); | ||
isSame( | ||
'"is_int" at line 0, column "prop". Value "1.0" is not an integer.', | ||
|
@@ -207,12 +219,15 @@ public function testIsInt(): void | |
); | ||
isSame( | ||
'"is_int" at line 0, column "prop". Value " 1" is not an integer.', | ||
(string)(string)$rule->validate(' 1'), | ||
(string)$rule->validate(' 1'), | ||
); | ||
isSame( | ||
'"is_int" at line 0, column "prop". Value "1 " is not an integer.', | ||
(string)(string)$rule->validate('1 '), | ||
(string)$rule->validate('1 '), | ||
); | ||
|
||
$rule = new IsInt('prop', false); | ||
isSame(null, $rule->validate(' 1')); | ||
} | ||
|
||
public function testIsIp(): void | ||
|
@@ -244,6 +259,9 @@ public function testIsLatitude(): void | |
'"is_latitude" at line 0, column "prop". Value "90.1.1.1.1" is not a float number.', | ||
(string)$rule->validate('90.1.1.1.1'), | ||
); | ||
|
||
$rule = new IsLatitude('prop', false); | ||
isSame(null, $rule->validate('90.1.1.1.1')); | ||
} | ||
|
||
public function testIsLongitude(): void | ||
|
@@ -269,6 +287,9 @@ public function testIsLongitude(): void | |
'"is_longitude" at line 0, column "prop". Value "1.0.0.0" is not a float number.', | ||
(string)$rule->validate('1.0.0.0'), | ||
); | ||
|
||
$rule = new IsLongitude('prop', false); | ||
isSame(null, $rule->validate('1.0.0.0')); | ||
} | ||
|
||
public function testIsUrl(): void | ||
|
@@ -285,6 +306,9 @@ public function testIsUrl(): void | |
'"is_url" at line 0, column "prop". Value "//example.com" is not a valid URL.', | ||
(string)$rule->validate('//example.com'), | ||
); | ||
|
||
$rule = new IsUrl('prop', false); | ||
isSame(null, $rule->validate('//example.com')); | ||
} | ||
|
||
public function testMin(): void | ||
|
@@ -436,6 +460,9 @@ public function testNotEmpty(): void | |
'"not_empty" at line 0, column "prop". Value is empty.', | ||
(string)$rule->validate(null), | ||
); | ||
|
||
$rule = new NotEmpty('prop', false); | ||
isSame(null, $rule->validate(null)); | ||
} | ||
|
||
public function testOnlyCapitalize(): void | ||
|
@@ -454,6 +481,9 @@ public function testOnlyCapitalize(): void | |
'"only_capitalize" at line 0, column "prop". Value "qwe Rty" should be in capitalize.', | ||
(string)$rule->validate('qwe Rty'), | ||
); | ||
|
||
$rule = new OnlyCapitalize('prop', false); | ||
isSame(null, $rule->validate('qwerty')); | ||
} | ||
|
||
public function testOnlyLowercase(): void | ||
|
@@ -472,6 +502,9 @@ public function testOnlyLowercase(): void | |
'"only_lowercase" at line 0, column "prop". Value "qwe Rty" should be in lowercase.', | ||
(string)$rule->validate('qwe Rty'), | ||
); | ||
|
||
$rule = new OnlyLowercase('prop', false); | ||
isSame(null, $rule->validate('Qwerty')); | ||
} | ||
|
||
public function testOnlyUppercase(): void | ||
|
@@ -489,6 +522,9 @@ public function testOnlyUppercase(): void | |
'"only_uppercase" at line 0, column "prop". Value "qwe Rty" is not uppercase.', | ||
(string)$rule->validate('qwe Rty'), | ||
); | ||
|
||
$rule = new OnlyUppercase('prop', false); | ||
isSame(null, $rule->validate('Qwerty')); | ||
} | ||
|
||
public function testPrecision(): void | ||
|
@@ -590,6 +626,9 @@ public function testUsaMarketName(): void | |
'Market name must have format "New York, NY".', | ||
(string)$rule->validate(', ST'), | ||
); | ||
|
||
$rule = new UsaMarketName('prop', false); | ||
isSame(null, $rule->validate(', ST')); | ||
} | ||
|
||
public function testIsUuid4(): void | ||
|
@@ -600,5 +639,8 @@ public function testIsUuid4(): void | |
'"is_uuid4" at line 0, column "prop". Value is not a valid UUID v4.', | ||
(string)$rule->validate('123'), | ||
); | ||
|
||
$rule = new IsUuid4('prop', false); | ||
isSame(null, $rule->validate('123')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"columns" : [ | ||
{ | ||
"name" : "seq", | ||
"rules" : {"not_empty" : true, "min" : 2} | ||
}, | ||
{ | ||
"name" : "bool", | ||
"rules" : {"not_empty" : true} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
return [ | ||
'columns' => [ | ||
[ | ||
'name' => 'seq', | ||
'rules' => ['not_empty' => true, 'min' => 2], | ||
], | ||
[ | ||
'name' => 'bool', | ||
'rules' => ['not_empty' => true], | ||
], | ||
], | ||
]; |