Working state
This commit is contained in:
@@ -37,10 +37,16 @@ final class PostConcurrentUpdateIntegrationTest extends TestCase
|
||||
$realRepo = new PostRepository($this->db);
|
||||
$repo = new class($realRepo) implements PostRepositoryInterface {
|
||||
private bool $deleted = false;
|
||||
|
||||
public function __construct(private readonly PostRepository $inner) {}
|
||||
|
||||
public function findAll(?int $categoryId = null): array { return $this->inner->findAll($categoryId); }
|
||||
public function findPage(int $limit, int $offset, ?int $categoryId = null): array { return $this->inner->findPage($limit, $offset, $categoryId); }
|
||||
public function countAll(?int $categoryId = null): int { return $this->inner->countAll($categoryId); }
|
||||
public function findRecent(int $limit): array { return $this->inner->findRecent($limit); }
|
||||
public function findByUserId(int $userId, ?int $categoryId = null): array { return $this->inner->findByUserId($userId, $categoryId); }
|
||||
public function findByUserPage(int $userId, int $limit, int $offset, ?int $categoryId = null): array { return $this->inner->findByUserPage($userId, $limit, $offset, $categoryId); }
|
||||
public function countByUserId(int $userId, ?int $categoryId = null): int { return $this->inner->countByUserId($userId, $categoryId); }
|
||||
public function findBySlug(string $slug): ?Post { return $this->inner->findBySlug($slug); }
|
||||
public function findById(int $id): ?Post { return $this->inner->findById($id); }
|
||||
public function create(Post $post, string $slug, int $authorId, ?int $categoryId): int { return $this->inner->create($post, $slug, $authorId, $categoryId); }
|
||||
@@ -53,7 +59,11 @@ final class PostConcurrentUpdateIntegrationTest extends TestCase
|
||||
}
|
||||
public function delete(int $id): int { return $this->inner->delete($id); }
|
||||
public function search(string $query, ?int $categoryId = null, ?int $authorId = null): array { return $this->inner->search($query, $categoryId, $authorId); }
|
||||
public function searchPage(string $query, int $limit, int $offset, ?int $categoryId = null, ?int $authorId = null): array { return $this->inner->searchPage($query, $limit, $offset, $categoryId, $authorId); }
|
||||
public function countSearch(string $query, ?int $categoryId = null, ?int $authorId = null): int { return $this->inner->countSearch($query, $categoryId, $authorId); }
|
||||
public function slugExists(string $slug, ?int $excludeId = null): bool { return $this->inner->slugExists($slug, $excludeId); }
|
||||
public function countByEmbeddedMediaUrl(string $url): int { return $this->inner->countByEmbeddedMediaUrl($url); }
|
||||
public function findByEmbeddedMediaUrl(string $url, int $limit = 5): array { return $this->inner->findByEmbeddedMediaUrl($url, $limit); }
|
||||
};
|
||||
|
||||
$sanitizer = new class implements HtmlSanitizerInterface {
|
||||
|
||||
@@ -11,9 +11,10 @@ use App\Post\PostServiceInterface;
|
||||
use App\Shared\Exception\NotFoundException;
|
||||
use App\Shared\Http\FlashServiceInterface;
|
||||
use App\Shared\Http\SessionManagerInterface;
|
||||
use App\Shared\Pagination\PaginatedResult;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Slim\Exception\HttpNotFoundException;
|
||||
use Tests\ControllerTestCase;
|
||||
use Tests\ControllerTestBase;
|
||||
|
||||
/**
|
||||
* Tests unitaires pour PostController.
|
||||
@@ -28,7 +29,7 @@ use Tests\ControllerTestCase;
|
||||
* - delete() : 404, droits insuffisants, succès
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class PostControllerTest extends ControllerTestCase
|
||||
final class PostControllerTest extends ControllerTestBase
|
||||
{
|
||||
/** @var \Slim\Views\Twig&MockObject */
|
||||
private \Slim\Views\Twig $view;
|
||||
@@ -73,8 +74,8 @@ final class PostControllerTest extends ControllerTestCase
|
||||
*/
|
||||
public function testIndexCallsGetAllPostsWithNoFilter(): void
|
||||
{
|
||||
$this->postService->expects($this->once())->method('getAllPosts')->with(null)->willReturn([]);
|
||||
$this->postService->expects($this->never())->method('searchPosts');
|
||||
$this->postService->expects($this->once())->method('getAllPostsPaginated')->with(1, 6, null)->willReturn(new PaginatedResult([], 0, 1, 6));
|
||||
$this->postService->expects($this->never())->method('searchPostsPaginated');
|
||||
|
||||
$res = $this->controller->index($this->makeGet('/'), $this->makeResponse());
|
||||
|
||||
@@ -87,10 +88,10 @@ final class PostControllerTest extends ControllerTestCase
|
||||
public function testIndexCallsSearchPostsWhenQueryParamPresent(): void
|
||||
{
|
||||
$this->postService->expects($this->once())
|
||||
->method('searchPosts')
|
||||
->with('php', null)
|
||||
->willReturn([]);
|
||||
$this->postService->expects($this->never())->method('getAllPosts');
|
||||
->method('searchPostsPaginated')
|
||||
->with('php', 1, 6, null)
|
||||
->willReturn(new PaginatedResult([], 0, 1, 6));
|
||||
$this->postService->expects($this->never())->method('getAllPostsPaginated');
|
||||
|
||||
$this->controller->index($this->makeGet('/', ['q' => 'php']), $this->makeResponse());
|
||||
}
|
||||
@@ -104,9 +105,9 @@ final class PostControllerTest extends ControllerTestCase
|
||||
$this->categoryService->expects($this->once())->method('findBySlug')->with('php')->willReturn($category);
|
||||
|
||||
$this->postService->expects($this->once())
|
||||
->method('getAllPosts')
|
||||
->with(3)
|
||||
->willReturn([]);
|
||||
->method('getAllPostsPaginated')
|
||||
->with(1, 6, 3)
|
||||
->willReturn(new PaginatedResult([], 0, 1, 6));
|
||||
|
||||
$this->controller->index(
|
||||
$this->makeGet('/', ['categorie' => 'php']),
|
||||
@@ -165,8 +166,8 @@ final class PostControllerTest extends ControllerTestCase
|
||||
$this->sessionManager->method('isAdmin')->willReturn(true);
|
||||
$this->sessionManager->method('isEditor')->willReturn(false);
|
||||
|
||||
$this->postService->expects($this->once())->method('getAllPosts')->willReturn([]);
|
||||
$this->postService->expects($this->never())->method('getPostsByUserId');
|
||||
$this->postService->expects($this->once())->method('getAllPostsPaginated')->with(1, 12, null)->willReturn(new PaginatedResult([], 0, 1, 12));
|
||||
$this->postService->expects($this->never())->method('getPostsByUserIdPaginated');
|
||||
|
||||
$res = $this->controller->admin($this->makeGet('/admin/posts'), $this->makeResponse());
|
||||
|
||||
@@ -182,8 +183,8 @@ final class PostControllerTest extends ControllerTestCase
|
||||
$this->sessionManager->method('isEditor')->willReturn(false);
|
||||
$this->sessionManager->method('getUserId')->willReturn(5);
|
||||
|
||||
$this->postService->expects($this->once())->method('getPostsByUserId')->with(5, null)->willReturn([]);
|
||||
$this->postService->expects($this->never())->method('getAllPosts');
|
||||
$this->postService->expects($this->once())->method('getPostsByUserIdPaginated')->with(5, 1, 12, null)->willReturn(new PaginatedResult([], 0, 1, 12));
|
||||
$this->postService->expects($this->never())->method('getAllPostsPaginated');
|
||||
|
||||
$this->controller->admin($this->makeGet('/admin/posts'), $this->makeResponse());
|
||||
}
|
||||
@@ -197,9 +198,9 @@ final class PostControllerTest extends ControllerTestCase
|
||||
$this->sessionManager->method('isEditor')->willReturn(false);
|
||||
|
||||
$this->postService->expects($this->once())
|
||||
->method('searchPosts')
|
||||
->with('php', null, null)
|
||||
->willReturn([]);
|
||||
->method('searchPostsPaginated')
|
||||
->with('php', 1, 12, null, null)
|
||||
->willReturn(new PaginatedResult([], 0, 1, 12));
|
||||
|
||||
$this->controller->admin(
|
||||
$this->makeGet('/admin/posts', ['q' => 'php']),
|
||||
@@ -492,7 +493,7 @@ final class PostControllerTest extends ControllerTestCase
|
||||
* Crée une entité Post de test avec les paramètres minimaux.
|
||||
*
|
||||
* Nommé buildPostEntity (et non makePost) pour ne pas masquer
|
||||
* ControllerTestCase::makePost() qui forge une requête HTTP.
|
||||
* ControllerTestBase::makePost() qui forge une requête HTTP.
|
||||
*/
|
||||
private function buildPostEntity(
|
||||
int $id,
|
||||
|
||||
@@ -143,9 +143,7 @@ final class PostRepositoryTest extends TestCase
|
||||
|
||||
$stmt->expects($this->once())
|
||||
->method('execute')
|
||||
->with($this->callback(fn (array $p): bool =>
|
||||
isset($p[':category_id']) && $p[':category_id'] === 3
|
||||
));
|
||||
->with([':category_id' => 3]);
|
||||
|
||||
$this->repository->findAll(3);
|
||||
}
|
||||
@@ -217,9 +215,7 @@ final class PostRepositoryTest extends TestCase
|
||||
|
||||
$stmt->expects($this->once())
|
||||
->method('execute')
|
||||
->with($this->callback(fn (array $p): bool =>
|
||||
isset($p[':author_id']) && $p[':author_id'] === 7
|
||||
));
|
||||
->with([':author_id' => 7]);
|
||||
|
||||
$this->repository->findByUserId(7);
|
||||
}
|
||||
@@ -234,11 +230,7 @@ final class PostRepositoryTest extends TestCase
|
||||
|
||||
$stmt->expects($this->once())
|
||||
->method('execute')
|
||||
->with($this->callback(fn (array $p): bool =>
|
||||
isset($p[':author_id'], $p[':category_id'])
|
||||
&& $p[':author_id'] === 7
|
||||
&& $p[':category_id'] === 3
|
||||
));
|
||||
->with([':author_id' => 7, ':category_id' => 3]);
|
||||
|
||||
$this->repository->findByUserId(7, 3);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use App\Post\Post;
|
||||
use App\Post\PostServiceInterface;
|
||||
use App\Post\RssController;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Tests\ControllerTestCase;
|
||||
use Tests\ControllerTestBase;
|
||||
|
||||
/**
|
||||
* Tests unitaires pour RssController.
|
||||
@@ -20,7 +20,7 @@ use Tests\ControllerTestCase;
|
||||
* - Appel à getRecentPosts() avec la constante FEED_LIMIT (20)
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class RssControllerTest extends ControllerTestCase
|
||||
final class RssControllerTest extends ControllerTestBase
|
||||
{
|
||||
/** @var PostServiceInterface&MockObject */
|
||||
private PostServiceInterface $postService;
|
||||
|
||||
Reference in New Issue
Block a user