generated from Nodarx/template
refactor: split service into ServiceBase and LiveService
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -6,7 +6,9 @@ namespace KTXT\ProviderImap\Tests\Unit;
|
||||
|
||||
use KTXM\ProviderImap\Client\{Client, ConnectionConfig};
|
||||
use KTXM\ProviderImap\Client\Transport\{ConnectionInterface, ConnectionFactoryInterface};
|
||||
use KTXM\ProviderImap\Providers\Service;
|
||||
use KTXM\ProviderImap\Providers\CollectionResource;
|
||||
use KTXM\ProviderImap\Providers\ServiceBase;
|
||||
use KTXM\ProviderImap\Providers\LiveService;
|
||||
use KTXM\ProviderImap\Service\Live\LiveMailService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -16,7 +18,7 @@ final class CollectionFetchTest extends TestCase
|
||||
|
||||
public function testWithListStatusUsesOneRoundTrip(): void
|
||||
{
|
||||
$mailbox = $this->service(listStatus: true)->collectionFetch('INBOX');
|
||||
$mailbox = $this->service(listStatus: true)->mailboxFetch('INBOX');
|
||||
|
||||
$this->assertCount(1, $this->commands);
|
||||
$this->assertStringContainsString('RETURN (STATUS', $this->commands[0]);
|
||||
@@ -27,7 +29,7 @@ final class CollectionFetchTest extends TestCase
|
||||
|
||||
public function testWithoutListStatusFallsBackToStatus(): void
|
||||
{
|
||||
$mailbox = $this->service(listStatus: false)->collectionFetch('INBOX');
|
||||
$mailbox = $this->service(listStatus: false)->mailboxFetch('INBOX');
|
||||
|
||||
$this->assertCount(2, $this->commands);
|
||||
$this->assertStringNotContainsString('RETURN', $this->commands[0]);
|
||||
@@ -39,7 +41,36 @@ final class CollectionFetchTest extends TestCase
|
||||
|
||||
public function testUnknownMailboxIsNull(): void
|
||||
{
|
||||
$this->assertNull($this->service(listStatus: false, exists: false)->collectionFetch('Missing'));
|
||||
$this->assertNull($this->service(listStatus: false, exists: false)->mailboxFetch('Missing'));
|
||||
}
|
||||
|
||||
public function testCollectionsAreResourcesKeyedByName(): void
|
||||
{
|
||||
$service = $this->service(listStatus: true);
|
||||
|
||||
$list = $service->collectionList();
|
||||
$collection = $service->collectionFetch('INBOX');
|
||||
|
||||
$this->assertSame(['INBOX'], array_keys($list));
|
||||
$this->assertInstanceOf(CollectionResource::class, $list['INBOX']);
|
||||
$this->assertInstanceOf(CollectionResource::class, $collection);
|
||||
$this->assertSame('INBOX', $collection?->identifier());
|
||||
$this->assertNull($this->service(listStatus: true, exists: false)->collectionFetch('Missing'));
|
||||
}
|
||||
|
||||
public function testDelimiterIsReadWithoutListingMailboxes(): void
|
||||
{
|
||||
$this->assertSame('/', $this->service(listStatus: false)->collectionDelimiter());
|
||||
$this->assertSame(['LIST "" ""'], $this->commands);
|
||||
}
|
||||
|
||||
public function testCollectionExtantReportsMissingMailboxes(): void
|
||||
{
|
||||
$service = new LiveService();
|
||||
$live = $this->service(listStatus: true, exists: false);
|
||||
(new \ReflectionProperty(LiveService::class, 'mailService'))->setValue($service, $live);
|
||||
|
||||
$this->assertSame(['Missing' => false], $service->collectionExtant('Missing'));
|
||||
}
|
||||
|
||||
private function service(bool $listStatus, bool $exists = true): LiveMailService
|
||||
@@ -57,6 +88,11 @@ final class CollectionFetchTest extends TestCase
|
||||
} else {
|
||||
$this->commands[] = $command;
|
||||
}
|
||||
if ($operation === 'LIST' && $command === 'LIST "" ""') {
|
||||
$lines[] = "* LIST (\\Noselect) \"/\" \"\"\r\n";
|
||||
$lines[] = "$tag OK Completed\r\n";
|
||||
return;
|
||||
}
|
||||
if ($operation === 'LIST') {
|
||||
if (!$listStatus && str_contains($command, 'RETURN')) {
|
||||
$lines[] = "$tag BAD Unknown RETURN option\r\n";
|
||||
@@ -80,8 +116,8 @@ final class CollectionFetchTest extends TestCase
|
||||
$client = new Client($factory);
|
||||
$client->connect(new ConnectionConfig('localhost'));
|
||||
|
||||
return new class($this->createStub(Service::class), $client) extends LiveMailService {
|
||||
public function __construct(Service $service, private readonly Client $client)
|
||||
return new class($this->createStub(ServiceBase::class), $client) extends LiveMailService {
|
||||
public function __construct(ServiceBase $service, private readonly Client $client)
|
||||
{
|
||||
parent::__construct($service);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user