65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Repositories;
|
|
|
|
use App\Features\Consoles\Models\Console;
|
|
use App\Features\Consoles\Repositories\ConsoleRepository;
|
|
use App\Features\Games\Models\Game;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Tests\TestCase;
|
|
|
|
class ConsoleRepositoryTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private ConsoleRepository $repository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->repository = new ConsoleRepository(new Console());
|
|
}
|
|
|
|
#[Test]
|
|
public function it_gets_all_consoles_with_games_count(): void
|
|
{
|
|
Console::factory()->count(3)->create();
|
|
|
|
$consoles = $this->repository->getAll();
|
|
|
|
$this->assertCount(3, $consoles);
|
|
}
|
|
|
|
#[Test]
|
|
public function it_gets_console_by_slug(): void
|
|
{
|
|
$console = Console::factory()->create(['slug' => 'nes']);
|
|
|
|
$found = $this->repository->getBySlug('nes');
|
|
|
|
$this->assertNotNull($found);
|
|
$this->assertEquals($console->id, $found->id);
|
|
}
|
|
|
|
#[Test]
|
|
public function it_returns_null_for_nonexistent_slug(): void
|
|
{
|
|
$found = $this->repository->getBySlug('nonexistent');
|
|
|
|
$this->assertNull($found);
|
|
}
|
|
|
|
#[Test]
|
|
public function it_gets_consoles_with_games_count(): void
|
|
{
|
|
$console = Console::factory()->create();
|
|
Game::factory()->count(5)->create(['console_id' => $console->id]);
|
|
|
|
$consoles = $this->repository->getWithGamesCount();
|
|
|
|
$this->assertCount(1, $consoles);
|
|
$this->assertEquals(5, $consoles->first()->games_count);
|
|
}
|
|
}
|