Files

59 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Storage\Admin\Dump\DumpContentAction;
use App\Actions\Storage\Admin\Dump\PruneDumpAction;
use App\Constants\Config\DumpConstants;
use App\Enums\Actions\ActionStatus;
use App\Models\Admin\Dump;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
pest()->use(WithFaker::class);
test('no results', function (): void {
$fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
$action = new PruneDumpAction(fake()->numberBetween(2, 9));
$pruneResults = $action->handle();
$result = $pruneResults->toActionResult();
expect($fs->allFiles())->toBeEmpty();
expect($result->hasFailed())->toBeTrue();
$this->assertDatabaseCount(Dump::class, 0);
});
test('pruned', function (): void {
$fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
$prunedCount = fake()->randomDigitNotNull();
Collection::times($prunedCount, function (): void {
Date::setTestNow(fake()->iso8601());
$action = new DumpContentAction();
$action->handle();
});
Date::setTestNow();
$action = new PruneDumpAction(-1);
$pruneResults = $action->handle();
$action->then($pruneResults);
$result = $pruneResults->toActionResult();
expect($fs->allFiles())->toBeEmpty();
expect($result->getStatus())->toBe(ActionStatus::PASSED);
expect(Dump::all())->toBeEmpty();
});