update project
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\SchoolCore\Context;
|
||||
|
||||
use App\Domain\SchoolCore\Context\SchoolContext;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SchoolContextTest extends TestCase
|
||||
{
|
||||
public function test_it_builds_audit_payload(): void
|
||||
{
|
||||
$context = new SchoolContext(
|
||||
schoolId: 12,
|
||||
actorUserId: 44,
|
||||
actorRoleIds: [1, 2],
|
||||
schoolYear: '2025-2026',
|
||||
term: 'spring',
|
||||
timezone: 'America/New_York',
|
||||
locale: 'en',
|
||||
currency: 'USD',
|
||||
domainProfile: SchoolContext::DOMAIN_ISLAMIC_SUNDAY_SCHOOL,
|
||||
);
|
||||
|
||||
$this->assertTrue($context->isIslamicSundaySchool());
|
||||
$this->assertSame(12, $context->auditPayload()['school_id']);
|
||||
$this->assertSame('spring', $context->term);
|
||||
$this->assertSame('fall', $context->withTerm('fall')->term);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\SchoolCore\Context;
|
||||
|
||||
use App\Domain\SchoolCore\Context\SchoolContext;
|
||||
use App\Domain\SchoolCore\Context\SchoolContextException;
|
||||
use App\Domain\SchoolCore\Context\SchoolContextValidator;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class SchoolContextValidatorTest extends TestCase
|
||||
{
|
||||
public function test_it_rejects_invalid_timezone(): void
|
||||
{
|
||||
$this->expectException(SchoolContextException::class);
|
||||
|
||||
$validator = new SchoolContextValidator();
|
||||
$validator->assertValid($this->context(timezone: 'Not/AZone'), new FakeActor(10, 99));
|
||||
}
|
||||
|
||||
public function test_it_rejects_wrong_school_actor(): void
|
||||
{
|
||||
$this->expectException(SchoolContextException::class);
|
||||
|
||||
$validator = new SchoolContextValidator();
|
||||
$validator->assertValid($this->context(schoolId: 20), new FakeActor(10, 99));
|
||||
}
|
||||
|
||||
private function context(int $schoolId = 10, string $timezone = 'UTC'): SchoolContext
|
||||
{
|
||||
return new SchoolContext(
|
||||
schoolId: $schoolId,
|
||||
actorUserId: 99,
|
||||
actorRoleIds: [],
|
||||
schoolYear: '2025-2026',
|
||||
term: 'spring',
|
||||
timezone: $timezone,
|
||||
locale: 'en',
|
||||
currency: 'USD',
|
||||
domainProfile: SchoolContext::DOMAIN_STANDARD_SCHOOL,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final class FakeActor implements Authenticatable
|
||||
{
|
||||
public function __construct(public int $school_id, private int $id)
|
||||
{
|
||||
}
|
||||
|
||||
public function getAuthIdentifierName(): string { return 'id'; }
|
||||
public function getAuthIdentifier(): mixed { return $this->id; }
|
||||
public function getAuthPassword(): string { return ''; }
|
||||
public function getAuthPasswordName(): string { return 'password'; }
|
||||
public function getRememberToken(): ?string { return null; }
|
||||
public function setRememberToken($value): void {}
|
||||
public function getRememberTokenName(): string { return 'remember_token'; }
|
||||
}
|
||||
Reference in New Issue
Block a user