feat(mail) : DTO MailSyncReport + test unitaire
This commit is contained in:
24
src/Mail/Dto/MailSyncReport.php
Normal file
24
src/Mail/Dto/MailSyncReport.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Mail\Dto;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
|
||||||
|
final readonly class MailSyncReport
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param list<string> $errors
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public int $createdCount,
|
||||||
|
public int $updatedCount,
|
||||||
|
public int $deletedCount,
|
||||||
|
public int $foldersScanned,
|
||||||
|
public array $errors,
|
||||||
|
public float $durationSeconds,
|
||||||
|
public DateTimeImmutable $startedAt,
|
||||||
|
public DateTimeImmutable $finishedAt,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
58
tests/Unit/Mail/MailSyncReportTest.php
Normal file
58
tests/Unit/Mail/MailSyncReportTest.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Unit\Mail;
|
||||||
|
|
||||||
|
use App\Mail\Dto\MailSyncReport;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class MailSyncReportTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testInstantiationWithDefaults(): void
|
||||||
|
{
|
||||||
|
$start = new DateTimeImmutable('2026-01-01 10:00:00');
|
||||||
|
$finish = new DateTimeImmutable('2026-01-01 10:00:05');
|
||||||
|
|
||||||
|
$report = new MailSyncReport(
|
||||||
|
createdCount: 3,
|
||||||
|
updatedCount: 1,
|
||||||
|
deletedCount: 0,
|
||||||
|
foldersScanned: 2,
|
||||||
|
errors: [],
|
||||||
|
durationSeconds: 5.0,
|
||||||
|
startedAt: $start,
|
||||||
|
finishedAt: $finish,
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertSame(3, $report->createdCount);
|
||||||
|
self::assertSame(1, $report->updatedCount);
|
||||||
|
self::assertSame(0, $report->deletedCount);
|
||||||
|
self::assertSame(2, $report->foldersScanned);
|
||||||
|
self::assertSame([], $report->errors);
|
||||||
|
self::assertSame(5.0, $report->durationSeconds);
|
||||||
|
self::assertSame($start, $report->startedAt);
|
||||||
|
self::assertSame($finish, $report->finishedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWithErrors(): void
|
||||||
|
{
|
||||||
|
$report = new MailSyncReport(
|
||||||
|
createdCount: 0,
|
||||||
|
updatedCount: 0,
|
||||||
|
deletedCount: 0,
|
||||||
|
foldersScanned: 1,
|
||||||
|
errors: ['IMAP connection timeout'],
|
||||||
|
durationSeconds: 0.5,
|
||||||
|
startedAt: new DateTimeImmutable(),
|
||||||
|
finishedAt: new DateTimeImmutable(),
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertCount(1, $report->errors);
|
||||||
|
self::assertSame('IMAP connection timeout', $report->errors[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user