generated from Nodarx/template
fix: Mailbox::fromStatus() so omitted fields preserve known values
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -26,13 +26,15 @@ final class Mailbox
|
|||||||
|
|
||||||
public function fromStatus(MailboxStatusResult $status): self
|
public function fromStatus(MailboxStatusResult $status): self
|
||||||
{
|
{
|
||||||
|
$items = $status->items();
|
||||||
|
|
||||||
return new self(
|
return new self(
|
||||||
$this->name,
|
$this->name,
|
||||||
$this->delimiter,
|
$this->delimiter,
|
||||||
$this->attributes,
|
$this->attributes,
|
||||||
$status->messages() ?? $this->messages,
|
$items['MESSAGES'] ?? $this->messages,
|
||||||
$status->unseen() ?? $this->unread,
|
$items['UNSEEN'] ?? $this->unread,
|
||||||
$status->uidValidity() ?? $this->uidValidity,
|
$items['UIDVALIDITY'] ?? $this->uidValidity,
|
||||||
$this->recent,
|
$this->recent,
|
||||||
$this->flags,
|
$this->flags,
|
||||||
$this->readOnly,
|
$this->readOnly,
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace KTXT\ProviderImap\Tests\Unit;
|
||||||
|
|
||||||
|
use KTXM\ProviderImap\Client\Mailbox;
|
||||||
|
use KTXM\ProviderImap\Client\Result\MailboxStatusResult;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class MailboxTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testPartialStatusPreservesUnreportedValues(): void
|
||||||
|
{
|
||||||
|
$mailbox = new Mailbox('INBOX', '/', [], 12, 4, 123);
|
||||||
|
|
||||||
|
$updated = $mailbox->fromStatus(new MailboxStatusResult('INBOX', ['UNSEEN' => 2]));
|
||||||
|
|
||||||
|
$this->assertSame(12, $updated->messages());
|
||||||
|
$this->assertSame(2, $updated->unread());
|
||||||
|
$this->assertSame(123, $updated->uidValidity());
|
||||||
|
$this->assertSame(4, $mailbox->unread());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExplicitZeroCountsReplaceKnownCounts(): void
|
||||||
|
{
|
||||||
|
$mailbox = new Mailbox('INBOX', '/', [], 12, 4, 123);
|
||||||
|
|
||||||
|
$updated = $mailbox->fromStatus(new MailboxStatusResult('INBOX', [
|
||||||
|
'MESSAGES' => 0,
|
||||||
|
'UNSEEN' => 0,
|
||||||
|
'UIDVALIDITY' => 456,
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertSame(0, $updated->messages());
|
||||||
|
$this->assertSame(0, $updated->unread());
|
||||||
|
$this->assertSame(456, $updated->uidValidity());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEmptyStatusPreservesMailboxIncludingUnknownUidValidity(): void
|
||||||
|
{
|
||||||
|
foreach ([null, 123] as $uidValidity) {
|
||||||
|
$mailbox = new Mailbox('INBOX', '/', ['\\HasNoChildren'], 12, 4, $uidValidity, 2, ['\\Seen'], false);
|
||||||
|
|
||||||
|
$updated = $mailbox->fromStatus(new MailboxStatusResult('INBOX', []));
|
||||||
|
|
||||||
|
$this->assertEquals($mailbox, $updated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user