fix(models): correct UserSetting import namespace and add test coverage
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Data;
|
||||
|
||||
use App\Features\Games\Data\RomFileData;
|
||||
use App\Features\Games\Models\RomFile;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RomFileDataTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function it_can_be_created_from_array(): void
|
||||
{
|
||||
$data = RomFileData::from([
|
||||
'id' => 1,
|
||||
'game_id' => 1,
|
||||
'file_path' => 'roms/nes/game.nes',
|
||||
'file_name' => 'game.nes',
|
||||
'file_size' => 102400,
|
||||
'file_hash' => 'abc123',
|
||||
'region' => 'USA',
|
||||
'language' => 'en',
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $data->id);
|
||||
$this->assertEquals(1, $data->gameId);
|
||||
$this->assertEquals('roms/nes/game.nes', $data->filePath);
|
||||
$this->assertEquals('game.nes', $data->fileName);
|
||||
$this->assertEquals(102400, $data->fileSize);
|
||||
$this->assertEquals('abc123', $data->fileHash);
|
||||
$this->assertEquals('USA', $data->region);
|
||||
$this->assertEquals('en', $data->language);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_can_be_created_from_model(): void
|
||||
{
|
||||
$romFile = RomFile::factory()->create([
|
||||
'region' => 'Europe',
|
||||
'language' => 'de',
|
||||
]);
|
||||
|
||||
$data = RomFileData::fromModel($romFile);
|
||||
|
||||
$this->assertEquals($romFile->id, $data->id);
|
||||
$this->assertEquals($romFile->game_id, $data->gameId);
|
||||
$this->assertEquals($romFile->file_path, $data->filePath);
|
||||
$this->assertEquals($romFile->file_name, $data->fileName);
|
||||
$this->assertEquals($romFile->file_size, $data->fileSize);
|
||||
$this->assertEquals($romFile->file_hash, $data->fileHash);
|
||||
$this->assertEquals('Europe', $data->region);
|
||||
$this->assertEquals('de', $data->language);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_handles_null_optional_fields(): void
|
||||
{
|
||||
$romFile = RomFile::factory()->create([
|
||||
'region' => null,
|
||||
'language' => null,
|
||||
]);
|
||||
|
||||
$data = RomFileData::fromModel($romFile);
|
||||
|
||||
$this->assertNull($data->region);
|
||||
$this->assertNull($data->language);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user