Commit graph

1991 commits

Author SHA1 Message Date
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
Alexandre Gomes Gaigalas 8cafa3f298 Drop PHP 7.4 support 2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas ab3732f91f Use SPDX IDs for licensing
SPDX IDs are shorter than licensing notes previously used, and
adhere better to FOSS standards. It is also machine-readable.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas ef4778b456 Remove version info from Tld.php
We currently use a GitHub action to automate updating this file.

That action has the ability to ignore making the PR if the file
didn't changed.

Having the version number, which changed a line, was causing
several useless PR.

Users can still check if Tld.php changed by seeing the git log,
and a manual note should be issued by the maintainer on the
CHANGELOG.md file when a release containing such changes is
made.
2023-02-19 00:19:09 -03:00
Alexandre Gomes Gaigalas 689026fc7b Improve FilterVar with FILTER_VALIDATE_* options
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
2023-02-19 00:19:09 -03:00
Alexandre Gomes Gaigalas a3e016bec9 Fix docs links 2023-02-18 15:29:37 -03:00
dependabot[bot] c6eaf05f47
Update symfony/validator requirement from ^3.0||^4.0 to ^3.0||^4.0||^5.0 (#1400)
Updates the requirements on [symfony/validator](https://github.com/symfony/validator) to permit the latest version.
- [Release notes](https://github.com/symfony/validator/releases)
- [Changelog](https://github.com/symfony/validator/blob/6.2/CHANGELOG.md)
- [Commits](https://github.com/symfony/validator/commits/v5.4.19)

---
updated-dependencies:
- dependency-name: symfony/validator
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-15 04:06:02 +00:00
dependabot[bot] 7776652c85
Bump actions/checkout from 2 to 3 (#1399)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-15 04:05:27 +00:00
dependabot[bot] a96614b5a6
Bump codecov/codecov-action from 1 to 3 (#1398)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 1 to 3.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v1...v3)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-15 04:04:53 +00:00
Alexandre Gomes Gaigalas f080f7da08 Improve auto-updaters and pull requesters, auto-tld fix 2023-02-15 00:49:09 -03:00
Alexandre Gomes Gaigalas 8b3c607d03 Update peter-evans/create-pull-request@v4 2023-02-15 00:35:36 -03:00
Alexandre Gomes Gaigalas 74dee73f65 Update updater workflows, remove countries outside ISO-3366-2, cleanup 2023-02-15 00:29:10 -03:00
Alexandre Gomes Gaigalas 1e2f75287c Change update_subdivision_codes to work with salsa/iso-codes, updates data 2023-02-15 00:01:32 -03:00
Alexandre Gomes Gaigalas 1e96fd1473 Update docs (and shiny badges) 2023-02-14 22:39:19 -03:00
Alexandre Gomes Gaigalas d304ace532 Final CHANGELOG for release 2.2.4 2023-02-14 22:05:24 -03:00
Alexandre Gomes Gaigalas 1481c8e1e5 Updated docheaders 2023-02-13 19:24:37 -03:00
Alexandre Gomes Gaigalas 9ae39de44e Updates for IntVal changes 2023-02-13 19:21:42 -03:00
Alexandre Gomes Gaigalas 3eb085af8f Updated docs 2023-02-13 19:18:16 -03:00
Alexandre Gomes Gaigalas ecccfb853e Updated CHANGELOG.md 2023-02-13 19:09:30 -03:00
Alexandre Gomes Gaigalas 74d7f037a4 Merge branch 'omega3000/master' into 2.2 2023-02-13 19:07:48 -03:00
Alexandre Gomes Gaigalas 2c5793a000 Updated CHANGELOG.md, small phpcs fixes 2023-02-13 19:06:26 -03:00
Alexandre Gomes Gaigalas 13f20e7516 Merge branch 'rule/portuguese_nif_rule' into 2.2 2023-02-13 19:02:10 -03:00