Skip to content

Laravel 13 compatibility + PHP 8.2 modernization#57

Open
navneetkumar-pim-webkul wants to merge 17 commits into
andersao:masterfrom
navneetkumar-pim-webkul:laravel-13-compatibility
Open

Laravel 13 compatibility + PHP 8.2 modernization#57
navneetkumar-pim-webkul wants to merge 17 commits into
andersao:masterfrom
navneetkumar-pim-webkul:laravel-13-compatibility

Conversation

@navneetkumar-pim-webkul

Copy link
Copy Markdown

Summary

Adds Laravel 13 compatibility, modernizes source for PHP 8.2+, adds a real test suite (none existed before), and replaces the dead Travis config with a GitHub Actions matrix.

This is a broader-scope alternative to #55 (which is the minimal Shift bump). Maintainer can pick whichever fits the project direction.

Dependencies

  • PHP floor bumped to ^8.2
  • illuminate/support + illuminate/validation^11.0|^12.0|^13.0
  • Drops Laravel 5.4 – 10 (Laravel 10 conflicts with PHPUnit 11+ floor; L10 reached end-of-security in Feb 2026)
  • require-dev adds phpunit/phpunit ^11|^12 and orchestra/testbench ^9|^10|^11

Source modernization

  • declare(strict_types=1); in all source files
  • Typed parameters, return types, and properties throughout
  • Constructor property promotion in LaravelValidator and ValidatorException
  • readonly $messageBag in ValidatorException
  • parserValidationRules() refactored from by-reference array_walk to foreach

Latent bug fix

AbstractValidator::__construct() now initializes $errors = new MessageBag(). Previously, calling errors() before a failed passes() produced Error: Call to a member function all() on array. New regression test guards this.

Tests

11 Pest-style PHPUnit tests booting a real Laravel container via Orchestra Testbench. Covers passes, passesOrFail, action-scoped rules, setId unique-rule rewriter (including pipe-string and non-unique edge cases), custom messages/attributes, fresh-instance errors(), and the ValidatorException payload.

CI

.github/workflows/tests.yml replaces .travis.yml. Matrix:

L11 L12 L13
PHP 8.2 excluded (L13 requires 8.3+)
PHP 8.3
PHP 8.4

Breaking changes (documented in README)

  • ValidatorInterface and AbstractValidator signatures are now typed — subclasses must update.
  • ValidatorException::getMessageBag() now returns Illuminate\Contracts\Support\MessageBag (contract) instead of the concrete class.
  • Custom AbstractValidator subclasses overriding __construct() must call parent::__construct() so $errors is initialized.
  • Laravel 5.4–10 no longer supported. Stay on a prior release for those targets.

Test plan

  • vendor/bin/phpunit — 11 tests, 19 assertions, green on Laravel 13.11.2 / PHP 8.3.30 locally
  • Non-regression check against Laravel 11 + 12 — green
  • composer validate — valid
  • PHP -l syntax check — clean on all 6 PHP files
  • YAML lint on workflow — OK
  • CI matrix on GitHub Actions — verify all 9 cells green after merge

- Add declare(strict_types=1) to all source files
- Add typed parameters, return types, and property types
- Use constructor property promotion (LaravelValidator, ValidatorException)
- Make ValidatorException::$messageBag readonly
- Switch ValidatorException to Illuminate\Contracts\Support\MessageBag for wider type compatibility
- Initialize $errors as empty MessageBag in AbstractValidator constructor (fixes latent fatal when errors() called before passes())
- Remove redundant PHPDoc blocks superseded by type declarations
- Refactor parserValidationRules() with foreach instead of array_walk by-reference

Breaking: ValidatorInterface signatures now typed. Consumers implementing the
interface or extending AbstractValidator must update method signatures.
- Assert errors() returns [] on fresh instance (regression for latent bug)
- Assert errors() returns [] after successful validation
- Cover ValidatorException::getMessageBag(), toArray(), toJson()
ValidatorException previously did not call parent::__construct(), so
$e->getMessage() returned an empty string. Restore that behavior to
avoid silently changing what API consumers display via getMessage().
Covers pipe-separated rule strings and non-unique rules left untouched
by setId() / parserValidationRules().
Copilot AI review requested due to automatic review settings May 26, 2026 14:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 13 changed files in this pull request and generated 3 comments.

Comment thread src/Prettus/Validator/Exceptions/ValidatorException.php
Comment thread .github/workflows/tests.yml
Comment thread README.md Outdated
- Throw on json_encode failure in ValidatorException::toJson instead of
  silently returning an empty string, so invalid JSON surfaces as an
  error rather than a malformed payload.
- Fix stale README install snippet that referenced the wrong package
  name and outdated version constraint.
@navneetkumar-pim-webkul

Copy link
Copy Markdown
Author

Hi @andersao — friendly nudge on this PR.

Beyond the dependency bumps in e219ceb (laravel-shift #55), this PR delivers actual Laravel 13 hardening on the source:

  • Strict types + declared parameter/return types across ValidatorInterface, AbstractValidator, LaravelValidator, ValidatorException.
  • Removes deprecated PHP patterns (@list(...) with default, suppressed-error operators).
  • Ensures $errors MessageBag is always initialized via parent::__construct().
  • Tightens composer.json to php ^8.2 + ^11.0|^12.0|^13.0 (current >=5.4.0 lets Composer install on EOL PHP versions where the code won't run).
  • Adds orchestra/testbench + phpunit/phpunit dev deps and a real test suite (11 tests, including regression coverage for the unique-rule rewriter edge cases).
  • GitHub Actions matrix: PHP 8.2/8.3/8.4 × Laravel 11/12/13.
  • Documents the breaking changes in README so consumers can pin to the prior tag if they need L5.4–10 support.

Branch rebased clean against current master. Happy to split into smaller PRs if that's easier to review. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants