I'm unsure whether this is a bug in "libphonenumber-for-php" or if we're
misusing the library. This commit will ensure that only phone numbers
from a specific region will be considered valid. I've reported the issue
to "libphonenumber-for-php" anyways [1].
[1]: https://github.com/giggsey/libphonenumber-for-php/issues/621
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
In version 2.3, the Phone rule started to require
"giggly/libphonenumber-for-php" as a dependency. That was a backward
compatibility break, but the validation also became stricter, and phone
numbers without country codes would not be considered valid.
This commit will revert the backward compatibility break. That way, when
validating a phone number without a country code (the behaviour from
version 2.2), the Phone will not use an external library.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
We decided to make the date format validation stricter[1]. Although
that's good, it could present some challenges for some people,
considering that the DateTime rule would be more flexible.
There are many cases in which PHP can parse a date but can't output it
the same way.
[1]: 5fe4b96ebf
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Country codes in ISO 3166-1 should be in uppercase, and the
`AbstractSearcher` should not change the input to search for a value.
While working on this fix, I also discovered that the
"PublicDomainSuffix" rule would throw an exception if it got a
non-scalar value as an input.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
I did some digging but couldn't figure out what was happening. It
probably is something related to today's date because PHP itself is not
parsing dates correctly.
```php
echo DateTime::createFromFormat('Ym', '202302')->format('Ym');
// Outputs 202303
```
For now, I'm just making the tests pass, but I created an issue with
getting back to it later.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
It's essential to test our abstract classes because users might use
them. However, creating mocks when writing those tests make the code too
complicated.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
From PHPUnit 10, all data providers need to be static. This commit will
make migrating from version 9 to 10 a bit easier.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
We can use the AlwaysValid and AlwaysInvalid rules in the tests instead
of mocking them. Those changes will help us later because we mainly use
the `createValidatableMock()` in the data providers and, as from
PHPUnit 10, all data providers need to be static.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
With that, the tests will be more straightforward, and we won't need to
use the test class in the data providers. That will help us later
because, on PHPUnit 10, all data providers need to be static.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
With that, the tests will be more straightforward, and we won't need to
use the test class in the data providers. That will help us later
because, on PHPUnit 10, all data providers need to be static.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
When we write tests requiring those interfaces, we create mocks. Those
new stubs will make those tests easier to read and allow us to reduce
the number of mocks we write with PHPUnit, making the code in the tests
a bit less complex.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
We had a method that returned the full path of the fixture directory,
and we frequently would concatenate that path with a file we needed. I
changed it to include the file's path inside the fixture directory. That
way, we avoid repeating the same patter over and over.
I made the method static because we use it in data providers, which need
to be static.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The integration tests use the same pattern to test exception messages.
With my changes, we won't validate which exception we throw in those
tests, but matching the message is enough. I created three functions to
replace most of those tests.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Most exception messages in Validation use "must" and "must not" in their
templates, but a few rules don't.
I fixed most of them, but AlwaysValid and AlwaysInvalid remain because I
wonder if they will be better if I update them.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
- For this particular updater, a list of exceptions to the rules
downloaded by geonames is included in POSTAL_CODES_EXTRA, for
cases in which we seem to do better than geonames itself based
on previous user reports.
- Added an option to also validate formatting of the postal codes.
- Combined multiple PR bots into a single one.
Doing regex on phone numbers is not a great idea. This is a breaking
change, but a good one. Phone validation is now much stricter, and
allows choosing the country.
The use case for negating a keyset is very confusing, and can
lead to validators that don't do what they expect.
This commit introduces NonNegatable rules, which will throw
a Component exception if you try to wrap them in `Not`.
This change was necessary to ensure proper message reporting
when extra keys exist on the keyset.
This fixes#1349
The `filter_var` function is more of a sanitizer, but we as
a validation library do not care for that use case.
We should treat its sanitizings as a signal for checking if
the type after sanitization matches the option provided.
This fixes#1387
Since "sokil/php-isocodes" is a dependency of our repository already, it
makes sense to use it as a source of currency codes instead of keeping a
list of currencies ourselves.
By using that library, we can also validate currency codes using
different sets.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Inside the "data/" directory, we have files with lists of subdivisions
that need to be updated. We have to update them manually, or we automate
that task with a script and GitHub actions.
The two options are very time consuming and also not ideal. We don't
want to deal with that problem and, thinking that the user of this
library may want to show the data that we validate, we should create a
whole library to make it more usable.
The "sokil/php-isocodes" is a simple library that, even supports
translations. It's frequently updated and has gone to major performance
updates.
I am not fond of the idea of requiring an external library to install
Validation, as I have seen that gone wrong before [1]. Ideally, that
would be an optional dependency for people who would like to use those
rules, but to make that happen, we need to release a MAJOR version.
[1]: d072b4de6a
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>