Skip to content

Commit 4d4c3e8

Browse files
CodeRabbit Generated Unit Tests: Add PEPPOL PHPUnit test suite and testing documentation (#107)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent a36f032 commit 4d4c3e8

File tree

10 files changed

+1904
-0
lines changed

10 files changed

+1904
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
3+
namespace Modules\Invoices\Tests\Unit\Enums;
4+
5+
use Modules\Invoices\Enums\PeppolConnectionStatus;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
use PHPUnit\Framework\Attributes\Group;
8+
use PHPUnit\Framework\Attributes\Test;
9+
use Tests\TestCase;
10+
11+
/**
12+
* PeppolConnectionStatusTest - Unit tests for PeppolConnectionStatus enum.
13+
*
14+
* Tests the connection status enum including labels, colors, icons,
15+
* and instantiation from values.
16+
*
17+
* @package Modules\Invoices\Tests\Unit\Enums
18+
*/
19+
#[Group('peppol')]
20+
class PeppolConnectionStatusTest extends TestCase
21+
{
22+
#[Test]
23+
public function it_has_all_expected_cases(): void
24+
{
25+
$cases = PeppolConnectionStatus::cases();
26+
27+
$this->assertCount(3, $cases);
28+
$this->assertContains(PeppolConnectionStatus::UNTESTED, $cases);
29+
$this->assertContains(PeppolConnectionStatus::SUCCESS, $cases);
30+
$this->assertContains(PeppolConnectionStatus::FAILED, $cases);
31+
}
32+
33+
#[Test]
34+
#[DataProvider('labelProvider')]
35+
public function it_provides_correct_labels(
36+
PeppolConnectionStatus $status,
37+
string $expectedLabel
38+
): void {
39+
$this->assertEquals($expectedLabel, $status->label());
40+
}
41+
42+
public static function labelProvider(): array
43+
{
44+
return [
45+
[PeppolConnectionStatus::UNTESTED, 'Untested'],
46+
[PeppolConnectionStatus::SUCCESS, 'Success'],
47+
[PeppolConnectionStatus::FAILED, 'Failed'],
48+
];
49+
}
50+
51+
#[Test]
52+
#[DataProvider('colorProvider')]
53+
public function it_provides_correct_colors(
54+
PeppolConnectionStatus $status,
55+
string $expectedColor
56+
): void {
57+
$this->assertEquals($expectedColor, $status->color());
58+
}
59+
60+
public static function colorProvider(): array
61+
{
62+
return [
63+
[PeppolConnectionStatus::UNTESTED, 'gray'],
64+
[PeppolConnectionStatus::SUCCESS, 'green'],
65+
[PeppolConnectionStatus::FAILED, 'red'],
66+
];
67+
}
68+
69+
#[Test]
70+
#[DataProvider('iconProvider')]
71+
public function it_provides_correct_icons(
72+
PeppolConnectionStatus $status,
73+
string $expectedIcon
74+
): void {
75+
$this->assertEquals($expectedIcon, $status->icon());
76+
}
77+
78+
public static function iconProvider(): array
79+
{
80+
return [
81+
[PeppolConnectionStatus::UNTESTED, 'heroicon-o-question-mark-circle'],
82+
[PeppolConnectionStatus::SUCCESS, 'heroicon-o-check-circle'],
83+
[PeppolConnectionStatus::FAILED, 'heroicon-o-x-circle'],
84+
];
85+
}
86+
87+
#[Test]
88+
#[DataProvider('valueProvider')]
89+
public function it_has_correct_enum_values(
90+
PeppolConnectionStatus $status,
91+
string $expectedValue
92+
): void {
93+
$this->assertEquals($expectedValue, $status->value);
94+
}
95+
96+
public static function valueProvider(): array
97+
{
98+
return [
99+
[PeppolConnectionStatus::UNTESTED, 'untested'],
100+
[PeppolConnectionStatus::SUCCESS, 'success'],
101+
[PeppolConnectionStatus::FAILED, 'failed'],
102+
];
103+
}
104+
105+
#[Test]
106+
public function it_can_be_instantiated_from_value(): void
107+
{
108+
$status = PeppolConnectionStatus::from('success');
109+
110+
$this->assertEquals(PeppolConnectionStatus::SUCCESS, $status);
111+
}
112+
113+
#[Test]
114+
public function it_throws_on_invalid_value(): void
115+
{
116+
$this->expectException(\ValueError::class);
117+
PeppolConnectionStatus::from('invalid_status');
118+
}
119+
120+
#[Test]
121+
public function it_can_try_from_value_returning_null_on_invalid(): void
122+
{
123+
$status = PeppolConnectionStatus::tryFrom('invalid');
124+
125+
$this->assertNull($status);
126+
}
127+
128+
#[Test]
129+
public function it_can_be_used_in_match_expressions(): void
130+
{
131+
$status = PeppolConnectionStatus::SUCCESS;
132+
133+
$message = match ($status) {
134+
PeppolConnectionStatus::UNTESTED => 'Not yet tested',
135+
PeppolConnectionStatus::SUCCESS => 'Connection successful',
136+
PeppolConnectionStatus::FAILED => 'Connection failed',
137+
};
138+
139+
$this->assertEquals('Connection successful', $message);
140+
}
141+
142+
#[Test]
143+
public function it_provides_all_cases_for_selection(): void
144+
{
145+
$cases = PeppolConnectionStatus::cases();
146+
$options = [];
147+
148+
foreach ($cases as $case) {
149+
$options[$case->value] = $case->label();
150+
}
151+
152+
$this->assertArrayHasKey('untested', $options);
153+
$this->assertArrayHasKey('success', $options);
154+
$this->assertArrayHasKey('failed', $options);
155+
$this->assertEquals('Untested', $options['untested']);
156+
$this->assertEquals('Success', $options['success']);
157+
$this->assertEquals('Failed', $options['failed']);
158+
}
159+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
namespace Modules\Invoices\Tests\Unit\Enums;
4+
5+
use Modules\Invoices\Enums\PeppolErrorType;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
use PHPUnit\Framework\Attributes\Group;
8+
use PHPUnit\Framework\Attributes\Test;
9+
use Tests\TestCase;
10+
11+
/**
12+
* PeppolErrorTypeTest - Unit tests for PeppolErrorType enum.
13+
*
14+
* Tests error type classification including labels, colors, and icons.
15+
*
16+
* @package Modules\Invoices\Tests\Unit\Enums
17+
*/
18+
#[Group('peppol')]
19+
class PeppolErrorTypeTest extends TestCase
20+
{
21+
#[Test]
22+
public function it_has_all_expected_cases(): void
23+
{
24+
$cases = PeppolErrorType::cases();
25+
26+
$this->assertCount(3, $cases);
27+
$this->assertContains(PeppolErrorType::TRANSIENT, $cases);
28+
$this->assertContains(PeppolErrorType::PERMANENT, $cases);
29+
$this->assertContains(PeppolErrorType::UNKNOWN, $cases);
30+
}
31+
32+
#[Test]
33+
#[DataProvider('labelProvider')]
34+
public function it_provides_correct_labels(
35+
PeppolErrorType $type,
36+
string $expectedLabel
37+
): void {
38+
$this->assertEquals($expectedLabel, $type->label());
39+
}
40+
41+
public static function labelProvider(): array
42+
{
43+
return [
44+
[PeppolErrorType::TRANSIENT, 'Transient Error'],
45+
[PeppolErrorType::PERMANENT, 'Permanent Error'],
46+
[PeppolErrorType::UNKNOWN, 'Unknown Error'],
47+
];
48+
}
49+
50+
#[Test]
51+
#[DataProvider('colorProvider')]
52+
public function it_provides_correct_colors(
53+
PeppolErrorType $type,
54+
string $expectedColor
55+
): void {
56+
$this->assertEquals($expectedColor, $type->color());
57+
}
58+
59+
public static function colorProvider(): array
60+
{
61+
return [
62+
[PeppolErrorType::TRANSIENT, 'yellow'],
63+
[PeppolErrorType::PERMANENT, 'red'],
64+
[PeppolErrorType::UNKNOWN, 'gray'],
65+
];
66+
}
67+
68+
#[Test]
69+
#[DataProvider('iconProvider')]
70+
public function it_provides_correct_icons(
71+
PeppolErrorType $type,
72+
string $expectedIcon
73+
): void {
74+
$this->assertEquals($expectedIcon, $type->icon());
75+
}
76+
77+
public static function iconProvider(): array
78+
{
79+
return [
80+
[PeppolErrorType::TRANSIENT, 'heroicon-o-arrow-path'],
81+
[PeppolErrorType::PERMANENT, 'heroicon-o-x-circle'],
82+
[PeppolErrorType::UNKNOWN, 'heroicon-o-question-mark-circle'],
83+
];
84+
}
85+
86+
#[Test]
87+
#[DataProvider('valueProvider')]
88+
public function it_has_correct_enum_values(
89+
PeppolErrorType $type,
90+
string $expectedValue
91+
): void {
92+
$this->assertEquals($expectedValue, $type->value);
93+
}
94+
95+
public static function valueProvider(): array
96+
{
97+
return [
98+
[PeppolErrorType::TRANSIENT, 'TRANSIENT'],
99+
[PeppolErrorType::PERMANENT, 'PERMANENT'],
100+
[PeppolErrorType::UNKNOWN, 'UNKNOWN'],
101+
];
102+
}
103+
104+
#[Test]
105+
public function it_can_be_instantiated_from_value(): void
106+
{
107+
$type = PeppolErrorType::from('TRANSIENT');
108+
109+
$this->assertEquals(PeppolErrorType::TRANSIENT, $type);
110+
}
111+
112+
#[Test]
113+
public function it_throws_on_invalid_value(): void
114+
{
115+
$this->expectException(\ValueError::class);
116+
PeppolErrorType::from('INVALID');
117+
}
118+
119+
#[Test]
120+
public function it_distinguishes_retryable_vs_permanent_errors(): void
121+
{
122+
$transient = PeppolErrorType::TRANSIENT;
123+
$permanent = PeppolErrorType::PERMANENT;
124+
125+
// Transient errors typically warrant retry
126+
$this->assertEquals('yellow', $transient->color());
127+
$this->assertStringContainsString('arrow-path', $transient->icon());
128+
129+
// Permanent errors should not be retried
130+
$this->assertEquals('red', $permanent->color());
131+
$this->assertStringContainsString('x-circle', $permanent->icon());
132+
}
133+
}

0 commit comments

Comments
 (0)