73 lines
2.3 KiB
PHP
73 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\AttendanceTracking;
|
|
|
|
use App\Models\AttendanceData;
|
|
use App\Models\Configuration;
|
|
use App\Models\Student;
|
|
use App\Services\AttendanceCommunicationSupportService;
|
|
use App\Services\AttendanceEmailComposerService;
|
|
use App\Services\AttendanceParentLookupService;
|
|
use Mockery;
|
|
use Tests\TestCase;
|
|
|
|
class AttendanceCommunicationSupportServiceTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
|
|
protected function makeService(
|
|
?Student $student = null,
|
|
?AttendanceData $attendanceData = null,
|
|
?Configuration $config = null,
|
|
?AttendanceParentLookupService $parents = null,
|
|
?AttendanceEmailComposerService $composer = null
|
|
): AttendanceCommunicationSupportService {
|
|
$student ??= Mockery::mock(Student::class);
|
|
$attendanceData ??= Mockery::mock(AttendanceData::class);
|
|
$config ??= Mockery::mock(Configuration::class);
|
|
$parents ??= Mockery::mock(AttendanceParentLookupService::class);
|
|
$composer ??= Mockery::mock(AttendanceEmailComposerService::class);
|
|
|
|
$config->shouldReceive('getConfig')->with('semester')->andReturn('Fall');
|
|
$config->shouldReceive('getConfig')->with('school_year')->andReturn('2025-2026');
|
|
|
|
return new AttendanceCommunicationSupportService(
|
|
$student,
|
|
$attendanceData,
|
|
$config,
|
|
$parents,
|
|
$composer
|
|
);
|
|
}
|
|
|
|
public function test_compose_returns_422_when_student_id_missing(): void
|
|
{
|
|
$service = $this->makeService();
|
|
|
|
$result = $service->compose(0);
|
|
|
|
$this->assertFalse($result['success']);
|
|
$this->assertSame(422, $result['status']);
|
|
}
|
|
|
|
public function test_parents_info_delegates_to_parent_lookup_service(): void
|
|
{
|
|
$parents = Mockery::mock(AttendanceParentLookupService::class);
|
|
$parents->shouldReceive('parentsInfo')
|
|
->once()
|
|
->with(20, '2025-2026')
|
|
->andReturn(['success' => true, 'data' => ['primary' => [], 'secondary' => []]]);
|
|
|
|
$service = $this->makeService(
|
|
parents: $parents
|
|
);
|
|
|
|
$result = $service->parentsInfo(20);
|
|
|
|
$this->assertTrue($result['success']);
|
|
}
|
|
} |