Working state
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user