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>
The idea of the "ParameterStringifier" is to convert any value to a
string. However, we use the "stringify" function directly when
converting the input into a string. That defies the purpose of the
ParameterStringifier, as it gives the "Formatter" two ways of converting
a value into a string.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This allows someone who wants to learn more about Validation to have a
more linear inflow of information.
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>
The documentation states that we should use Validator::keySet() in
combination with Validator::key() but the return type of key() does not
match the expected parameter type of keyset().
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
PHP 8.0 is no longer supported. Some of our dependencies now do not work
on PHP 8.0 anymore.
This commit will also run tests on PHP 8.3.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
I want to get the build green. Currently, PHPStan is complaining about a
couple of issues that are not so critical. It's especially concerning
that strict_types must be the very first statement on PHPT files, but
that's fine since PHPUnit parses its content.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
For now, I'm ignoring many rules because they'll make the changes that
would bring backward compatibility breaks, and I'm aiming to release a
minor version next.
However, upgrading "respect/coding-standard" is necessary because
version 4.0 no longer works.
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.
Previously, we were loading country info from a JSON file. This
changes it to use PHP files instead. It also caches these resources
across calls avoiding these files to be loaded more than once
per process.
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