ValidationFailure tests

This commit is contained in:
icefox 2026-02-19 08:44:49 -03:00
parent 709201547c
commit f1d46dacb6
No known key found for this signature in database
7 changed files with 264 additions and 5 deletions

View file

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Tests\Classes;
use Icefox\DTO\DataObject;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\Validator;
readonly class FailsWithHttpResponse
{
use DataObject;
public function __construct(
public string $string,
public int $int,
) {}
public static function fails(Validator $validator): ?static
{
throw new HttpResponseException(
response()->json(['errors' => $validator->errors()], 422)
);
}
}