85428826a0
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Service;
|
|
|
|
use App\Service\ProviderErrorCode;
|
|
use App\Service\ProviderStatus;
|
|
use App\Service\ProviderStatusType;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
#[CoversClass(ProviderStatus::class)]
|
|
final class ProviderStatusTest extends TestCase
|
|
{
|
|
#[Test]
|
|
public function it_serializes_ok_status(): void
|
|
{
|
|
$status = new ProviderStatus('github', ProviderStatusType::Ok);
|
|
|
|
$this->assertSame(['status' => 'ok'], $status->toArray());
|
|
}
|
|
|
|
#[Test]
|
|
public function it_serializes_not_configured_status(): void
|
|
{
|
|
$status = new ProviderStatus('github', ProviderStatusType::NotConfigured);
|
|
|
|
$this->assertSame(['status' => 'not_configured'], $status->toArray());
|
|
}
|
|
|
|
#[Test]
|
|
public function it_serializes_error_status_with_code_and_message(): void
|
|
{
|
|
$status = new ProviderStatus('github', ProviderStatusType::Error, ProviderErrorCode::AuthFailed, 'Token expired');
|
|
|
|
$this->assertSame([
|
|
'status' => 'error',
|
|
'error' => 'auth_failed',
|
|
'message' => 'Token expired',
|
|
], $status->toArray());
|
|
}
|
|
|
|
#[Test]
|
|
public function it_omits_null_error_fields_from_array(): void
|
|
{
|
|
$status = new ProviderStatus('github', ProviderStatusType::Ok);
|
|
|
|
$array = $status->toArray();
|
|
|
|
$this->assertArrayNotHasKey('error', $array);
|
|
$this->assertArrayNotHasKey('message', $array);
|
|
}
|
|
|
|
#[Test]
|
|
public function it_exposes_typed_status_property(): void
|
|
{
|
|
$status = new ProviderStatus('github', ProviderStatusType::Error, ProviderErrorCode::Unknown, 'msg');
|
|
|
|
$this->assertSame(ProviderStatusType::Error, $status->status);
|
|
$this->assertSame(ProviderErrorCode::Unknown, $status->error);
|
|
}
|
|
}
|