Repository navigation
Update the LIVR test suite and fix the bugs it finds - #31
Merged
Merged
Conversation
The test suite is copied from the LIVR repository. As before, the copy keeps
negative/22-not_empty_list and negative/27-any_object adjusted, as PHP decodes
{} and [] to the same array.
- or: pass empty values to the rule sets, so "required" and "not_empty" in
them work
- or: do not unwrap a list in the first argument, as a set of rules can be a
list: { or: [['email', 'to_lc'], 'positive_integer'] }
- list_of_different_objects, variable_object: return FORMAT_ERROR for array
selector values instead of throwing a TypeError
- list_of_different_objects: return the errors when an item is not an object
(it was dropped from the output), and FORMAT_ERROR when the value is not a
list (it became an empty list)
- equal_to_field: compare values as strings, as "==" finds "10" and "1e1"
equal, and do not warn when the other field is missing
Found with the tests of the JavaScript implementation that apply to PHP.
- Auto trim trims the values of lists too, not only of objects
- registerDefaultRules() replaces registered rules with the same names, as
the README shows for max_number. "+" kept the registered rules.
- An empty list of rules ('field' => [] or list_of: []) is a list without
rules, not a rule without a name ("Rule [] not registered")
This was referenced Oct 23, 2026
koorchik
added a commit
that referenced
this pull request
Oct 23, 2026
The repository has no Packagist hook, so Packagist only picks up changes on its weekly crawl: four days after #31 was merged, dev-master on Packagist was still abbe57e. The workflow calls Packagist's update-package API after every push to master and every tag. It needs the PACKAGIST_USERNAME and PACKAGIST_TOKEN secrets of a maintainer of validator/livr on packagist.org, and only warns while they're not set.
This was referenced Oct 26, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/test_suiteto the current LIVR test suite. As before,negative/22-not_empty_listandnegative/27-any_objectstay adjusted, as PHP decodes{}and[]to the same array.Fixes
Found with the test suite:
orskipped empty values, sorequiredandnot_emptyin its rule sets never worked.ortook a list in its first argument as the list of rule sets, so{ or: [['email', 'to_lc'], 'positive_integer'] }, the example from the LIVR docs, threw a TypeError.list_of_different_objectsandvariable_objectthrew a TypeError on PHP 8 (a warning on PHP 7) when the selector value is an array.list_of_different_objectsdropped items that are not objects from the output instead of returning an error, and turned values that are not lists into empty lists.equal_to_fieldcompared values with==, so"10"was equal to"1e1"and"0123"to"123", for example in a password confirmation. It also warned when the other field is missing.Found with the tests of the JavaScript implementation:
registerDefaultRules()did not replace registered rules, though the README shows it formax_number.'field' => []orlist_of: []) threwRule [] not registered.Behavior changes
ortakes each argument as a set of rules, like the JavaScript and Perl implementations. Before, when the first argument was a list, PHP took it as the list of rule sets:{ or: [['email', 'to_lc'], 'positive_integer'] }threw a TypeError, and{ or: [['positive_integer', { max_number: 10 }]] }meant "positive_integer or max_number" instead of both.{ or: ['email', 'positive_integer'] }works as before.equal_to_fieldcompares values as strings, so numeric strings in different notations are not equal anymore.registerDefaultRules()replaces rules with the same names.Testing
tests/05-rules_edge_cases.phpandtests/03-auto_trim.php.{}and[]cases above.Emails are still checked with
filter_var(), so quoted local parts like"a@b"@example.comare accepted, unlike in the JavaScript implementation. The version is not bumped.