71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Post\UseCases;
|
|
|
|
use App\Post\CreatePostDto;
|
|
use App\Post\Post;
|
|
use App\Post\UseCases\ListFeaturedPosts\ListFeaturedPosts;
|
|
use DateTimeImmutable;
|
|
use DateTimeZone;
|
|
use Tests\Fakes\FakePostRepository;
|
|
use Tests\TestCase;
|
|
|
|
class ListFeaturedPostsTest extends TestCase
|
|
{
|
|
private FakePostRepository $postRepo;
|
|
|
|
private ListFeaturedPosts $useCase;
|
|
|
|
private DateTimeImmutable $now;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->now = new DateTimeImmutable(
|
|
'2026-05-06T12:00:00',
|
|
new DateTimeZone('UTC'),
|
|
);
|
|
$this->postRepo = new FakePostRepository;
|
|
$this->useCase = new ListFeaturedPosts($this->postRepo);
|
|
}
|
|
|
|
private function seedFeaturedPost(string $title, ?int $slot): Post
|
|
{
|
|
$post = $this->postRepo->create(new CreatePostDto(
|
|
userId: 1,
|
|
title: $title,
|
|
body: 'B',
|
|
createdAt: $this->now,
|
|
));
|
|
if ($slot === null) {
|
|
return $post;
|
|
}
|
|
|
|
return $this->postRepo->update(new Post(
|
|
id: $post->getId(),
|
|
userId: $post->getUserId(),
|
|
title: $post->getTitle(),
|
|
body: $post->getBody(),
|
|
createdAt: $post->getCreatedAt(),
|
|
featureSlot: $slot,
|
|
));
|
|
}
|
|
|
|
public function test_returns_empty_when_none_featured(): void
|
|
{
|
|
$this->seedFeaturedPost('not featured', null);
|
|
$this->assertSame([], $this->useCase->execute());
|
|
}
|
|
|
|
public function test_returns_featured_posts_in_slot_order(): void
|
|
{
|
|
$this->seedFeaturedPost('slot-2', 2);
|
|
$this->seedFeaturedPost('slot-1', 1);
|
|
$this->seedFeaturedPost('not-featured', null);
|
|
|
|
$featured = $this->useCase->execute();
|
|
|
|
$this->assertCount(2, $featured);
|
|
$this->assertSame('slot-1', $featured[0]->getTitle());
|
|
$this->assertSame('slot-2', $featured[1]->getTitle());
|
|
}
|
|
}
|