mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-27 01:04:40 +02:00
* chore: address deprecations to validation rules in Laravel 10 * style: fix StyleCI findings
62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Rules\Storage;
|
|
|
|
use App\Rules\Storage\StorageDirectoryExistsRule;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class StorageDirectoryExistsTest.
|
|
*/
|
|
class StorageDirectoryExistsTest extends TestCase
|
|
{
|
|
use WithFaker;
|
|
|
|
/**
|
|
* The Storage Directory Exists Rule shall return true if the directory exists in the filesystem.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testPassesIfDirectoryExists(): void
|
|
{
|
|
$directory = $this->faker->word();
|
|
|
|
$fs = Storage::fake($this->faker->word());
|
|
|
|
$fs->makeDirectory($directory);
|
|
|
|
$attribute = $this->faker->word();
|
|
|
|
$validator = Validator::make(
|
|
[$attribute => $directory],
|
|
[$attribute => new StorageDirectoryExistsRule($fs)]
|
|
);
|
|
|
|
static::assertTrue($validator->passes());
|
|
}
|
|
|
|
/**
|
|
* The Storage Directory Exists Rule shall return false if the directory does not exist in the filesystem.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testFailsIfDirectoryDoesNotExist(): void
|
|
{
|
|
$fs = Storage::fake($this->faker->word());
|
|
|
|
$attribute = $this->faker->word();
|
|
|
|
$validator = Validator::make(
|
|
[$attribute => $this->faker->word()],
|
|
[$attribute => new StorageDirectoryExistsRule($fs)]
|
|
);
|
|
|
|
static::assertFalse($validator->passes());
|
|
}
|
|
}
|