<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
danilopolani / laravel-json-validation-testing example snippets
use DaniloPolani\JsonValidation\JsonValidation;
JsonValidation::getRuleErrorMessage('foo', '
it('throws validation error', function () {
$this->postJson('/')
->assertJsonValidationErrorRule('foo', '
it('throws validation error', function () {
$this->postJson('/')
->assertJsonValidationErrorRule('foo', 'between.string:1,5') // The foo must be between 1 and 5 characters.
->assertJsonValidationErrorRule('foo', 'size.array:3'); // The foo must contain 3 items.
});
use DaniloPolani\JsonValidation\JsonValidation;
it('throws validation error', function () {
$this->postJson('/')
->assertJsonValidationErrorRule([
'foo' => '
namespace App\Rules;
use Closure;
use DaniloPolani\JsonValidation\Contracts\HasRuleMessage;
use Illuminate\Contracts\Validation\ValidationRule;
class Uppercase implements ValidationRule, HasRuleMessage
{
/**
* Run the validation rule.
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (strtoupper($value) !== $value) {
$fail($this->message());
}
}
public function message(): string
{
return 'The :attribute must be uppercase.';
}
}
it('throws validation error', function () {
$this->postJson('/')
->assertJsonValidationErrorRule('foo', new Uppercase());
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.