Files
alrahma_sunday_school/tests/app/Services/SchoolYearClosingServiceTest.php
T
root 36e8ffe56d
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 49s
Tests / PHPUnit (push) Successful in 1m21s
fix the enrollement-carryover balance
2026-09-09 21:40:01 -04:00

81 lines
2.9 KiB
PHP

<?php
namespace Tests\App\Services;
use App\Services\SchoolYearClosingService;
use CodeIgniter\Test\CIUnitTestCase;
use ReflectionClass;
final class SchoolYearClosingServiceTest extends CIUnitTestCase
{
public function testPromotionBlockerStudentsIncludeIdentifyingInformation(): void
{
$service = (new ReflectionClass(SchoolYearClosingService::class))->newInstanceWithoutConstructor();
$students = $this->privateMethodInvoker($service, 'promotionStudentsWithStatus')([
[
'student_id' => 17,
'student_name' => 'Amina Rahman',
'school_id' => 'S-1042',
'class_section_name' => 'Grade 4 - A',
'status' => 'missing',
],
[
'student_id' => 18,
'student_name' => 'Omar Ali',
'school_id' => 'S-1043',
'class_section_name' => 'Grade 5 - B',
'status' => 'decided',
],
], 'missing');
$this->assertSame([[
'student_id' => 17,
'student_name' => 'Amina Rahman',
'school_id' => 'S-1042',
'class_section_name' => 'Grade 4 - A',
]], $students);
}
public function testLegacyManualDecisionPreventsFalseMissingDecisionBlocker(): void
{
$service = (new ReflectionClass(SchoolYearClosingService::class))->newInstanceWithoutConstructor();
$merge = $this->privateMethodInvoker($service, 'mergeFallbackPromotionDecisions');
$decisions = $merge([], [[
'student_id' => 191,
'decision' => 'Make-up exam in fall',
'notes' => 'Make-up exam approved.',
]]);
$this->assertSame('decided', $decisions[191]['status']);
$this->assertSame('MAKE_UP_EXAM', $decisions[191]['normalized_decision']);
$this->assertSame('manual', $decisions[191]['source']);
}
public function testLegacyManualDecisionReplacesStalePendingConsolidatedDecision(): void
{
$service = (new ReflectionClass(SchoolYearClosingService::class))->newInstanceWithoutConstructor();
$merge = $this->privateMethodInvoker($service, 'mergeFallbackPromotionDecisions');
$decisions = $merge([
191 => ['status' => 'pending', 'decision' => '', 'source' => 'pending'],
], [[
'student_id' => 191,
'decision' => 'Make-up exam in fall',
'notes' => '',
]]);
$this->assertSame('decided', $decisions[191]['status']);
$this->assertSame('Make-up exam in fall', $decisions[191]['decision']);
}
private function privateMethodInvoker(object $object, string $method): callable
{
$reflection = new ReflectionClass($object);
$reflectionMethod = $reflection->getMethod($method);
return static fn (...$arguments) => $reflectionMethod->invoke($object, ...$arguments);
}
}