This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user