Files
animethemes-server/tests/Feature/Console/Commands/Storage/Admin/DumpPruneTest.php
T
paranarimasu 1d93000c6f feat(admin): migrate db dumps from github to platform (#463)
* feat(admin): migrate db dumps from github to platform

* style: fix StyleCI findings
2022-09-18 22:31:29 -05:00

68 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Storage\Admin;
use App\Actions\Storage\Admin\Dump\DumpWikiAction;
use App\Console\Commands\Storage\Admin\DumpPruneCommand;
use App\Constants\Config\DumpConstants;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
/**
* Class DumpPruneTest.
*/
class DumpPruneTest extends TestCase
{
use WithFaker;
/**
* If no changes are needed, the Prune Database Dumps Command shall output 'No database dumps deleted'.
*
* @return void
*/
public function testNoResults(): void
{
$this->baseRefreshDatabase(); // Cannot lazily refresh database within pending command
Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
$this->artisan(DumpPruneCommand::class, ['--hours' => 0])
->assertFailed()
->expectsOutput('No prunings were attempted.');
}
/**
* If dumps are deleted, the Prune Database Dumps Command shall output '{Deleted Count} database dumps deleted'.
*
* @return void
*/
public function testDeleted(): void
{
$this->baseRefreshDatabase(); // Cannot lazily refresh database within pending command
Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
$prunedCount = $this->faker->randomDigitNotNull();
Collection::times($prunedCount, function () {
Date::setTestNow($this->faker->iso8601());
$action = new DumpWikiAction();
$action->handle();
});
Date::setTestNow();
$this->artisan(DumpPruneCommand::class, ['--hours' => -1])
->assertSuccessful()
->expectsOutputToContain('Pruned');
}
}