Files
animethemes-server/tests/Unit/Rules/Api/RandomSoleTest.php
T
paranarimasuandGitHub fd2cebe3cf chore: address deprecations to validation rules in Laravel 10 (#584)
* chore: address deprecations to validation rules in Laravel 10

* style: fix StyleCI findings
2023-06-05 01:01:49 -05:00

77 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Rules\Api;
use App\Http\Api\Criteria\Sort\RandomCriteria;
use App\Rules\Api\RandomSoleRule;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Validator;
use Tests\TestCase;
/**
* Class RandomSoleTest.
*/
class RandomSoleTest extends TestCase
{
use WithFaker;
/**
* The Random Sole Rule shall return false if the random key is provided and is not the sole sort.
*
* @return void
*/
public function testFailsIfRandomIsNotSoleSort(): void
{
$sorts = $this->faker->words($this->faker->randomDigitNotNull());
$sorts[] = RandomCriteria::PARAM_VALUE;
$attribute = $this->faker->word();
$validator = Validator::make(
[$attribute => implode(',', $sorts)],
[$attribute => new RandomSoleRule()]
);
static::assertFalse($validator->passes());
}
/**
* The Random Sole Rule shall return true if the random key is not provided.
*
* @return void
*/
public function testPassesIfRandomIsNotIncluded(): void
{
$sorts = $this->faker->words($this->faker->randomDigitNotNull());
$attribute = $this->faker->word();
$validator = Validator::make(
[$attribute => implode(',', $sorts)],
[$attribute => new RandomSoleRule()]
);
static::assertTrue($validator->passes());
}
/**
* The Random Sole Rule shall return true if the random key is the only sort provided.
*
* @return void
*/
public function testPassesIfRandomIsSoleSort(): void
{
$attribute = $this->faker->word();
$validator = Validator::make(
[$attribute => RandomCriteria::PARAM_VALUE],
[$attribute => new RandomSoleRule()]
);
static::assertTrue($validator->passes());
}
}