fix test issues
Tests / PHPUnit (push) Failing after 51s

This commit is contained in:
root
2026-07-12 19:37:19 -04:00
parent 84337e8a50
commit 62492a5644
4 changed files with 4 additions and 206 deletions
@@ -1,150 +0,0 @@
<?php
namespace App\Controllers\Api;
use App\Controllers\BaseController;
use App\Models\AssignmentModel;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
class AssignmentController extends BaseController
{
use ResponseTrait;
protected $assignmentModel;
public function __construct()
{
$this->assignmentModel = new AssignmentModel();
}
public function setRequest(RequestInterface $request): void
{
$this->request = $request;
}
public function index()
{
$page = (int) ($this->request->getGet('page') ?? 1);
$perPage = (int) ($this->request->getGet('per_page') ?? 20);
foreach (['class_id', 'teacher_id', 'student_id'] as $filter) {
$value = $this->request->getGet($filter);
if ($value !== null && $value !== '') {
$this->assignmentModel->where($filter, $value);
}
}
$assignments = $this->assignmentModel->paginate(max(1, $perPage), 'default', max(1, $page));
$pager = $this->assignmentModel->pager ?? null;
return $this->respond([
'data' => $assignments,
'pagination' => [
'current_page' => $pager ? (int) $pager->getCurrentPage() : max(1, $page),
'per_page' => $pager ? (int) $pager->getPerPage() : max(1, $perPage),
'total' => $pager ? (int) $pager->getTotal() : count($assignments),
'total_pages' => $pager ? (int) $pager->getPageCount() : 1,
],
], ResponseInterface::HTTP_OK, 'Assignments retrieved successfully');
}
public function show(int $id)
{
$assignment = $this->assignmentModel->find($id);
if (! $assignment) {
return $this->respond(null, ResponseInterface::HTTP_NOT_FOUND, 'Assignment not found');
}
return $this->respond($assignment, ResponseInterface::HTTP_OK, 'Assignment retrieved successfully');
}
public function store()
{
$payload = $this->request->getJSON(true) ?? [];
$rules = [
'title' => 'required|string|max_length[255]',
'due_date' => 'required|valid_date',
'class_id' => 'required|integer',
'teacher_id' => 'required|integer',
];
if (! $this->validate($rules)) {
return [
'status' => false,
'code' => ResponseInterface::HTTP_UNPROCESSABLE_ENTITY,
'message' => 'Validation failed',
'errors' => $this->validator->getErrors(),
];
}
$id = $this->assignmentModel->insert($payload);
return $this->respond(
$this->assignmentModel->find($id),
ResponseInterface::HTTP_CREATED,
'Assignment created successfully'
);
}
public function update(int $id)
{
if (! $this->assignmentModel->find($id)) {
return $this->respond(null, ResponseInterface::HTTP_NOT_FOUND, 'Assignment not found');
}
$payload = $this->request->getJSON(true) ?? [];
$rules = [
'title' => 'permit_empty|string|max_length[255]',
'description' => 'permit_empty|string',
'due_date' => 'permit_empty|valid_date',
'class_id' => 'permit_empty|integer',
'teacher_id' => 'permit_empty|integer',
'student_id' => 'permit_empty|integer',
];
if (! $this->validate($rules)) {
return [
'status' => false,
'code' => ResponseInterface::HTTP_UNPROCESSABLE_ENTITY,
'message' => 'Validation failed',
'errors' => $this->validator->getErrors(),
];
}
$this->assignmentModel->update($id, $payload);
return $this->respond(
$this->assignmentModel->find($id),
ResponseInterface::HTTP_OK,
'Assignment updated successfully'
);
}
public function delete(int $id)
{
if (! $this->assignmentModel->find($id)) {
return $this->respond(null, ResponseInterface::HTTP_NOT_FOUND, 'Assignment not found');
}
$this->assignmentModel->delete($id);
return $this->respond(null, ResponseInterface::HTTP_OK, 'Assignment deleted successfully');
}
public function student(int $studentId)
{
$assignments = $this->assignmentModel
->where('student_id', $studentId)
->findAll();
return $this->respond(
$assignments,
ResponseInterface::HTTP_OK,
'Assignments retrieved successfully for student'
);
}
}