{"id":16749897,"url":"https://github.com/danilopolani/laravel-json-validation-testing","last_synced_at":"2026-04-17T17:01:35.771Z","repository":{"id":41882467,"uuid":"465252472","full_name":"danilopolani/laravel-json-validation-testing","owner":"danilopolani","description":"Better JSON validation errors testing ","archived":false,"fork":false,"pushed_at":"2025-12-09T16:00:49.000Z","size":48,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-26T16:22:28.241Z","etag":null,"topics":["laravel","laravel-package","testing-tools","validation-error"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danilopolani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://www.buymeacoffee.com/theraloss"]}},"created_at":"2022-03-02T10:10:26.000Z","updated_at":"2025-12-09T15:29:18.000Z","dependencies_parsed_at":"2024-04-29T04:37:50.705Z","dependency_job_id":"a601dbc7-8cc8-49e2-b99c-db767d50e704","html_url":"https://github.com/danilopolani/laravel-json-validation-testing","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.46153846153846156","last_synced_commit":"8f0b3539acc7424c26570c39ec318b5e12394f34"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/danilopolani/laravel-json-validation-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Flaravel-json-validation-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Flaravel-json-validation-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Flaravel-json-validation-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Flaravel-json-validation-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danilopolani","download_url":"https://codeload.github.com/danilopolani/laravel-json-validation-testing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Flaravel-json-validation-testing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31937732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T12:37:54.787Z","status":"ssl_error","status_checked_at":"2026-04-17T12:37:25.095Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-package","testing-tools","validation-error"],"created_at":"2024-10-13T02:26:25.726Z","updated_at":"2026-04-17T17:01:35.751Z","avatar_url":"https://github.com/danilopolani.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/theraloss"],"categories":[],"sub_categories":[],"readme":"# JSON Validation errors testing helper\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/danilopolani/laravel-json-validation-testing.svg?style=flat-square)](https://packagist.org/packages/danilopolani/laravel-json-validation-testing)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/danilopolani/laravel-json-validation-testing/run-tests?label=tests)](https://github.com/danilopolani/laravel-json-validation-testing/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/danilopolani/laravel-json-validation-testing/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/danilopolani/laravel-json-validation-testing/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/danilopolani/laravel-json-validation-testing.svg?style=flat-square)](https://packagist.org/packages/danilopolani/laravel-json-validation-testing)\n\nA simple library to help testing JSON validation errors by rules.  \n\nThe current way to test HTTP errors is **broken**: it tests that the validation fails or you have to manually specify the error message. With this package you'll just need to specify the validation rule that fails and it builds the error message to be sure at 100% that it fails and **what fails**. (Further reading [here](https://github.com/laravel/framework/pull/41239) in the old merge request for Laravel).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require --dev danilopolani/laravel-json-validation-testing\n```\n\n## Usage\n\nThe package provides an helper to retrieve a compiled error message:\n\n```php\nuse DaniloPolani\\JsonValidation\\JsonValidation;\n\nJsonValidation::getRuleErrorMessage('foo', 'required');\n\n// =\u003e [\"The foo field is required.\"]\n```\n\nHowever, if you need to test that your HTTP APIs, the package ships with a brand new `assertJsonValidationErrorRule` assertion to make your life easier:\n\n```php\nit('throws validation error', function () {\n    $this-\u003epostJson('/')\n        -\u003eassertJsonValidationErrorRule('foo', 'required');\n});\n```\n\nIt supports as well dynamic rules, such as `between`, `size`, `max` etc. You just need to specify the type of rule you want to apply:\n\n```php\nit('throws validation error', function () {\n    $this-\u003epostJson('/')\n        -\u003eassertJsonValidationErrorRule('foo', 'between.string:1,5') // The foo must be between 1 and 5 characters.\n        -\u003eassertJsonValidationErrorRule('foo', 'size.array:3'); // The foo must contain 3 items.\n});\n```\n\nYou can even test multiple validation errors at once by providing an array of `field =\u003e rule` as argument:\n\n```php\nuse DaniloPolani\\JsonValidation\\JsonValidation;\n\nit('throws validation error', function () {\n    $this-\u003epostJson('/')\n        -\u003eassertJsonValidationErrorRule([\n            'foo' =\u003e 'required',\n            'bar' =\u003e 'required_array_keys:foo,baz',\n        ]);\n});\n```\n\n### Custom rules\nIf you want to test a custom rule, make sure it implements the interface `DaniloPolani\\JsonValidation\\Contracts\\HasRuleMessage`, needed to extract the failing message to check against.\n\nFor example, a custom Rule would look like this:\n```php\n\u003c?php\n \nnamespace App\\Rules;\n \nuse Closure;\nuse DaniloPolani\\JsonValidation\\Contracts\\HasRuleMessage;\nuse Illuminate\\Contracts\\Validation\\ValidationRule;\n \nclass Uppercase implements ValidationRule, HasRuleMessage\n{\n    /**\n     * Run the validation rule.\n     */\n    public function validate(string $attribute, mixed $value, Closure $fail): void\n    {\n        if (strtoupper($value) !== $value) {\n            $fail($this-\u003emessage());\n        }\n    }\n\n    public function message(): string\n    {\n        return 'The :attribute must be uppercase.';\n    }\n}\n```\n\nAnd then you can use it in your assert function:\n\n\nOf course you can provide your own custom validation Rules:\n\n```php\nit('throws validation error', function () {\n    $this-\u003epostJson('/')\n        -\u003eassertJsonValidationErrorRule('foo', new Uppercase());\n});\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Danilo Polani](https://github.com/danilopolani)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilopolani%2Flaravel-json-validation-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanilopolani%2Flaravel-json-validation-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilopolani%2Flaravel-json-validation-testing/lists"}