generated from Nodarx/template
feat: implement message create and update
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXT\ProviderImap\Tests\Unit;
|
||||
|
||||
use KTXM\ProviderImap\Providers\Service;
|
||||
use KTXM\ProviderImap\Service\Remote\RemoteMailService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
final class RemoteMailServiceTest extends TestCase {
|
||||
|
||||
public function testEntityReplaceReturnsAuthoritativeReplacementUid(): void {
|
||||
$service = new RemoteMailServiceStub($this->createStub(Service::class));
|
||||
$service->appendUid = 202;
|
||||
$service->destroyResults = [[101 => true]];
|
||||
|
||||
$result = $service->entityReplace('Drafts', 101, 'raw message', ['\\Draft']);
|
||||
|
||||
$this->assertSame(202, $result);
|
||||
$this->assertSame([
|
||||
['Drafts', 'raw message', ['\\Draft']],
|
||||
], $service->createCalls);
|
||||
$this->assertSame([
|
||||
['Drafts', [101]],
|
||||
], $service->destroyCalls);
|
||||
}
|
||||
|
||||
public function testEntityReplaceRemovesReplacementWhenOldUidCannotBeDeleted(): void {
|
||||
$service = new RemoteMailServiceStub($this->createStub(Service::class));
|
||||
$service->appendUid = 202;
|
||||
$service->destroyResults = [
|
||||
[101 => false],
|
||||
[202 => true],
|
||||
];
|
||||
|
||||
try {
|
||||
$service->entityReplace('Drafts', 101, 'raw message', ['\\Draft']);
|
||||
$this->fail('Expected superseded message cleanup failure');
|
||||
} catch (RuntimeException $exception) {
|
||||
$this->assertSame('Failed to delete the superseded IMAP entity', $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertSame([
|
||||
['Drafts', [101]],
|
||||
['Drafts', [202]],
|
||||
], $service->destroyCalls);
|
||||
}
|
||||
}
|
||||
|
||||
final class RemoteMailServiceStub extends RemoteMailService {
|
||||
|
||||
public ?int $appendUid = null;
|
||||
public array $createCalls = [];
|
||||
public array $destroyCalls = [];
|
||||
public array $destroyResults = [];
|
||||
|
||||
public function entityCreate(string $collection, string $rawMessage, array $flags = []): ?int {
|
||||
$this->createCalls[] = [$collection, $rawMessage, $flags];
|
||||
return $this->appendUid;
|
||||
}
|
||||
|
||||
public function entityDestroy(string $collection, int ...$uids): array {
|
||||
$this->destroyCalls[] = [$collection, $uids];
|
||||
return array_shift($this->destroyResults) ?? [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user