031e499819
API CI/CD / Validate (composer + pint) (push) Successful in 3m10s
API CI/CD / Test (PHPUnit) (push) Failing after 6m49s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 1m0s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Staff;
|
|
|
|
use App\Models\Staff;
|
|
use App\Models\User;
|
|
use App\Services\Staff\StaffCommandService;
|
|
use App\Services\System\GlobalConfigService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
class StaffCommandServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_create_requires_user(): void
|
|
{
|
|
$this->seedRole('teacher');
|
|
$service = new StaffCommandService(new GlobalConfigService);
|
|
|
|
$this->expectException(\RuntimeException::class);
|
|
$service->create([
|
|
'firstname' => 'Test',
|
|
'lastname' => 'User',
|
|
'email' => 'missing@example.com',
|
|
'role_name' => 'teacher',
|
|
]);
|
|
}
|
|
|
|
public function test_create_with_user_id(): void
|
|
{
|
|
$this->seedRole('teacher');
|
|
$user = User::query()->create([
|
|
'firstname' => 'Test',
|
|
'lastname' => 'User',
|
|
'email' => 'staffcmd@example.com',
|
|
'cellphone' => '5555555555',
|
|
'address_street' => '123 Main',
|
|
'city' => 'City',
|
|
'state' => 'ST',
|
|
'zip' => '12345',
|
|
'accept_school_policy' => 1,
|
|
'status' => 'Active',
|
|
'password' => bcrypt('secret'),
|
|
'semester' => 'Fall',
|
|
'school_year' => '2025-2026',
|
|
]);
|
|
|
|
$service = new StaffCommandService(new GlobalConfigService);
|
|
$staff = $service->create([
|
|
'user_id' => $user->id,
|
|
'firstname' => 'Staff',
|
|
'lastname' => 'User',
|
|
'email' => 'staffcmd@example.com',
|
|
'role_name' => 'teacher',
|
|
'school_year' => '2025-2026',
|
|
]);
|
|
|
|
$this->assertInstanceOf(Staff::class, $staff);
|
|
$this->assertSame($user->id, $staff->user_id);
|
|
}
|
|
|
|
private function seedRole(string $name): void
|
|
{
|
|
DB::table('roles')->updateOrInsert(
|
|
['name' => $name],
|
|
[
|
|
'slug' => $name,
|
|
'priority' => 1,
|
|
'is_active' => 1,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]
|
|
);
|
|
}
|
|
}
|