fix(models): correct UserSetting import namespace and add test coverage
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Repositories;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Games\Models\Game;
|
||||
use App\Features\Games\Models\RomFile;
|
||||
use App\Features\Games\Repositories\RomFileRepository;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RomFileRepositoryTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private RomFileRepository $repository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->repository = new RomFileRepository(new RomFile());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_counts_rom_files(): void
|
||||
{
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
RomFile::factory()->count(5)->create(['game_id' => $game->id]);
|
||||
|
||||
$this->assertEquals(5, $this->repository->count());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_finds_by_hash(): void
|
||||
{
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
$romFile = RomFile::factory()->create([
|
||||
'game_id' => $game->id,
|
||||
'file_hash' => 'abc123',
|
||||
]);
|
||||
|
||||
$found = $this->repository->findByHash('abc123');
|
||||
|
||||
$this->assertNotNull($found);
|
||||
$this->assertEquals($romFile->id, $found->id);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_returns_null_for_nonexistent_hash(): void
|
||||
{
|
||||
$found = $this->repository->findByHash('nonexistent');
|
||||
|
||||
$this->assertNull($found);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_creates_a_rom_file(): void
|
||||
{
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$romFile = $this->repository->create([
|
||||
'game_id' => $game->id,
|
||||
'file_path' => 'roms/nes/game.nes',
|
||||
'file_name' => 'game.nes',
|
||||
'file_size' => 102400,
|
||||
'file_hash' => 'abc123',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('rom_files', ['file_hash' => 'abc123']);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_gets_rom_files_by_game(): void
|
||||
{
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
RomFile::factory()->count(3)->create(['game_id' => $game->id]);
|
||||
|
||||
$otherGame = Game::factory()->create(['console_id' => $console->id]);
|
||||
RomFile::factory()->count(2)->create(['game_id' => $otherGame->id]);
|
||||
|
||||
$romFiles = $this->repository->getByGame($game->id);
|
||||
|
||||
$this->assertCount(3, $romFiles);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user