bookings = Mockery::mock(BookingRepository::class); $this->payments = Mockery::mock(PaymentRepository::class); $this->availability = Mockery::mock(AvailabilityRepository::class); $this->controller = new LessonController($this->bookings, $this->payments, $this->availability); $_POST = []; Functions\when('current_user_can')->justReturn(true); Functions\when('get_userdata')->justReturn(false); Functions\when('mysql2date')->alias( static fn (string $format, string $date) => date($format, (int) strtotime($date)) ); } public function testAdminDashboardShowsSlotDateTimeInsteadOfSlotId(): void { $lesson = new Lesson(slotId: 10, studentId: 5, instructorId: 3, id: 1); $slot = new AvailabilitySlot( instructorId: 3, startDt: '2026-07-06 09:00:00', endDt: '2026-07-06 10:00:00', id: 10 ); $this->bookings->shouldReceive('findAllUpcoming')->once()->andReturn([$lesson]); $this->availability->shouldReceive('findById')->once()->with(10)->andReturn($slot); $html = $this->render(); self::assertStringContainsString('Jul 6, 2026 9:00 AM–10:00 AM', $html); self::assertStringContainsString('Date/Time', $html); self::assertStringNotContainsString('Slot ID', $html); } public function testSlotCrossingMidnightRepeatsTheDateOnTheEndTime(): void { $lesson = new Lesson(slotId: 11, studentId: 5, instructorId: 3, id: 2); $slot = new AvailabilitySlot( instructorId: 3, startDt: '2026-07-06 23:00:00', endDt: '2026-07-07 00:30:00', id: 11 ); $this->bookings->shouldReceive('findAllUpcoming')->once()->andReturn([$lesson]); $this->availability->shouldReceive('findById')->once()->with(11)->andReturn($slot); $html = $this->render(); self::assertStringContainsString('Jul 6, 2026 11:00 PM–Jul 7, 2026 12:30 AM', $html); } public function testMissingSlotRendersDash(): void { $lesson = new Lesson(slotId: 99, studentId: 5, instructorId: 3, id: 3); $this->bookings->shouldReceive('findAllUpcoming')->once()->andReturn([$lesson]); $this->availability->shouldReceive('findById')->once()->with(99)->andReturn(null); $html = $this->render(); self::assertStringContainsString('—', $html); } public function testInstructorLessonsShowSlotDateTime(): void { Functions\when('get_current_user_id')->justReturn(3); $lesson = new Lesson(slotId: 12, studentId: 5, instructorId: 3, id: 4); $slot = new AvailabilitySlot( instructorId: 3, startDt: '2026-08-01 14:00:00', endDt: '2026-08-01 15:00:00', id: 12 ); $this->bookings->shouldReceive('findUpcomingForInstructor')->once()->with(3)->andReturn([$lesson]); $this->availability->shouldReceive('findById')->once()->with(12)->andReturn($slot); ob_start(); $this->controller->renderInstructorLessons(); $html = (string) ob_get_clean(); self::assertStringContainsString('Aug 1, 2026 2:00 PM–3:00 PM', $html); } private function render(): string { ob_start(); $this->controller->renderAdminDashboard(); return (string) ob_get_clean(); } }