Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions Modules/Invoices/Tests/Unit/Enums/PeppolConnectionStatusTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php

namespace Modules\Invoices\Tests\Unit\Enums;

use Modules\Invoices\Enums\PeppolConnectionStatus;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

/**
* PeppolConnectionStatusTest - Unit tests for PeppolConnectionStatus enum.
*
* Tests the connection status enum including labels, colors, icons,
* and instantiation from values.
*
* @package Modules\Invoices\Tests\Unit\Enums
*/
#[Group('peppol')]
class PeppolConnectionStatusTest extends TestCase
{
#[Test]
public function it_has_all_expected_cases(): void
{
$cases = PeppolConnectionStatus::cases();

$this->assertCount(3, $cases);
$this->assertContains(PeppolConnectionStatus::UNTESTED, $cases);
$this->assertContains(PeppolConnectionStatus::SUCCESS, $cases);
$this->assertContains(PeppolConnectionStatus::FAILED, $cases);
}

#[Test]
#[DataProvider('labelProvider')]
public function it_provides_correct_labels(
PeppolConnectionStatus $status,
string $expectedLabel
): void {
$this->assertEquals($expectedLabel, $status->label());
}

public static function labelProvider(): array
{
return [
[PeppolConnectionStatus::UNTESTED, 'Untested'],
[PeppolConnectionStatus::SUCCESS, 'Success'],
[PeppolConnectionStatus::FAILED, 'Failed'],
];
}

#[Test]
#[DataProvider('colorProvider')]
public function it_provides_correct_colors(
PeppolConnectionStatus $status,
string $expectedColor
): void {
$this->assertEquals($expectedColor, $status->color());
}

public static function colorProvider(): array
{
return [
[PeppolConnectionStatus::UNTESTED, 'gray'],
[PeppolConnectionStatus::SUCCESS, 'green'],
[PeppolConnectionStatus::FAILED, 'red'],
];
}

#[Test]
#[DataProvider('iconProvider')]
public function it_provides_correct_icons(
PeppolConnectionStatus $status,
string $expectedIcon
): void {
$this->assertEquals($expectedIcon, $status->icon());
}

public static function iconProvider(): array
{
return [
[PeppolConnectionStatus::UNTESTED, 'heroicon-o-question-mark-circle'],
[PeppolConnectionStatus::SUCCESS, 'heroicon-o-check-circle'],
[PeppolConnectionStatus::FAILED, 'heroicon-o-x-circle'],
];
}

#[Test]
#[DataProvider('valueProvider')]
public function it_has_correct_enum_values(
PeppolConnectionStatus $status,
string $expectedValue
): void {
$this->assertEquals($expectedValue, $status->value);
}

public static function valueProvider(): array
{
return [
[PeppolConnectionStatus::UNTESTED, 'untested'],
[PeppolConnectionStatus::SUCCESS, 'success'],
[PeppolConnectionStatus::FAILED, 'failed'],
];
}

#[Test]
public function it_can_be_instantiated_from_value(): void
{
$status = PeppolConnectionStatus::from('success');

$this->assertEquals(PeppolConnectionStatus::SUCCESS, $status);
}

#[Test]
public function it_throws_on_invalid_value(): void
{
$this->expectException(\ValueError::class);
PeppolConnectionStatus::from('invalid_status');
}

#[Test]
public function it_can_try_from_value_returning_null_on_invalid(): void
{
$status = PeppolConnectionStatus::tryFrom('invalid');

$this->assertNull($status);
}

#[Test]
public function it_can_be_used_in_match_expressions(): void
{
$status = PeppolConnectionStatus::SUCCESS;

$message = match ($status) {
PeppolConnectionStatus::UNTESTED => 'Not yet tested',
PeppolConnectionStatus::SUCCESS => 'Connection successful',
PeppolConnectionStatus::FAILED => 'Connection failed',
};

$this->assertEquals('Connection successful', $message);
}

#[Test]
public function it_provides_all_cases_for_selection(): void
{
$cases = PeppolConnectionStatus::cases();
$options = [];

foreach ($cases as $case) {
$options[$case->value] = $case->label();
}

$this->assertArrayHasKey('untested', $options);
$this->assertArrayHasKey('success', $options);
$this->assertArrayHasKey('failed', $options);
$this->assertEquals('Untested', $options['untested']);
$this->assertEquals('Success', $options['success']);
$this->assertEquals('Failed', $options['failed']);
}
}
133 changes: 133 additions & 0 deletions Modules/Invoices/Tests/Unit/Enums/PeppolErrorTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

namespace Modules\Invoices\Tests\Unit\Enums;

use Modules\Invoices\Enums\PeppolErrorType;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

/**
* PeppolErrorTypeTest - Unit tests for PeppolErrorType enum.
*
* Tests error type classification including labels, colors, and icons.
*
* @package Modules\Invoices\Tests\Unit\Enums
*/
#[Group('peppol')]
class PeppolErrorTypeTest extends TestCase
{
#[Test]
public function it_has_all_expected_cases(): void
{
$cases = PeppolErrorType::cases();

$this->assertCount(3, $cases);
$this->assertContains(PeppolErrorType::TRANSIENT, $cases);
$this->assertContains(PeppolErrorType::PERMANENT, $cases);
$this->assertContains(PeppolErrorType::UNKNOWN, $cases);
}

#[Test]
#[DataProvider('labelProvider')]
public function it_provides_correct_labels(
PeppolErrorType $type,
string $expectedLabel
): void {
$this->assertEquals($expectedLabel, $type->label());
}

public static function labelProvider(): array
{
return [
[PeppolErrorType::TRANSIENT, 'Transient Error'],
[PeppolErrorType::PERMANENT, 'Permanent Error'],
[PeppolErrorType::UNKNOWN, 'Unknown Error'],
];
}

#[Test]
#[DataProvider('colorProvider')]
public function it_provides_correct_colors(
PeppolErrorType $type,
string $expectedColor
): void {
$this->assertEquals($expectedColor, $type->color());
}

public static function colorProvider(): array
{
return [
[PeppolErrorType::TRANSIENT, 'yellow'],
[PeppolErrorType::PERMANENT, 'red'],
[PeppolErrorType::UNKNOWN, 'gray'],
];
}

#[Test]
#[DataProvider('iconProvider')]
public function it_provides_correct_icons(
PeppolErrorType $type,
string $expectedIcon
): void {
$this->assertEquals($expectedIcon, $type->icon());
}

public static function iconProvider(): array
{
return [
[PeppolErrorType::TRANSIENT, 'heroicon-o-arrow-path'],
[PeppolErrorType::PERMANENT, 'heroicon-o-x-circle'],
[PeppolErrorType::UNKNOWN, 'heroicon-o-question-mark-circle'],
];
}

#[Test]
#[DataProvider('valueProvider')]
public function it_has_correct_enum_values(
PeppolErrorType $type,
string $expectedValue
): void {
$this->assertEquals($expectedValue, $type->value);
}

public static function valueProvider(): array
{
return [
[PeppolErrorType::TRANSIENT, 'TRANSIENT'],
[PeppolErrorType::PERMANENT, 'PERMANENT'],
[PeppolErrorType::UNKNOWN, 'UNKNOWN'],
];
}

#[Test]
public function it_can_be_instantiated_from_value(): void
{
$type = PeppolErrorType::from('TRANSIENT');

$this->assertEquals(PeppolErrorType::TRANSIENT, $type);
}

#[Test]
public function it_throws_on_invalid_value(): void
{
$this->expectException(\ValueError::class);
PeppolErrorType::from('INVALID');
}

#[Test]
public function it_distinguishes_retryable_vs_permanent_errors(): void
{
$transient = PeppolErrorType::TRANSIENT;
$permanent = PeppolErrorType::PERMANENT;

// Transient errors typically warrant retry
$this->assertEquals('yellow', $transient->color());
$this->assertStringContainsString('arrow-path', $transient->icon());

// Permanent errors should not be retried
$this->assertEquals('red', $permanent->color());
$this->assertStringContainsString('x-circle', $permanent->icon());
}
}
Loading