-
Notifications
You must be signed in to change notification settings - Fork 0
Add GetOthersPostsController action and its feature test #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,87 @@ | ||||||
| <?php | ||||||
|
|
||||||
| namespace App\Post\Presentation\PresentationTest\Controller; | ||||||
|
|
||||||
| use App\Post\Application\UseCase\GetOthersAllPostsUseCase; | ||||||
| use App\Post\Presentation\Controller\PostController; | ||||||
| use Illuminate\Http\JsonResponse; | ||||||
| use Illuminate\Http\Request; | ||||||
| use Tests\TestCase; | ||||||
| use Mockery; | ||||||
| use App\Common\Application\Dto\Pagination as PaginationDto; | ||||||
|
|
||||||
| class PostController_getOthersPostsTest extends TestCase | ||||||
| { | ||||||
|
|
||||||
| private $currentPage; | ||||||
| private $perPage; | ||||||
|
|
||||||
| private $controller; | ||||||
|
|
||||||
| protected function setUp(): void | ||||||
| { | ||||||
| parent::setUp(); | ||||||
| $this->currentPage = 1; | ||||||
| $this->perPage = 10; | ||||||
| $this->controller = new PostController(); | ||||||
| } | ||||||
|
|
||||||
| protected function tearDown(): void | ||||||
| { | ||||||
| parent::tearDown(); | ||||||
| } | ||||||
|
|
||||||
| private function mockUseCase(): GetOthersAllPostsUseCase | ||||||
| { | ||||||
| $useCase = Mockery::mock(GetOthersAllPostsUseCase::class); | ||||||
|
|
||||||
| $useCase->shouldReceive('handle') | ||||||
| ->with( | ||||||
| Mockery::type('int'), | ||||||
| Mockery::type($this->perPage), | ||||||
| Mockery::type($this->currentPage) | ||||||
| ) | ||||||
| ->andReturn($this->mockPagination()); | ||||||
|
|
||||||
| return $useCase; | ||||||
| } | ||||||
|
|
||||||
| private function mockPagination(): PaginationDto | ||||||
| { | ||||||
| $paginationDto = Mockery::mock(PaginationDto::class); | ||||||
|
|
||||||
| $paginationDto->shouldReceive('getCurrentPage') | ||||||
| ->andReturn($this->currentPage); | ||||||
|
|
||||||
| $paginationDto->shouldReceive('getPerPage') | ||||||
| ->andReturn($this->perPage); | ||||||
|
|
||||||
| return $paginationDto; | ||||||
| } | ||||||
|
|
||||||
| private function mockRequest(): Request | ||||||
| { | ||||||
| $request = Mockery::mock(Request::class); | ||||||
|
|
||||||
| $request->shouldReceive('input') | ||||||
| ->with('perPage') | ||||||
|
||||||
| ->with('perPage') | |
| ->with('per_page') |
Copilot
AI
Jul 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test mocks input('currentPage') but the controller uses get('current_page'); update the mock to input('current_page') or make naming consistent.
| ->with('currentPage') | |
| ->with('current_page') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Mockery::type($this->perPage)will not match the integer type; useMockery::type('int')or a more specific matcher instead.