Files
animethemes-server/tests/Feature/Actions/Repositories/Admin/Dump/ReconcileDumpRepositoriesTest.php
T
paranarimasu 6015dcbbbf refactor: migration from laravel-enum package to native php enums (#585)
* refactor: migration from laravel-enum package to native php enums

* style: fix StyleCI findings
2023-06-09 14:29:10 -05:00

124 lines
4.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Actions\Repositories\Admin\Dump;
use App\Actions\Repositories\Admin\Dump\ReconcileDumpRepositoriesAction;
use App\Constants\Config\DumpConstants;
use App\Enums\Actions\ActionStatus;
use App\Models\Admin\Dump;
use App\Repositories\Eloquent\Admin\DumpRepository as DumpDestinationRepository;
use App\Repositories\Storage\Admin\DumpRepository as DumpSourceRepository;
use Exception;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use Mockery\MockInterface;
use Tests\TestCase;
/**
* Class ReconcileDumpRepositoriesTest.
*/
class ReconcileDumpRepositoriesTest extends TestCase
{
use WithFaker;
/**
* If no changes are needed, the Reconcile Dump Repository Action shall indicate no changes were made.
*
* @return void
*
* @throws Exception
*/
public function testNoResults(): void
{
Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
$this->mock(DumpSourceRepository::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once()->andReturn(Collection::make());
});
$action = new ReconcileDumpRepositoriesAction();
$source = App::make(DumpSourceRepository::class);
$destination = App::make(DumpDestinationRepository::class);
$result = $action->reconcileRepositories($source, $destination);
static::assertTrue(ActionStatus::PASSED === $result->getStatus());
static::assertFalse($result->hasChanges());
static::assertDatabaseCount(Dump::class, 0);
}
/**
* If dumps are created, the Reconcile Dump Repository Action shall return created dumps.
*
* @return void
*
* @throws Exception
*/
public function testCreated(): void
{
Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
$createdDumpCount = $this->faker->numberBetween(2, 9);
$dumps = Dump::factory()->count($createdDumpCount)->make();
$this->mock(DumpSourceRepository::class, function (MockInterface $mock) use ($dumps) {
$mock->shouldReceive('get')->once()->andReturn($dumps);
});
$action = new ReconcileDumpRepositoriesAction();
$source = App::make(DumpSourceRepository::class);
$destination = App::make(DumpDestinationRepository::class);
$result = $action->reconcileRepositories($source, $destination);
static::assertTrue(ActionStatus::PASSED === $result->getStatus());
static::assertTrue($result->hasChanges());
static::assertCount($createdDumpCount, $result->getCreated());
static::assertDatabaseCount(Dump::class, $createdDumpCount);
}
/**
* If dumps are deleted, the Reconcile Dump Repository Action shall return deleted dumps.
*
* @return void
*
* @throws Exception
*/
public function testDeleted(): void
{
Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
$deletedDumpCount = $this->faker->numberBetween(2, 9);
$dumps = Dump::factory()->count($deletedDumpCount)->create();
$this->mock(DumpSourceRepository::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once()->andReturn(Collection::make());
});
$action = new ReconcileDumpRepositoriesAction();
$source = App::make(DumpSourceRepository::class);
$destination = App::make(DumpDestinationRepository::class);
$result = $action->reconcileRepositories($source, $destination);
static::assertTrue(ActionStatus::PASSED === $result->getStatus());
static::assertTrue($result->hasChanges());
static::assertCount($deletedDumpCount, $result->getDeleted());
static::assertDatabaseCount(Dump::class, $deletedDumpCount);
foreach ($dumps as $dump) {
static::assertSoftDeleted($dump);
}
}
}