CluPilotCloud/app/Services/Mail/FakeMailbox.php

38 lines
937 B
PHP

<?php
namespace App\Services\Mail;
/**
* A mailbox that answers with whatever a test put in it.
*
* The socket half of ImapMailbox cannot be exercised without a mail server, and
* a test that needs one is a test nobody runs. What CAN be exercised — and is,
* in tests/Feature/Admin/InboundMailTest.php — is the parsing (MailParser
* against real raw messages) and everything the ingest decides afterwards.
*/
class FakeMailbox implements InboundMailbox
{
public bool $configured = true;
/** @var array<int, FetchedMail> */
public array $mails = [];
/** @var array<int, string> */
public array $seen = [];
public function isConfigured(): bool
{
return $this->configured;
}
public function fetch(int $limit = 50): array
{
return array_slice($this->mails, 0, $limit);
}
public function markSeen(string $uid): void
{
$this->seen[] = $uid;
}
}