generated from Nodarx/template
feat: serve message lists from the cache
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ namespace KTXT\ProviderImap\Tests\Support;
|
||||
|
||||
use Generator;
|
||||
use KTXF\Resource\Filter\IFilter;
|
||||
use KTXF\Resource\Range\IRange;
|
||||
use KTXF\Resource\Sort\ISort;
|
||||
use KTXM\ProviderImap\Client\Mailbox;
|
||||
use KTXM\ProviderImap\Client\Protocol\Command\Argument\FetchOptions;
|
||||
@@ -75,6 +76,26 @@ final class FakeLiveMailService extends LiveMailService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Every message of the mailbox in UID order; filter / sort / range are not evaluated.
|
||||
*/
|
||||
public function messageList(string $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null): Generator
|
||||
{
|
||||
$this->calls[] = ['messageList', [$collection]];
|
||||
$uids = array_keys($this->flags);
|
||||
sort($uids);
|
||||
yield from $this->messageFetch($collection, null, ...$uids);
|
||||
}
|
||||
|
||||
/** @var int[] UIDs entityFind() returns */
|
||||
public array $found = [];
|
||||
|
||||
public function entityFind(string $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null): array
|
||||
{
|
||||
$this->calls[] = ['entityFind', [$collection, $filter]];
|
||||
return $this->found;
|
||||
}
|
||||
|
||||
public function entityPatch(string $collection, array $flagsToAdd = [], array $flagsToRemove = [], int ...$uids): void
|
||||
{
|
||||
$this->calls[] = ['entityPatch', [$collection, $flagsToAdd, $flagsToRemove, $uids]];
|
||||
|
||||
@@ -19,6 +19,11 @@ final class FakeMessageFileStore extends MessageFileStore
|
||||
$this->files[$uidValidity][$uid] = $content;
|
||||
}
|
||||
|
||||
public function read(string $tenantId, string $serviceId, string $mailbox, int $uidValidity, int $uid): ?array
|
||||
{
|
||||
return $this->files[$uidValidity][$uid] ?? null;
|
||||
}
|
||||
|
||||
public function delete(string $tenantId, string $serviceId, string $mailbox, int $uidValidity, int ...$uids): void
|
||||
{
|
||||
foreach ($uids as $uid) {
|
||||
|
||||
@@ -20,6 +20,7 @@ final class FakeMessageStore extends MessageStore
|
||||
$meta = $entity->toCacheMeta();
|
||||
$existing = $this->documents[$uidValidity][$meta['uid']] ?? null;
|
||||
$this->documents[$uidValidity][$meta['uid']] = [
|
||||
'meta' => $meta,
|
||||
'flags' => $meta['flags'],
|
||||
'addedSeq' => $existing['addedSeq'] ?? $seq,
|
||||
'modSeq' => $seq,
|
||||
@@ -28,6 +29,30 @@ final class FakeMessageStore extends MessageStore
|
||||
ksort($this->documents[$uidValidity]);
|
||||
}
|
||||
|
||||
/** Last query() arguments, for assertions */
|
||||
public ?array $lastQuery = null;
|
||||
|
||||
/**
|
||||
* Live UIDs in ascending order; the filter / sort translation is covered by MessageQueryBuilderTest.
|
||||
*/
|
||||
public function query(string $serviceId, string $mailbox, int $uidValidity, array $filter = [], array $sort = ['uid' => 1], ?array $collation = null): array
|
||||
{
|
||||
$this->lastQuery = [$filter, $sort, $collation];
|
||||
return array_keys($this->flags($serviceId, $mailbox, $uidValidity));
|
||||
}
|
||||
|
||||
public function fetchMany(string $serviceId, string $mailbox, int $uidValidity, int ...$uids): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($uids as $uid) {
|
||||
$document = $this->documents[$uidValidity][$uid] ?? null;
|
||||
if ($document !== null && $document['removedSeq'] === null) {
|
||||
$list[$uid] = [...$document['meta'], 'uid' => $uid, 'flags' => $document['flags']];
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function flags(string $serviceId, string $mailbox, int $uidValidity): array
|
||||
{
|
||||
$flags = [];
|
||||
|
||||
Reference in New Issue
Block a user