Commit graph

2012 commits

Author SHA1 Message Date
The Respect Panda 967f7b6cc7 Update Regional Information 2024-04-13 11:45:55 +02:00
Henrique Moody 263ae118fb
Do not validate phone numbers from other regions
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>
2024-03-24 19:49:24 +01:00
The Respect Panda ccec34cf21 Update Regional Information 2024-03-15 11:45:30 +01:00
Henrique Moody 955405b997
Fix type in HexRgbColor documentation
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-11 23:14:36 +01:00
Henrique Moody 788939e359
Remove backwards compatibility break from Phone rule
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>
2024-03-11 22:14:03 +01:00
Henrique Moody fb322df1da
Use "ParameterStringifier" to stringify input
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>
2024-03-11 20:01:47 +01:00
Henrique Moody 543b97309a
Fix broken documentation links
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-19 14:20:39 +01:00
Henrique Moody d8cd6a30e0
Change documentation order
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>
2024-02-04 16:11:57 +01:00
Henrique Moody 5ba9b31cc8
Make the behavior of DateTime more explicit
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>
2024-02-04 15:57:53 +01:00
Henrique Moody 5b7ea866e4
Do not allow lowercase country codes
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>
2024-02-02 16:55:37 +01:00
Henrique Moody debf6c556e
Make DateTime tests pass
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>
2024-01-29 22:28:49 +01:00
Henrique Moody 176d76c709
Create Read the Docs configuration file
The documentation is outdated because the file doesn't exist.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-28 21:50:01 +01:00
César de la Cal 4c91e3397a
Fix wrong type in "KeySet" rule
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>
2024-01-28 14:55:45 +01:00
Alan Taylor 8d7d783698
Check if property is initialized before getting its value
This commit also removed the use of "setAccessible", since it's not
neccessary after PHP 8.1.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-27 20:36:01 +01:00
Henrique Moody 6e3ed94076
Get CHANGELOG ready for release
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-27 20:14:16 +01:00
Henrique Moody cf3da2aa9c
Update changelog
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-27 20:09:57 +01:00
Henrique Moody 24edfda1aa
Drop support for PHP 8.0 and below
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>
2024-01-27 20:04:17 +01:00
Henrique Moody bd953f99f0
Ignore PHPStan errors
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>
2024-01-27 20:04:16 +01:00
Henrique Moody 177657d5f4
Upgrade Coding Standards
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>
2024-01-27 19:41:12 +01:00
The Respect Panda 703f610ee8 Update Regional Information 2023-06-13 21:46:15 -03:00
Henrique Moody 2a743962e4
Use a concrete class to test AbstractEnvelop
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>
2023-04-03 17:20:39 +02:00
Henrique Moody 2ee7509c2e
Make data providers static
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>
2023-04-03 17:20:31 +02:00
Henrique Moody ebcf247187
Do not use mocks to simulate a rule
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>
2023-04-03 16:28:38 +02:00
Henrique Moody 049b0b27ae
Do not use the test class to test the Callback rule
That will help us later because, on PHPUnit 10, all data providers need
to be static.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2023-04-03 16:28:38 +02:00
Henrique Moody 445af454fd
Create a class to help test the Callable rule
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>
2023-04-03 16:28:38 +02:00
Henrique Moody ee8dd98f54
Create class to help testing the Attribute rule
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>
2023-04-03 16:28:38 +02:00
Henrique Moody 07c4095f11
Create stubs for PSR-7 interfaces
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>
2023-04-03 16:28:37 +02:00
Henrique Moody e8fcdb661f
Allow creating paths from fixture files
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>
2023-04-03 16:28:37 +02:00
Henrique Moody 8a7bc1ab7a
Improve readability of integration tests
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>
2023-04-01 07:40:42 +02:00
Henrique Moody 003830b8e9
Standardize exception messages
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>
2023-04-01 05:54:52 +02:00
Henrique Moody 830ad97126
Fix the typo on the "Exists" rule's exception
When I created that rule, I barely spoke English.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2023-03-22 20:39:02 +01:00
github-actions[bot] dd053f2eea
Update Regional Information (#1414)
Co-authored-by: The Respect Panda <therespectpanda@gmail.com>
2023-03-19 05:35:32 +00:00
Danilo Correa afa4cc41ea
Increase test coverage for some rules (#1412)
- Add test for null value in the Cnpj rule.
- Add UploadedFileInterface object test for Size rule.
- Add test for invalid values in Sorted rule.
2023-03-11 20:43:10 +00:00
Henrique Moody 508566eafc
Update list of rules in the chained validator (#1411)
The "bic" rule has been removed, and two more rules were added.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2023-03-10 14:42:27 +00:00
github-actions[bot] 2080e0d2fb
Update Regional Information (#1410)
Co-authored-by: The Respect Panda <therespectpanda@gmail.com>
2023-03-09 00:51:45 +00:00
Alexandre Gomes Gaigalas 8f545c142c Ensure empty strings are never a valid currency code 2023-02-19 22:21:13 -03:00
Alexandre Gomes Gaigalas 636906fa07 Fixed previously introduced bug, add integration test 2023-02-19 22:11:35 -03:00
Alexandre Gomes Gaigalas bae314dd00 Do not hide messages on EachException 2023-02-19 15:26:07 -03:00
Alexandre Gomes Gaigalas 5fe4b96ebf Stricter date format validation 2023-02-19 15:00:47 -03:00
Alexandre Gomes Gaigalas 7c28d2c1f4 Update sorting order on public suffix data 2023-02-19 00:44:41 -03:00
Alexandre Gomes Gaigalas 154cccf408 Add idn2 to gh workflow installs 2023-02-19 00:21:13 -03:00
Alexandre Gomes Gaigalas ce9608d0a8 Auto update postal code list
- 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.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas e2b6138bf6 Add PublicDomainSuffix Rule
- List will be auto-updated from https://publicsuffix.org/list/public_suffix_list.dat
 - Updated AbstractSearcher rules to be case insensitive
 - Updated PR creator bots
 - Docs and tests
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas 7e7c3f2fcc Tests and docs for IP range validation 2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas 55290af1fd Add test cases for issue #665 to PhoneTest 2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas 6173757f63 Use PHP files and setup a runtime cache for CountryInfo
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.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas cc3bf86b2f Use libphonenumber
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.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas fc8230acef Make KeySet impossible to wrap in not(), fix structure message
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
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas 493a665e99 Add a test/example of how to explore the exception tree 2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas 727e7ccbfa Increase phpstan level from 7 to 8
- Fixed all phpstan errors and ignoreds.
 - False positives now have a "Why:" comment on phpstan config.
2023-02-19 00:19:10 -03:00