PHP code example of danilopolani / laravel-json-validation-testing

1. Go to this page and download the library: Download danilopolani/laravel-json-validation-testing library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?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());
});