Skip to content

Commit

Permalink
test: fix redis not being used properly in imapClientFactoryTest
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
st3iny committed Aug 30, 2024
1 parent 44c5315 commit e48e41b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/Integration/IMAP/IMAPClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
use Horde_Imap_Client_Socket;
use OC\Memcache\Redis;
use OCA\Mail\Account;
use OCA\Mail\Cache\CacheFactory;
use OCA\Mail\Db\MailAccount;
use OCA\Mail\IMAP\HordeImapClient;
use OCA\Mail\IMAP\IMAPClientFactory;
use OCA\Mail\Tests\Integration\Framework\Caching;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ICacheFactory;
Expand All @@ -40,6 +42,7 @@ class IMAPClientFactoryTest extends TestCase {
private $factory;
private IEventDispatcher|MockObject $eventDispatcher;
private ITimeFactory|MockObject $timeFactory;
private CacheFactory|MockObject $hordeCacheFactory;

protected function setUp(): void {
parent::setUp();
Expand All @@ -49,13 +52,15 @@ protected function setUp(): void {
$this->cacheFactory = Server::get(ICacheFactory::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->hordeCacheFactory = $this->createMock(CacheFactory::class);

$this->factory = new IMAPClientFactory(
$this->crypto,
$this->config,
$this->cacheFactory,
$this->eventDispatcher,
$this->timeFactory,
$this->hordeCacheFactory,
);
}

Expand Down Expand Up @@ -106,13 +111,21 @@ public function testRateLimiting(): void {
if (ltrim($cacheClass, '\\') !== Redis::class) {
$this->markTestSkipped('Redis not available. Found ' . $cacheClass);
}

[$imapClientFactory, $cacheFactory] = Caching::getImapClientFactoryAndConfiguredCacheFactory($this->crypto);
$this->assertInstanceOf(
Redis::class,
$cacheFactory->createDistributed(),
'Distributed cache is not Redis',
);

$account = $this->getTestAccount();
$this->crypto->expects($this->once())
->method('decrypt')
->with('encrypted')
->willReturn('notmypassword');

$client = $this->factory->getClient($account);
$client = $imapClientFactory->getClient($account);
self::assertInstanceOf(HordeImapClient::class, $client);
foreach ([1, 2, 3] as $attempts) {
try {
Expand Down

0 comments on commit e48e41b

Please sign in to comment.