fix school year and related issues
Tests / PHPUnit (push) Failing after 34s

This commit is contained in:
root
2026-07-30 00:48:54 -04:00
parent f8f00c70c8
commit 81a72a4c59
27 changed files with 1512 additions and 52 deletions
@@ -29,6 +29,8 @@ final class SchoolYearContextRequest extends MockIncomingRequest
final class SchoolYearContextFakeModel extends SchoolYearModel
{
private array $filters = [];
public function __construct(private readonly array $rows)
{
}
@@ -48,6 +50,35 @@ final class SchoolYearContextFakeModel extends SchoolYearModel
return null;
}
public function where($key, $value = null, ?bool $escape = null)
{
$this->filters[] = [$key, $value];
return $this;
}
public function orderBy($orderBy, string $direction = '', ?bool $escape = null)
{
return $this;
}
public function findAll(?int $limit = null, int $offset = 0)
{
$rows = array_values(array_filter($this->rows, function (array $row): bool {
foreach ($this->filters as [$key, $value]) {
if (($row[$key] ?? null) !== $value) {
return false;
}
}
return true;
}));
$this->filters = [];
return $limit !== null ? array_slice($rows, $offset, $limit) : array_slice($rows, $offset);
}
}
final class SchoolYearContextServiceTest extends CIUnitTestCase
@@ -116,4 +147,20 @@ final class SchoolYearContextServiceTest extends CIUnitTestCase
$this->assertNull(session()->get('semester'));
$this->assertNull(session()->get('active_school_year'));
}
public function testSingleClosingYearIsUsedAsReadonlyContextWhenNoActiveYearExists(): void
{
$service = new SchoolYearContextService(new SchoolYearContextFakeModel([
1 => ['id' => 1, 'name' => '2025-2026', 'status' => 'closing'],
2 => ['id' => 2, 'name' => '2026-2027', 'status' => 'draft'],
]));
$context = $service->resolve(new SchoolYearContextRequest());
$this->assertSame(1, $context->id());
$this->assertSame('2025-2026', $context->yearName());
$this->assertSame('closing', $context->status());
$this->assertTrue($context->isReadonly());
$this->assertFalse($context->isExplicitSelection());
}
}