From d9c84f91fa609fc025bc37279e9a5184160c1d82 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Wed, 21 Aug 2024 14:18:22 +0200 Subject: [PATCH] test: fix redis not being used properly in imapClientFactoryTest Signed-off-by: Richard Steinmetz --- tests/Integration/Framework/Caching.php | 50 +++++++++++++++++++ .../IMAP/IMAPClientFactoryTest.php | 11 +++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/Framework/Caching.php diff --git a/tests/Integration/Framework/Caching.php b/tests/Integration/Framework/Caching.php new file mode 100644 index 0000000000..73dbea2b42 --- /dev/null +++ b/tests/Integration/Framework/Caching.php @@ -0,0 +1,50 @@ + 'mail-integration-tests', + Server::get(LoggerInterface::class), + Server::get(IProfiler::class), + $config->getSystemValue('memcache.local', null), + $config->getSystemValue('memcache.distributed', null), + $config->getSystemValue('memcache.locking', null), + $config->getSystemValueString('redis_log_file') + ); + $imapClient = new IMAPClientFactory( + $crypto ?? Server::get(ICrypto::class), + $config, + $cacheFactory, + Server::get(IEventDispatcher::class), + Server::get(ITimeFactory::class), + Server::get(HordeCacheFactory::class), + ); + return [$imapClient, $cacheFactory]; + } +} diff --git a/tests/Integration/IMAP/IMAPClientFactoryTest.php b/tests/Integration/IMAP/IMAPClientFactoryTest.php index e62f656035..63ba13d9f0 100644 --- a/tests/Integration/IMAP/IMAPClientFactoryTest.php +++ b/tests/Integration/IMAP/IMAPClientFactoryTest.php @@ -18,6 +18,7 @@ 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; @@ -110,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 {