diff --git a/tests/AddressListTest.php b/tests/AddressListTest.php index d1e2e83363..aebdde934e 100644 --- a/tests/AddressListTest.php +++ b/tests/AddressListTest.php @@ -1,5 +1,7 @@ assertEquals($expected, $json); } - public function testParseSingleAddress() { + public function testParseSingleAddress(): void { $source = 'a@b.c'; $expected = new AddressList([ Address::fromRaw('a@b.c', 'a@b.c'), @@ -48,7 +50,7 @@ public function testParseSingleAddress() { $this->assertEquals($expected, $list); } - public function testFromHordeList() { + public function testFromHordeList(): void { $hordeList = new Horde_Mail_Rfc822_List([ new Horde_Mail_Rfc822_Address(), new Horde_Mail_Rfc822_Group(), @@ -59,7 +61,7 @@ public function testFromHordeList() { $this->assertCount(1, $list); } - public function testToHorde() { + public function testToHorde(): void { $list = new AddressList([ Address::fromRaw('A', 'a@domain.tld'), Address::fromRaw('B', 'b@domain.tld'), @@ -78,7 +80,7 @@ public function testToHorde() { $this->assertEquals($expected, $hordeList); } - public function testFromAndToHorde() { + public function testFromAndToHorde(): void { $add1 = new Horde_Mail_Rfc822_Address('a@domain.tld'); $add1->personal = 'A'; $add2 = new Horde_Mail_Rfc822_Address('b@domain.tld'); @@ -98,7 +100,7 @@ public function testFromAndToHorde() { $this->assertEquals($expected, $hordeList); } - public function testMergeIdentical() { + public function testMergeIdentical(): void { $a = new AddressList([ Address::fromRaw('A', 'a@b.c'), ]); @@ -111,7 +113,7 @@ public function testMergeIdentical() { $this->assertCount(1, $c); } - public function testMergeNonIdentical() { + public function testMergeNonIdentical(): void { $a = new AddressList([ Address::fromRaw('A', 'a@b.c'), ]); @@ -126,7 +128,7 @@ public function testMergeNonIdentical() { $this->assertCount(2, $c); } - public function testMergeMixed() { + public function testMergeMixed(): void { $a = new AddressList([ Address::fromRaw('A', 'a@b.c'), Address::fromRaw('B', 'b@b.c'), @@ -140,7 +142,7 @@ public function testMergeMixed() { $this->assertCount(2, $c); } - public function testMergeEmpty() { + public function testMergeEmpty(): void { $a = new AddressList([ Address::fromRaw('A', 'a@b.c'), Address::fromRaw('B', 'b@b.c'), @@ -152,7 +154,7 @@ public function testMergeEmpty() { $this->assertCount(2, $c); } - public function testMergeToEmpty() { + public function testMergeToEmpty(): void { $a = new AddressList([ ]); $b = new AddressList([ diff --git a/tests/AddressTest.php b/tests/AddressTest.php index 6c24380d68..dc6548f8ab 100644 --- a/tests/AddressTest.php +++ b/tests/AddressTest.php @@ -1,5 +1,7 @@ assertEquals($expected, $json); } - public function testToHorde() { + public function testToHorde(): void { $address = Address::fromRaw('Christoph Wurst', 'christoph@domain.tld'); $expected = new Horde_Mail_Rfc822_Address('christoph@domain.tld'); $expected->personal = 'Christoph Wurst'; @@ -34,7 +36,7 @@ public function testToHorde() { $this->assertEquals($expected, $horde); } - public function testEqualsIdentical() { + public function testEqualsIdentical(): void { $address = Address::fromRaw('Christoph Wurst', 'christoph@domain.tld'); $equals = $address->equals($address); @@ -42,7 +44,7 @@ public function testEqualsIdentical() { $this->assertTrue($equals); } - public function testEquals() { + public function testEquals(): void { $address1 = Address::fromRaw('Christoph Wurst', 'christoph@domain1.tld'); $address2 = Address::fromRaw('Christoph Wurst', 'christoph@domain1.tld'); @@ -51,7 +53,7 @@ public function testEquals() { $this->assertTrue($equals); } - public function testDoesNotEqual() { + public function testDoesNotEqual(): void { $address1 = Address::fromRaw('Christoph Wurst', 'christoph@domain1.tld'); $address2 = Address::fromRaw('Christoph Wurst', 'christoph@domain2.tld'); @@ -60,7 +62,7 @@ public function testDoesNotEqual() { $this->assertFalse($equals); } - public function testDoesNotEqualBecauseDifferentLabel() { + public function testDoesNotEqualBecauseDifferentLabel(): void { $address1 = Address::fromRaw('Christoph Wurst', 'christoph@domain.tld'); $address2 = Address::fromRaw('Wurst Christoph', 'christoph@domain.tld'); diff --git a/tests/FolderTest.php b/tests/FolderTest.php index 7492c24058..8aa530c83a 100644 --- a/tests/FolderTest.php +++ b/tests/FolderTest.php @@ -1,5 +1,7 @@ folder = new Folder($this->accountId, $this->mailbox, $attributes, $delimiter, []); } - public function testGetMailbox() { + public function testGetMailbox(): void { $this->mockFolder(); $this->mailbox->expects($this->once()) ->method('__get') @@ -39,7 +41,7 @@ public function testGetMailbox() { $this->assertSame('Sent', $this->folder->getMailbox()); } - public function testGetDelimiter() { + public function testGetDelimiter(): void { $this->mockFolder([], ','); $this->assertSame(',', $this->folder->getDelimiter()); @@ -51,13 +53,13 @@ public function testGetDelimiterNull(): void { $this->assertNull($this->folder->getDelimiter()); } - public function testGetAttributes() { + public function testGetAttributes(): void { $this->mockFolder(['\noselect']); $this->assertSame(['\noselect'], $this->folder->getAttributes()); } - public function testSetStatus() { + public function testSetStatus(): void { $this->mockFolder(); $this->folder->setStatus([ @@ -67,7 +69,7 @@ public function testSetStatus() { $this->addToAssertionCount(1); } - public function testSpecialUse() { + public function testSpecialUse(): void { $this->mockFolder(); $this->folder->addSpecialUse('flagged'); diff --git a/tests/HordeTranslationHandlerTest.php b/tests/HordeTranslationHandlerTest.php index be1516b7a8..dd59ccd4ce 100644 --- a/tests/HordeTranslationHandlerTest.php +++ b/tests/HordeTranslationHandlerTest.php @@ -1,5 +1,7 @@ handler = new HordeTranslationHandler(); } - public function testT() { + public function testT(): void { $message = 'Hello'; $expected = $message; @@ -28,18 +30,16 @@ public function testT() { $this->assertEquals($expected, $actual); } - public function singularPluralDataProvider() { - return [ - [0], - [1], - [2], - ]; + public function singularPluralDataProvider(): \Iterator { + yield [0]; + yield [1]; + yield [2]; } /** * @dataProvider singularPluralDataProvider */ - public function testNgettext($number) { + public function testNgettext($number): void { $singular = 'mail'; $plural = 'mails'; diff --git a/tests/Integration/Connector/ImapMailboxConnectorTest.php b/tests/Integration/Connector/ImapMailboxConnectorTest.php index 835eb27add..b37fdbace9 100644 --- a/tests/Integration/Connector/ImapMailboxConnectorTest.php +++ b/tests/Integration/Connector/ImapMailboxConnectorTest.php @@ -16,7 +16,7 @@ use OCA\Mail\Tests\Integration\Framework\ImapTestAccount; use OCP\Server; -class ImapMailboxConnectorTest extends AbstractMailboxConnectorTest { +final class ImapMailboxConnectorTest extends AbstractMailboxConnectorTest { use ImapTest; use ImapTestAccount; diff --git a/tests/Integration/Connector/JmapMailboxConnectorTest.php b/tests/Integration/Connector/JmapMailboxConnectorTest.php index 165270541c..9ee75e1651 100644 --- a/tests/Integration/Connector/JmapMailboxConnectorTest.php +++ b/tests/Integration/Connector/JmapMailboxConnectorTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Tests\Integration\Framework\JmapTestAccount; use OCP\Server; -class JmapMailboxConnectorTest extends AbstractMailboxConnectorTest { +final class JmapMailboxConnectorTest extends AbstractMailboxConnectorTest { use JmapTestAccount; protected function createConnector(): IMailboxConnector { diff --git a/tests/Integration/Connector/JmapMessageConnectorTest.php b/tests/Integration/Connector/JmapMessageConnectorTest.php index 2911799fdf..fd41648869 100644 --- a/tests/Integration/Connector/JmapMessageConnectorTest.php +++ b/tests/Integration/Connector/JmapMessageConnectorTest.php @@ -22,7 +22,7 @@ use OCP\Server; use Psr\Log\NullLogger; -class JmapMessageConnectorTest extends TestCase { +final class JmapMessageConnectorTest extends TestCase { use DatabaseTransaction; use JmapTestAccount; diff --git a/tests/Integration/Db/AliasMapperTest.php b/tests/Integration/Db/AliasMapperTest.php index 7781639d63..4a87884a01 100644 --- a/tests/Integration/Db/AliasMapperTest.php +++ b/tests/Integration/Db/AliasMapperTest.php @@ -21,7 +21,7 @@ /** * @group DB */ -class AliasMapperTest extends TestCase { +final class AliasMapperTest extends TestCase { use DatabaseTransaction; /** @var AliasMapper */ @@ -42,7 +42,7 @@ public function setup(): void { $this->mapper = new AliasMapper($this->db); } - public function testFind() { + public function testFind(): void { $accountMapper = new MailAccountMapper($this->db); $account = new MailAccount(); $account->setName('Peter Parker'); @@ -86,7 +86,7 @@ public function testFind() { ); } - public function testCountByAccountId() { + public function testCountByAccountId(): void { $account = $this->insertAccount(); self::assertSame(0, $this->mapper->countByAccountId($account->getId(), $account->getUserId())); @@ -102,7 +102,7 @@ public function testCountByAccountId() { self::assertSame(2, $this->mapper->countByAccountId($account->getId(), $account->getUserId())); } - public function testCountByAccountIdIgnoresOtherUsers() { + public function testCountByAccountIdIgnoresOtherUsers(): void { $account = $this->insertAccount(); $alias = new Alias(); @@ -156,7 +156,7 @@ private function insertAccount(string $userId = 'user12345'): MailAccount { return (new MailAccountMapper($this->db))->insert($account); } - public function testDeleteProvisionedAliasesByUid() { + public function testDeleteProvisionedAliasesByUid(): void { $accountMapper = new MailAccountMapper($this->db); // Create first account with provisioning_id diff --git a/tests/Integration/Db/CollectedAddressMapperTest.php b/tests/Integration/Db/CollectedAddressMapperTest.php index 35ede56dfc..9a7f7171e2 100644 --- a/tests/Integration/Db/CollectedAddressMapperTest.php +++ b/tests/Integration/Db/CollectedAddressMapperTest.php @@ -1,5 +1,7 @@ address3 = $this->mapper->insert($this->address3); } - public function matchingData(): array { - return [ - ['user1@example.com', ['user1@example.com']], - ['examp', ['user1@example.com', 'user2@example.com']], - ]; + public function matchingData(): \Iterator { + yield ['user1@example.com', ['user1@example.com']]; + yield ['examp', ['user1@example.com', 'user2@example.com']]; } /** * @dataProvider matchingData */ - public function testFindMatching($query, $result) { + public function testFindMatching($query, $result): void { $matches = $this->mapper->findMatching($this->userId, $query); $this->assertCount(\count($result), $matches); @@ -91,11 +91,9 @@ public function testFindMatching($query, $result) { } } - public function insertIfNewData(): array { - return [ - ['user1@example.com', false], - ['user3@example.com', true], - ]; + public function insertIfNewData(): \Iterator { + yield ['user1@example.com', false]; + yield ['user3@example.com', true]; } /** @@ -107,19 +105,19 @@ public function testExists($email, $expected): void { $this->assertSame($expected, $actual); } - public function testGetTotal() { + public function testGetTotal(): void { $total = $this->mapper->getTotal(); $this->assertSame(3, $total); } - public function testGetChunk() { + public function testGetChunk(): void { $chunk = $this->mapper->getChunk(); $this->assertCount(3, $chunk); } - public function testGetChunkWithOffset() { + public function testGetChunkWithOffset(): void { $chunk = $this->mapper->getChunk($this->address2->getId()); $this->assertCount(2, $chunk); diff --git a/tests/Integration/Db/DelegationMapperTest.php b/tests/Integration/Db/DelegationMapperTest.php index a49bb4cf15..715bc53495 100644 --- a/tests/Integration/Db/DelegationMapperTest.php +++ b/tests/Integration/Db/DelegationMapperTest.php @@ -23,7 +23,7 @@ * @group DB * @covers \OCA\Mail\Db\DelegationMapper */ -class DelegationMapperTest extends TestCase { +final class DelegationMapperTest extends TestCase { use DatabaseTransaction; private IDBConnection $db; diff --git a/tests/Integration/Db/InternalAddressMapperTest.php b/tests/Integration/Db/InternalAddressMapperTest.php index 469167eac6..7c3a121f5e 100644 --- a/tests/Integration/Db/InternalAddressMapperTest.php +++ b/tests/Integration/Db/InternalAddressMapperTest.php @@ -18,7 +18,7 @@ use OCP\IUser; use OCP\Server; -class InternalAddressMapperTest extends TestCase { +final class InternalAddressMapperTest extends TestCase { use DatabaseTransaction, TestUser; /** @var IDBConnection */ diff --git a/tests/Integration/Db/LocalAttachmentMapperTest.php b/tests/Integration/Db/LocalAttachmentMapperTest.php index 2efc5f7b99..655fbffe80 100644 --- a/tests/Integration/Db/LocalAttachmentMapperTest.php +++ b/tests/Integration/Db/LocalAttachmentMapperTest.php @@ -22,7 +22,7 @@ use OCP\IDBConnection; use PHPUnit\Framework\MockObject\MockObject; -class LocalAttachmentMapperTest extends TestCase { +final class LocalAttachmentMapperTest extends TestCase { use DatabaseTransaction; /** @var IDBConnection */ diff --git a/tests/Integration/Db/LocalMessageMapperTest.php b/tests/Integration/Db/LocalMessageMapperTest.php index 37ad20396c..745477cd85 100644 --- a/tests/Integration/Db/LocalMessageMapperTest.php +++ b/tests/Integration/Db/LocalMessageMapperTest.php @@ -23,7 +23,7 @@ use OCP\IDBConnection; use PHPUnit\Framework\MockObject\MockObject; -class LocalMessageMapperTest extends TestCase { +final class LocalMessageMapperTest extends TestCase { use DatabaseTransaction; use ImapTestAccount; diff --git a/tests/Integration/Db/LocalMessageTest.php b/tests/Integration/Db/LocalMessageTest.php index 54a6cb709e..76b4e533ef 100644 --- a/tests/Integration/Db/LocalMessageTest.php +++ b/tests/Integration/Db/LocalMessageTest.php @@ -14,7 +14,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use PHPUnit\Framework\MockObject\MockObject; -class LocalMessageTest extends TestCase { +final class LocalMessageTest extends TestCase { /** @var ITimeFactory|MockObject */ private $timeFactory; diff --git a/tests/Integration/Db/MailAccountMapperTest.php b/tests/Integration/Db/MailAccountMapperTest.php index 5bbe0c8d69..70c9d6313d 100644 --- a/tests/Integration/Db/MailAccountMapperTest.php +++ b/tests/Integration/Db/MailAccountMapperTest.php @@ -22,7 +22,7 @@ * @group DB * @covers \OCA\Mail\Db\MailAccountMapper */ -class MailAccountMapperTest extends TestCase { +final class MailAccountMapperTest extends TestCase { use DatabaseTransaction; /** @var MailAccountMapper */ @@ -61,7 +61,7 @@ public function setup(): void { $this->account->setOrder(27); } - public function testFind() { + public function testFind(): void { /** @var MailAccount $b */ $b = $this->mapper->insert($this->account); @@ -77,7 +77,7 @@ public function testFind() { $this->assertEquals($b->toJson(), $c->toJson()); } - public function testSave() { + public function testSave(): void { $a = $this->account; // test insert diff --git a/tests/Integration/Db/MailAccountTest.php b/tests/Integration/Db/MailAccountTest.php index 75aa24dac4..e43cc945d4 100644 --- a/tests/Integration/Db/MailAccountTest.php +++ b/tests/Integration/Db/MailAccountTest.php @@ -13,8 +13,8 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\MailAccount; -class MailAccountTest extends TestCase { - public function testToAPI() { +final class MailAccountTest extends TestCase { + public function testToAPI(): void { $a = new MailAccount(); $a->setId(3); $a->setName('Peter Parker'); @@ -81,7 +81,7 @@ public function testToAPI() { ], $a->toJson()); } - public function testMailAccountConstruct() { + public function testMailAccountConstruct(): void { $expected = [ 'id' => 12345, 'accountId' => 12345, diff --git a/tests/Integration/Db/MailboxMapperTest.php b/tests/Integration/Db/MailboxMapperTest.php index 0c438b0159..f89fbc7a70 100644 --- a/tests/Integration/Db/MailboxMapperTest.php +++ b/tests/Integration/Db/MailboxMapperTest.php @@ -19,7 +19,7 @@ use OCP\IDBConnection; use PHPUnit\Framework\MockObject\MockObject; -class MailboxMapperTest extends TestCase { +final class MailboxMapperTest extends TestCase { use DatabaseTransaction; /** @var IDBConnection */ @@ -47,7 +47,7 @@ protected function setUp(): void { $delete->executeStatement(); } - public function testFindAllNoData() { + public function testFindAllNoData(): void { $account = $this->createMock(Account::class); $account->method('getId')->willReturn(13); @@ -56,7 +56,7 @@ public function testFindAllNoData() { $this->assertEmpty($result); } - public function testFindAll() { + public function testFindAll(): void { $account = $this->createMock(Account::class); $account->method('getId')->willReturn(13); foreach (range(1, 10) as $i) { @@ -82,7 +82,7 @@ public function testFindAll() { $this->assertCount(5, $result); } - public function testCountByAccountNoData() { + public function testCountByAccountNoData(): void { $account = $this->createMock(Account::class); $account->method('getId')->willReturn(13); @@ -91,7 +91,7 @@ public function testCountByAccountNoData() { $this->assertSame(0, $count); } - public function testCountByAccountOnlyCountsItsOwnAccount() { + public function testCountByAccountOnlyCountsItsOwnAccount(): void { $account = $this->createMock(Account::class); $account->method('getId')->willReturn(13); foreach (range(1, 10) as $i) { @@ -114,7 +114,7 @@ public function testCountByAccountOnlyCountsItsOwnAccount() { $this->assertSame(5, $count); } - public function testNoInboxFound() { + public function testNoInboxFound(): void { /** @var Account|MockObject $account */ $account = $this->createMock(Account::class); $account->method('getId')->willReturn(13); @@ -123,7 +123,7 @@ public function testNoInboxFound() { $this->mapper->find($account, 'INBOX'); } - public function testFindInbox() { + public function testFindInbox(): void { /** @var Account|MockObject $account */ $account = $this->createMock(Account::class); $account->method('getId')->willReturn(13); @@ -148,7 +148,7 @@ public function testFindInbox() { $this->assertSame('INBOX', $result->getName()); } - public function testMailboxesWithTrailingSpace() { + public function testMailboxesWithTrailingSpace(): void { /** @var Account|MockObject $account */ $account = $this->createMock(Account::class); $account->method('getId')->willReturn(13); diff --git a/tests/Integration/Db/MessageMapperTest.php b/tests/Integration/Db/MessageMapperTest.php index f65d2ef103..76e04c4e4b 100644 --- a/tests/Integration/Db/MessageMapperTest.php +++ b/tests/Integration/Db/MessageMapperTest.php @@ -30,7 +30,7 @@ use function range; use function time; -class MessageMapperTest extends TestCase { +final class MessageMapperTest extends TestCase { use DatabaseTransaction; /** A user that has no mail accounts on a development instance */ diff --git a/tests/Integration/Db/ProvisioningMapperTest.php b/tests/Integration/Db/ProvisioningMapperTest.php index 8aee3e3f2a..2266dd54cd 100644 --- a/tests/Integration/Db/ProvisioningMapperTest.php +++ b/tests/Integration/Db/ProvisioningMapperTest.php @@ -20,7 +20,7 @@ /** * @group DB */ -class ProvisioningMapperTest extends TestCase { +final class ProvisioningMapperTest extends TestCase { use DatabaseTransaction; /** @var ProvisioningMapper */ @@ -60,7 +60,7 @@ public function setup(): void { $this->data['sieveEnabled'] = false; } - public function testValidate() { + public function testValidate(): void { $provisioning = new Provisioning(); $provisioning->setId(1); $provisioning->setProvisioningDomain($this->data['provisioningDomain']); @@ -89,7 +89,7 @@ public function testValidate() { } } - public function testValidateException() { + public function testValidateException(): void { $data = []; $data['provisioningDomain'] = 'heart-of-gold.com' ; @@ -98,7 +98,7 @@ public function testValidateException() { $provisioning = $this->mapper->validate($data); } - public function testValidateRejectsMalformedLdapPlaceholder() { + public function testValidateRejectsMalformedLdapPlaceholder(): void { $data = $this->data; $data['emailTemplate'] = '%ldap:uid%@heart-of-gold.com'; @@ -107,7 +107,7 @@ public function testValidateRejectsMalformedLdapPlaceholder() { $this->mapper->validate($data); } - public function testValidateAcceptsLdapPlaceholder() { + public function testValidateAcceptsLdapPlaceholder(): void { $data = $this->data; $data['emailTemplate'] = '%LDAP:sAMAccountName%@heart-of-gold.com'; @@ -116,7 +116,7 @@ public function testValidateAcceptsLdapPlaceholder() { $this->assertSame('%LDAP:sAMAccountName%@heart-of-gold.com', $provisioning->getEmailTemplate()); } - public function testGetNoResult() { + public function testGetNoResult(): void { $db = $this->mapper->get(99999); $this->assertNull($db); } @@ -124,7 +124,7 @@ public function testGetNoResult() { /** * @return void */ - public function testUpdate() { + public function testUpdate(): void { $provisioning = new Provisioning(); $provisioning->setProvisioningDomain('somebody-elses-problem.com'); $provisioning->setEmailTemplate($this->data['emailTemplate']); @@ -148,7 +148,7 @@ public function testUpdate() { $this->assertEquals('arthur-dent.com', $update->getProvisioningDomain()); } - public function testGetAll() { + public function testGetAll(): void { $provisioning = new Provisioning(); $provisioning->setProvisioningDomain($this->data['provisioningDomain']); $provisioning->setEmailTemplate($this->data['emailTemplate']); @@ -170,7 +170,7 @@ public function testGetAll() { $this->assertContainsOnlyInstancesOf(Provisioning::class, $results); } - public function testGet() { + public function testGet(): void { $provisioning = new Provisioning(); $provisioning->setProvisioningDomain($this->data['provisioningDomain']); $provisioning->setEmailTemplate($this->data['emailTemplate']); @@ -198,7 +198,7 @@ public function testGet() { } } - public function testFindUniqueImapHosts() { + public function testFindUniqueImapHosts(): void { $provisioning = new Provisioning(); $provisioning->setProvisioningDomain($this->data['provisioningDomain']); $provisioning->setEmailTemplate($this->data['emailTemplate']); diff --git a/tests/Integration/Db/RecipientMapperTest.php b/tests/Integration/Db/RecipientMapperTest.php index 135efe2404..fd37306494 100644 --- a/tests/Integration/Db/RecipientMapperTest.php +++ b/tests/Integration/Db/RecipientMapperTest.php @@ -22,7 +22,7 @@ use OCP\IDBConnection; use PHPUnit\Framework\MockObject\MockObject; -class RecipientMapperTest extends TestCase { +final class RecipientMapperTest extends TestCase { use DatabaseTransaction; use ImapTestAccount; diff --git a/tests/Integration/Db/RecipientTest.php b/tests/Integration/Db/RecipientTest.php index c3c4fa647b..d69a3bc1f5 100644 --- a/tests/Integration/Db/RecipientTest.php +++ b/tests/Integration/Db/RecipientTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\Recipient; -class RecipientTest extends TestCase { +final class RecipientTest extends TestCase { protected function setUp(): void { } diff --git a/tests/Integration/Db/TagMapperTest.php b/tests/Integration/Db/TagMapperTest.php index 88d9b14c9d..1dae60c6f4 100644 --- a/tests/Integration/Db/TagMapperTest.php +++ b/tests/Integration/Db/TagMapperTest.php @@ -16,7 +16,7 @@ use OCP\IDBConnection; use OCP\IL10N; -class TagMapperTest extends TestCase { +final class TagMapperTest extends TestCase { use DatabaseTransaction; private IDBConnection $db; diff --git a/tests/Integration/Db/ThreadMapperTest.php b/tests/Integration/Db/ThreadMapperTest.php index ebd2691c32..e4e6d90939 100644 --- a/tests/Integration/Db/ThreadMapperTest.php +++ b/tests/Integration/Db/ThreadMapperTest.php @@ -21,7 +21,7 @@ use OCP\IDBConnection; use OCP\Server; -class ThreadMapperTest extends TestCase { +final class ThreadMapperTest extends TestCase { use DatabaseTransaction; /** A user that has no mail accounts on a development instance */ diff --git a/tests/Integration/Db/TrustedSenderMapperTest.php b/tests/Integration/Db/TrustedSenderMapperTest.php index f5cc85f5a1..5be7dab6f5 100644 --- a/tests/Integration/Db/TrustedSenderMapperTest.php +++ b/tests/Integration/Db/TrustedSenderMapperTest.php @@ -17,7 +17,7 @@ use OCP\IUser; use OCP\Server; -class TrustedSenderMapperTest extends TestCase { +final class TrustedSenderMapperTest extends TestCase { use DatabaseTransaction, TestUser; /** @var IDBConnection */ diff --git a/tests/Integration/Framework/SelfTest.php b/tests/Integration/Framework/SelfTest.php index 73a10108ac..1b5e674fe8 100644 --- a/tests/Integration/Framework/SelfTest.php +++ b/tests/Integration/Framework/SelfTest.php @@ -1,5 +1,7 @@ assertCount(4, $this->getMailboxes()); $this->createImapMailbox('folder1'); $this->assertCount(5, $this->getMailboxes()); @@ -24,7 +26,7 @@ public function testResetAccount() { $this->assertCount(4, $this->getMailboxes()); } - public function testMessageCapabilities() { + public function testMessageCapabilities(): void { $mb = $this->getMessageBuilder(); $message = $mb->to('fritz@phantom.at') ->from('tom@turbo.at') diff --git a/tests/Integration/IMAP/IMAPClientFactoryTest.php b/tests/Integration/IMAP/IMAPClientFactoryTest.php index 0d60515db8..a2e4cf633d 100644 --- a/tests/Integration/IMAP/IMAPClientFactoryTest.php +++ b/tests/Integration/IMAP/IMAPClientFactoryTest.php @@ -29,7 +29,7 @@ use PHPUnit\Framework\MockObject\MockObject; use function ltrim; -class IMAPClientFactoryTest extends TestCase { +final class IMAPClientFactoryTest extends TestCase { /** @var ICrypto|MockObject */ private $crypto; @@ -80,7 +80,7 @@ private function getTestAccount() { return new Account($mailAccount); } - public function testGetClient() { + public function testGetClient(): void { $account = $this->getTestAccount(); $this->crypto->expects($this->once()) ->method('decrypt') @@ -103,7 +103,7 @@ public function testGetClientDecryptionFailing(): void { $this->factory->getClient($account); } - public function testClientConnectivity() { + public function testClientConnectivity(): void { $account = $this->getTestAccount(); $this->crypto->expects($this->once()) ->method('decrypt') diff --git a/tests/Integration/IMAP/ImapMessageFetcherIntegrationTest.php b/tests/Integration/IMAP/ImapMessageFetcherIntegrationTest.php index 0bfeaaa92b..5acdd37d1d 100644 --- a/tests/Integration/IMAP/ImapMessageFetcherIntegrationTest.php +++ b/tests/Integration/IMAP/ImapMessageFetcherIntegrationTest.php @@ -21,7 +21,7 @@ use OCP\Security\ICrypto; use OCP\Server; -class ImapMessageFetcherIntegrationTest extends TestCase { +final class ImapMessageFetcherIntegrationTest extends TestCase { use ImapTest, ImapTestAccount; @@ -168,12 +168,10 @@ public function testFetchMessageWithSignedMessage(): void { $this->assertTrue($message->isSignatureValid()); } - public function aiGeneratedHeaderProvider(): array { - return [ - [LocalMessage::HEADER_AI_GENERATED . ": 1\r\n", true], - [LocalMessage::HEADER_AI_GENERATED . ": 0\r\n", false], - ['', false], - ]; + public function aiGeneratedHeaderProvider(): \Iterator { + yield [LocalMessage::HEADER_AI_GENERATED . ": 1\r\n", true]; + yield [LocalMessage::HEADER_AI_GENERATED . ": 0\r\n", false]; + yield ['', false]; } /** diff --git a/tests/Integration/IMAP/MessageMapperTest.php b/tests/Integration/IMAP/MessageMapperTest.php index 6bde410533..4feef8524e 100644 --- a/tests/Integration/IMAP/MessageMapperTest.php +++ b/tests/Integration/IMAP/MessageMapperTest.php @@ -21,7 +21,7 @@ use OCA\Mail\Tests\Integration\Framework\ImapTestAccount; use OCP\Server; -class MessageMapperTest extends TestCase { +final class MessageMapperTest extends TestCase { use ImapTest, ImapTestAccount; diff --git a/tests/Integration/KItinerary/ItineraryExtractorTest.php b/tests/Integration/KItinerary/ItineraryExtractorTest.php index b46a406cbc..4512cf986b 100644 --- a/tests/Integration/KItinerary/ItineraryExtractorTest.php +++ b/tests/Integration/KItinerary/ItineraryExtractorTest.php @@ -17,7 +17,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class ItineraryExtractorTest extends TestCase { +final class ItineraryExtractorTest extends TestCase { /** @var BinaryAdapter|MockObject */ private $binaryAdapter; @@ -49,7 +49,7 @@ protected function setUp(): void { ); } - public function testNoAdapterAvailable() { + public function testNoAdapterAvailable(): void { $this->binaryAdapter->expects($this->never()) ->method('extractFromString'); $this->flatpakAdapter->expects($this->never()) @@ -60,7 +60,7 @@ public function testNoAdapterAvailable() { $this->assertEquals([], $itinerary->jsonSerialize()); } - public function testBinAvailable() { + public function testBinAvailable(): void { $this->binaryAdapter->expects($this->once()) ->method('isAvailable') ->willReturn(true); @@ -77,7 +77,7 @@ public function testBinAvailable() { $this->assertEquals([], $itinerary->jsonSerialize()); } - public function testFlatpakAvailable() { + public function testFlatpakAvailable(): void { $this->binaryAdapter->expects($this->never()) ->method('extractFromString'); $this->flatpakAdapter->expects($this->once()) @@ -91,7 +91,7 @@ public function testFlatpakAvailable() { $this->assertEquals([], $itinerary->jsonSerialize()); } - public function testSysAvailable() { + public function testSysAvailable(): void { $this->binaryAdapter->expects($this->never()) ->method('extractFromString'); $this->sysAdapter->expects($this->once()) diff --git a/tests/Integration/MailboxSynchronizationTest.php b/tests/Integration/MailboxSynchronizationTest.php index 59b676b9fb..a3722ad7ac 100644 --- a/tests/Integration/MailboxSynchronizationTest.php +++ b/tests/Integration/MailboxSynchronizationTest.php @@ -28,7 +28,7 @@ use OCP\Server; use Psr\Log\LoggerInterface; -class MailboxSynchronizationTest extends TestCase { +final class MailboxSynchronizationTest extends TestCase { use ImapTest, ImapTestAccount; @@ -66,7 +66,7 @@ public function tearDown(): void { $this->client->logout(); } - public function testSyncEmptyMailbox() { + public function testSyncEmptyMailbox(): void { /** @var MailManager $mailManager */ $mailManager = Server::get(MailManager::class); $mailBoxes = $mailManager->getMailboxes(new Account($this->account)); @@ -104,7 +104,7 @@ public function testSyncEmptyMailbox() { self::assertEmpty($data['vanishedMessages']); } - public function testSyncNewMessage() { + public function testSyncNewMessage(): void { /** @var SyncService $syncService */ $syncService = Server::get(SyncService::class); /** @var MailManager $mailManager */ @@ -146,7 +146,7 @@ public function testSyncNewMessage() { self::assertCount(0, $syncJson['vanishedMessages']); } - public function testSyncChangedMessage() { + public function testSyncChangedMessage(): void { /** @var SyncService $syncService */ $syncService = Server::get(SyncService::class); $mailbox = 'INBOX'; @@ -189,7 +189,7 @@ public function testSyncChangedMessage() { self::assertCount(0, $syncJson['vanishedMessages']); } - public function testSyncVanishedMessage() { + public function testSyncVanishedMessage(): void { $mailbox = 'INBOX'; $message = $this->getMessageBuilder() ->from('ralph@buffington@domain.tld') @@ -232,7 +232,7 @@ public function testSyncVanishedMessage() { // self::assertCount(1, $syncJson['vanishedMessages'], 'Message does not show as vanished, possibly because UID and ID are mixed up above.'); } - public function testUnsolicitedVanishedMessage() { + public function testUnsolicitedVanishedMessage(): void { $mailbox = 'INBOX'; $message = $this->getMessageBuilder() ->from('ralph@buffington@domain.tld') diff --git a/tests/Integration/Migration/MigrateImportantFromImapAndDbTest.php b/tests/Integration/Migration/MigrateImportantFromImapAndDbTest.php index 188ba84998..f9e402a00d 100644 --- a/tests/Integration/Migration/MigrateImportantFromImapAndDbTest.php +++ b/tests/Integration/Migration/MigrateImportantFromImapAndDbTest.php @@ -1,5 +1,7 @@ createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); $uids = [1,2,3]; @@ -61,7 +63,7 @@ public function testMigrateImportantOnImap() { $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } - public function testMigrateImportantOnImapNoUids() { + public function testMigrateImportantOnImapNoUids(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); $uids = []; @@ -78,7 +80,7 @@ public function testMigrateImportantOnImapNoUids() { $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } - public function testMigrateImportantOnImapExceptionGetFlagged() { + public function testMigrateImportantOnImapExceptionGetFlagged(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); $e = new Horde_Imap_Client_Exception(''); @@ -96,7 +98,7 @@ public function testMigrateImportantOnImapExceptionGetFlagged() { $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } - public function testMigrateImportantOnImapExceptionOnFlag() { + public function testMigrateImportantOnImapExceptionOnFlag(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setName('INBOX'); @@ -138,7 +140,7 @@ public function migrateImportantFromDb() { $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } - public function testMigrateImportantFromDbNoUids() { + public function testMigrateImportantFromDbNoUids(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setId(1); @@ -156,7 +158,7 @@ public function testMigrateImportantFromDbNoUids() { $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } - public function testMigrateImportantFromDbExceptionOnFlag() { + public function testMigrateImportantFromDbExceptionOnFlag(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setId(1); diff --git a/tests/Integration/Protocol/ProtocolFactoryImapTest.php b/tests/Integration/Protocol/ProtocolFactoryImapTest.php index c34de829f6..18e80bb06f 100644 --- a/tests/Integration/Protocol/ProtocolFactoryImapTest.php +++ b/tests/Integration/Protocol/ProtocolFactoryImapTest.php @@ -16,7 +16,7 @@ use OCA\Mail\Tests\Integration\Framework\ImapTestAccount; use OCP\Server; -class ProtocolFactoryImapTest extends TestCase { +final class ProtocolFactoryImapTest extends TestCase { use ImapTestAccount; private ProtocolFactory $protocolFactory; diff --git a/tests/Integration/Protocol/ProtocolFactoryJmapTest.php b/tests/Integration/Protocol/ProtocolFactoryJmapTest.php index 1f77368cf6..21967a9e92 100644 --- a/tests/Integration/Protocol/ProtocolFactoryJmapTest.php +++ b/tests/Integration/Protocol/ProtocolFactoryJmapTest.php @@ -16,7 +16,7 @@ use OCA\Mail\Tests\Integration\Framework\JmapTestAccount; use OCP\Server; -class ProtocolFactoryJmapTest extends TestCase { +final class ProtocolFactoryJmapTest extends TestCase { use JmapTestAccount; private ProtocolFactory $protocolFactory; diff --git a/tests/Integration/Service/AntiSpamServiceIntegrationTest.php b/tests/Integration/Service/AntiSpamServiceIntegrationTest.php index 0a49f001ce..c937f80ea0 100644 --- a/tests/Integration/Service/AntiSpamServiceIntegrationTest.php +++ b/tests/Integration/Service/AntiSpamServiceIntegrationTest.php @@ -1,5 +1,7 @@ service = Server::get(IAvatarService::class); } - public function testJansGravatar() { + public function testJansGravatar(): void { $this->markTestSkipped('Unreliable test'); return; $avatar = $this->service->getAvatar('hey@jancborchardt.net', 'john'); diff --git a/tests/Integration/Service/DraftServiceIntegrationTest.php b/tests/Integration/Service/DraftServiceIntegrationTest.php index 773dbc548c..0cc989df34 100644 --- a/tests/Integration/Service/DraftServiceIntegrationTest.php +++ b/tests/Integration/Service/DraftServiceIntegrationTest.php @@ -41,7 +41,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -class DraftServiceIntegrationTest extends TestCase { +final class DraftServiceIntegrationTest extends TestCase { use ImapTest, ImapTestAccount, TestUser; diff --git a/tests/Integration/Service/FolderMapperIntegrationTest.php b/tests/Integration/Service/FolderMapperIntegrationTest.php index d3f29916bb..df3287898f 100644 --- a/tests/Integration/Service/FolderMapperIntegrationTest.php +++ b/tests/Integration/Service/FolderMapperIntegrationTest.php @@ -1,5 +1,7 @@ createMock(Account::class); $account->method('getId')->willReturn(13); $client = $this->getTestClient(); diff --git a/tests/Integration/Service/MailTransmissionIntegrationTest.php b/tests/Integration/Service/MailTransmissionIntegrationTest.php index 06783db4f2..dbd9665df0 100644 --- a/tests/Integration/Service/MailTransmissionIntegrationTest.php +++ b/tests/Integration/Service/MailTransmissionIntegrationTest.php @@ -30,7 +30,7 @@ use OCP\Server; use Psr\Log\NullLogger; -class MailTransmissionIntegrationTest extends TestCase { +final class MailTransmissionIntegrationTest extends TestCase { use ImapTest, TestUser; @@ -103,13 +103,13 @@ protected function setUp(): void { $this->chain = Server::get(Chain::class); } - public function testSendMail() { + public function testSendMail(): void { $this->chain->process($this->account, $this->message); $this->addToAssertionCount(1); } - public function testSendMailWithLocalAttachment() { + public function testSendMailWithLocalAttachment(): void { $file = new UploadedFile([ 'name' => 'text.txt', 'tmp_name' => __DIR__ . '/../../data/mail-message-123.txt', @@ -124,7 +124,7 @@ public function testSendMailWithLocalAttachment() { $this->addToAssertionCount(1); } - public function testSendReply() { + public function testSendReply(): void { $mb = $this->getMessageBuilder(); $originalMessage = $mb->from('from@domain.tld') ->to('to@domain.tld') @@ -149,7 +149,7 @@ public function testSendReply() { $this->assertMessageCount(1, 'Sent'); } - public function testSendReplyWithoutSubject() { + public function testSendReplyWithoutSubject(): void { $mb = $this->getMessageBuilder(); $originalMessage = $mb->from('from@domain.tld') ->to('to@domain.tld') @@ -175,7 +175,7 @@ public function testSendReplyWithoutSubject() { $this->assertMessageCount(1, 'Sent'); } - public function testSendReplyWithoutReplySubject() { + public function testSendReplyWithoutReplySubject(): void { $mb = $this->getMessageBuilder(); $originalMessage = $mb->from('from@domain.tld') ->to('to@domain.tld') diff --git a/tests/Integration/Service/OutboxServiceIntegrationTest.php b/tests/Integration/Service/OutboxServiceIntegrationTest.php index fe27340ac9..ec7357b2fa 100644 --- a/tests/Integration/Service/OutboxServiceIntegrationTest.php +++ b/tests/Integration/Service/OutboxServiceIntegrationTest.php @@ -44,7 +44,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -class OutboxServiceIntegrationTest extends TestCase { +final class OutboxServiceIntegrationTest extends TestCase { use ImapTest, ImapTestAccount, TestUser; diff --git a/tests/Integration/Service/Phishing/PhishingDetectionServiceIntegrationTest.php b/tests/Integration/Service/Phishing/PhishingDetectionServiceIntegrationTest.php index 72ef5606ce..ca465197e2 100644 --- a/tests/Integration/Service/Phishing/PhishingDetectionServiceIntegrationTest.php +++ b/tests/Integration/Service/Phishing/PhishingDetectionServiceIntegrationTest.php @@ -1,5 +1,7 @@ getTestAccount(); $this->crypto->expects($this->once()) ->method('decrypt') @@ -80,7 +80,7 @@ public function testClientConnectivity() { $this->assertInstanceOf(ManageSieve::class, $client); } - public function testClientInstallScript() { + public function testClientInstallScript(): void { $account = $this->getTestAccount(); $this->crypto->expects($this->once()) ->method('decrypt') diff --git a/tests/Integration/Sieve/SieveLoggerTest.php b/tests/Integration/Sieve/SieveLoggerTest.php index 9e61fb363a..cc7214ba3e 100644 --- a/tests/Integration/Sieve/SieveLoggerTest.php +++ b/tests/Integration/Sieve/SieveLoggerTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Sieve\SieveLogger; -class SieveLoggerTest extends TestCase { +final class SieveLoggerTest extends TestCase { // public function testOpenInvalidFile(): void { // $this->expectException(\InvalidArgumentException::class); // $this->expectDeprecationMessage('Unable to use "/root/horde_sieve.log" as log file for sieve.'); diff --git a/tests/Integration/Sync/ImapToDbSynchronizerTest.php b/tests/Integration/Sync/ImapToDbSynchronizerTest.php index 7afc93a57c..516c422712 100644 --- a/tests/Integration/Sync/ImapToDbSynchronizerTest.php +++ b/tests/Integration/Sync/ImapToDbSynchronizerTest.php @@ -22,7 +22,7 @@ use OCP\Server; use Psr\Log\LoggerInterface; -class ImapToDbSynchronizerTest extends TestCase { +final class ImapToDbSynchronizerTest extends TestCase { use ImapTest, ImapTestAccount; diff --git a/tests/Integration/TestCase.php b/tests/Integration/TestCase.php index 76c873da09..1194b32021 100644 --- a/tests/Integration/TestCase.php +++ b/tests/Integration/TestCase.php @@ -1,5 +1,7 @@ command = new CreateImapAccount($this->service, $this->crypto, $this->userManager, $this->classificationSettingsService); } - public function testName() { + public function testName(): void { $this->assertSame('mail:account:create-imap', $this->command->getName()); } - public function testAlias() { + public function testAlias(): void { $this->assertSame(['mail:account:create'], $this->command->getAliases()); } - public function testDescription() { + public function testDescription(): void { $this->assertSame('creates an IMAP mail account', $this->command->getDescription()); } - public function testArguments() { + public function testArguments(): void { $actual = $this->command->getDefinition()->getArguments(); foreach ($actual as $actArg) { @@ -78,7 +78,7 @@ public function testArguments() { } } - public function testInvalidUserId() { + public function testInvalidUserId(): void { $userId = 'invalidUser'; $data = [ 'user-id' => $userId, diff --git a/tests/Unit/Command/CreateJmapAccountTest.php b/tests/Unit/Command/CreateJmapAccountTest.php index eda12b6415..77f961b4e3 100644 --- a/tests/Unit/Command/CreateJmapAccountTest.php +++ b/tests/Unit/Command/CreateJmapAccountTest.php @@ -20,7 +20,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class CreateJmapAccountTest extends TestCase { +final class CreateJmapAccountTest extends TestCase { private AccountService&MockObject $service; private ICrypto&MockObject $crypto; private IUserManager&MockObject $userManager; diff --git a/tests/Unit/Command/CreateProvisioningTest.php b/tests/Unit/Command/CreateProvisioningTest.php index b05505deae..bb67b6e3f0 100644 --- a/tests/Unit/Command/CreateProvisioningTest.php +++ b/tests/Unit/Command/CreateProvisioningTest.php @@ -22,7 +22,7 @@ use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Tester\CommandTester; -class CreateProvisioningTest extends TestCase { +final class CreateProvisioningTest extends TestCase { private ProvisioningManager&MockObject $provisioningManager; private CreateProvisioning $command; private CommandTester $tester; @@ -152,11 +152,9 @@ public function testRejectsMasterUserWithoutMasterPassword(array $options): void self::assertStringContainsString('--master-user requires the master password to be enabled with --master-password', $this->tester->getDisplay()); } - public static function masterUserWithoutMasterPassword(): array { - return [ - 'no master password option' => [['--master-user' => '*admin']], - 'master password disabled' => [['--master-user' => '*admin', '--no-master-password' => true]], - ]; + public static function masterUserWithoutMasterPassword(): \Iterator { + yield 'no master password option' => [['--master-user' => '*admin']]; + yield 'master password disabled' => [['--master-user' => '*admin', '--no-master-password' => true]]; } /** @dataProvider passwordInputs */ @@ -174,15 +172,13 @@ public function testReadsMasterPassword(bool $interactive, string $input, string self::assertStringNotContainsString($expected, $this->tester->getDisplay()); } - public static function passwordInputs(): array { - return [ - 'interactive' => [true, 'sesame', 'sesame'], - 'interactive whitespace' => [true, ' sesame ', ' sesame '], - 'interactive tabs' => [true, "\tsesame\t", "\tsesame\t"], - 'non-interactive' => [false, 'sesame', 'sesame'], - 'non-interactive whitespace' => [false, ' sesame ', ' sesame '], - 'non-interactive CRLF' => [false, " sesame \r", ' sesame '], - ]; + public static function passwordInputs(): \Iterator { + yield 'interactive' => [true, 'sesame', 'sesame']; + yield 'interactive whitespace' => [true, ' sesame ', ' sesame ']; + yield 'interactive tabs' => [true, "\tsesame\t", "\tsesame\t"]; + yield 'non-interactive' => [false, 'sesame', 'sesame']; + yield 'non-interactive whitespace' => [false, ' sesame ', ' sesame ']; + yield 'non-interactive CRLF' => [false, " sesame \r", ' sesame ']; } public function testRejectsMissingPasswordInput(): void { @@ -235,8 +231,9 @@ public function testAcceptsPortBoundaries(int $port): void { self::assertSame(Command::SUCCESS, $status); } - public static function validPortBoundaries(): array { - return [[1], [65535]]; + public static function validPortBoundaries(): \Iterator { + yield [1]; + yield [65535]; } public function testRequiresPortWhenEnablingSieve(): void { @@ -260,11 +257,9 @@ public function testRequiresUserWhenEnablingSieve(array $user): void { self::assertStringContainsString('--sieve-user is required', $this->tester->getDisplay()); } - public static function missingSieveUsers(): array { - return [ - 'omitted' => [[]], - 'empty' => [['--sieve-user' => '']], - ]; + public static function missingSieveUsers(): \Iterator { + yield 'omitted' => [[]]; + yield 'empty' => [['--sieve-user' => '']]; } public function testAllowsMissingPortWhenSieveIsDisabled(): void { @@ -292,20 +287,18 @@ public function testRejectsContradictoryOptions(array $options, string $message) self::assertStringContainsString($message, $this->tester->getDisplay()); } - public static function contradictoryOptions(): array { - return [ - 'sieve' => [ - ['--no-sieve' => true, '--sieve-host' => 'sieve.example.com', '--sieve-port' => '4190'], - '--no-sieve cannot be combined with --sieve-host', - ], - 'ldap aliases' => [ - ['--no-ldap-aliases' => true, '--ldap-aliases-attribute' => 'mailAlias'], - '--no-ldap-aliases cannot be combined with --ldap-aliases-attribute', - ], - 'master password' => [ - ['--no-master-password' => true, '--master-password' => null], - '--no-master-password cannot be combined with --master-password', - ], + public static function contradictoryOptions(): \Iterator { + yield 'sieve' => [ + ['--no-sieve' => true, '--sieve-host' => 'sieve.example.com', '--sieve-port' => '4190'], + '--no-sieve cannot be combined with --sieve-host', + ]; + yield 'ldap aliases' => [ + ['--no-ldap-aliases' => true, '--ldap-aliases-attribute' => 'mailAlias'], + '--no-ldap-aliases cannot be combined with --ldap-aliases-attribute', + ]; + yield 'master password' => [ + ['--no-master-password' => true, '--master-password' => null], + '--no-master-password cannot be combined with --master-password', ]; } @@ -321,11 +314,9 @@ public function testAllowsDisablingWithEmptyValue(array $options, string $key): self::assertSame(Command::SUCCESS, $status); } - public static function redundantDisableOptions(): array { - return [ - 'sieve' => [['--no-sieve' => true, '--sieve-host' => ''], 'sieveEnabled'], - 'ldap aliases' => [['--no-ldap-aliases' => true, '--ldap-aliases-attribute' => ''], 'ldapAliasesProvisioning'], - ]; + public static function redundantDisableOptions(): \Iterator { + yield 'sieve' => [['--no-sieve' => true, '--sieve-host' => ''], 'sieveEnabled']; + yield 'ldap aliases' => [['--no-ldap-aliases' => true, '--ldap-aliases-attribute' => ''], 'ldapAliasesProvisioning']; } public function testRejectsUnknownSslMode(): void { diff --git a/tests/Unit/Command/DeleteAccountTest.php b/tests/Unit/Command/DeleteAccountTest.php index aed2bd8551..07061cec34 100644 --- a/tests/Unit/Command/DeleteAccountTest.php +++ b/tests/Unit/Command/DeleteAccountTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Service\AccountService; use Psr\Log\LoggerInterface; -class DeleteAccountTest extends TestCase { +final class DeleteAccountTest extends TestCase { private $accountService; private $logger; private $command; @@ -35,15 +35,15 @@ protected function setUp(): void { $this->command = new DeleteAccount($this->accountService, $this->logger); } - public function testName() { + public function testName(): void { $this->assertSame('mail:account:delete', $this->command->getName()); } - public function testDescription() { + public function testDescription(): void { $this->assertSame('Delete an IMAP account', $this->command->getDescription()); } - public function testArguments() { + public function testArguments(): void { $actual = $this->command->getDefinition()->getArguments(); foreach ($actual as $actArg) { diff --git a/tests/Unit/Command/DeleteProvisioningTest.php b/tests/Unit/Command/DeleteProvisioningTest.php index 7d051d4142..9068b45a93 100644 --- a/tests/Unit/Command/DeleteProvisioningTest.php +++ b/tests/Unit/Command/DeleteProvisioningTest.php @@ -19,7 +19,7 @@ use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Tester\CommandTester; -class DeleteProvisioningTest extends TestCase { +final class DeleteProvisioningTest extends TestCase { private ProvisioningManager&MockObject $provisioningManager; private DeleteProvisioning $command; private CommandTester $tester; @@ -97,7 +97,13 @@ public function testRejectsInvalidIdBeforeDeleting(string $id): void { self::assertStringContainsString('positive integer', $this->tester->getDisplay()); } - public static function invalidIds(): array { - return [[''], ['0'], ['-1'], ['3typo'], ['3.5'], ['3e1'], ['99999999999999999999']]; + public static function invalidIds(): \Iterator { + yield ['']; + yield ['0']; + yield ['-1']; + yield ['3typo']; + yield ['3.5']; + yield ['3e1']; + yield ['99999999999999999999']; } } diff --git a/tests/Unit/Command/InspectMailboxTest.php b/tests/Unit/Command/InspectMailboxTest.php index 1e89a8add3..0fad9269a8 100644 --- a/tests/Unit/Command/InspectMailboxTest.php +++ b/tests/Unit/Command/InspectMailboxTest.php @@ -19,7 +19,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -class InspectMailboxTest extends TestCase { +final class InspectMailboxTest extends TestCase { private MailboxMapper|\PHPUnit\Framework\MockObject\MockObject $mailboxMapper; private ITimeFactory|\PHPUnit\Framework\MockObject\MockObject $timeFactory; private InspectMailbox $command; diff --git a/tests/Unit/Command/ListMailboxesTest.php b/tests/Unit/Command/ListMailboxesTest.php index 361fb81aad..be94cc52c5 100644 --- a/tests/Unit/Command/ListMailboxesTest.php +++ b/tests/Unit/Command/ListMailboxesTest.php @@ -21,7 +21,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -class ListMailboxesTest extends TestCase { +final class ListMailboxesTest extends TestCase { private AccountService|\PHPUnit\Framework\MockObject\MockObject $accountService; private MailboxMapper|\PHPUnit\Framework\MockObject\MockObject $mailboxMapper; private ITimeFactory|\PHPUnit\Framework\MockObject\MockObject $timeFactory; diff --git a/tests/Unit/Command/ListProvisioningsTest.php b/tests/Unit/Command/ListProvisioningsTest.php index 8572aab494..989436da44 100644 --- a/tests/Unit/Command/ListProvisioningsTest.php +++ b/tests/Unit/Command/ListProvisioningsTest.php @@ -17,7 +17,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -class ListProvisioningsTest extends TestCase { +final class ListProvisioningsTest extends TestCase { private ProvisioningManager&MockObject $provisioningManager; private CommandTester $tester; diff --git a/tests/Unit/Command/ProvisionAccountsTest.php b/tests/Unit/Command/ProvisionAccountsTest.php index 9ce1efe7cb..2acfdab133 100644 --- a/tests/Unit/Command/ProvisionAccountsTest.php +++ b/tests/Unit/Command/ProvisionAccountsTest.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -class ProvisionAccountsTest extends TestCase { +final class ProvisionAccountsTest extends TestCase { private ProvisioningManager&MockObject $provisioningManager; private CommandTester $tester; diff --git a/tests/Unit/Command/UnlockMailboxTest.php b/tests/Unit/Command/UnlockMailboxTest.php index 14a82a4ce5..6c6a1074ce 100644 --- a/tests/Unit/Command/UnlockMailboxTest.php +++ b/tests/Unit/Command/UnlockMailboxTest.php @@ -18,7 +18,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -class UnlockMailboxTest extends TestCase { +final class UnlockMailboxTest extends TestCase { private MailboxMapper|\PHPUnit\Framework\MockObject\MockObject $mailboxMapper; private ITimeFactory|\PHPUnit\Framework\MockObject\MockObject $timeFactory; private UnlockMailbox $command; diff --git a/tests/Unit/Command/UpdateImapAccountTest.php b/tests/Unit/Command/UpdateImapAccountTest.php index b2412e85d4..e4e8bd5785 100644 --- a/tests/Unit/Command/UpdateImapAccountTest.php +++ b/tests/Unit/Command/UpdateImapAccountTest.php @@ -18,7 +18,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class UpdateImapAccountTest extends TestCase { +final class UpdateImapAccountTest extends TestCase { private MailAccountMapper&MockObject $mapper; private ICrypto&MockObject $crypto; private UpdateImapAccount $command; diff --git a/tests/Unit/Command/UpdateJmapAccountTest.php b/tests/Unit/Command/UpdateJmapAccountTest.php index 24dd2a5611..6691edbd61 100644 --- a/tests/Unit/Command/UpdateJmapAccountTest.php +++ b/tests/Unit/Command/UpdateJmapAccountTest.php @@ -18,7 +18,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class UpdateJmapAccountTest extends TestCase { +final class UpdateJmapAccountTest extends TestCase { private MailAccountMapper&MockObject $mapper; private ICrypto&MockObject $crypto; private UpdateJmapAccount $command; diff --git a/tests/Unit/Command/UpdateProvisioningTest.php b/tests/Unit/Command/UpdateProvisioningTest.php index 2e574a9a24..249e572d7b 100644 --- a/tests/Unit/Command/UpdateProvisioningTest.php +++ b/tests/Unit/Command/UpdateProvisioningTest.php @@ -20,7 +20,7 @@ use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Tester\CommandTester; -class UpdateProvisioningTest extends TestCase { +final class UpdateProvisioningTest extends TestCase { private ProvisioningManager&MockObject $provisioningManager; private CommandTester $tester; @@ -184,8 +184,14 @@ public function testRejectsInvalidIdBeforeUpdating(string $id): void { self::assertStringContainsString('positive integer', $this->tester->getDisplay()); } - public static function invalidIds(): array { - return [[''], ['0'], ['-1'], ['3typo'], ['3.5'], ['3e1'], ['99999999999999999999']]; + public static function invalidIds(): \Iterator { + yield ['']; + yield ['0']; + yield ['-1']; + yield ['3typo']; + yield ['3.5']; + yield ['3e1']; + yield ['99999999999999999999']; } /** @dataProvider passwordInputModes */ @@ -204,8 +210,9 @@ public function testUpdatesMasterPasswordFromInput(bool $interactive): void { self::assertStringNotContainsString('new password', $this->tester->getDisplay()); } - public static function passwordInputModes(): array { - return [[true], [false]]; + public static function passwordInputModes(): \Iterator { + yield [true]; + yield [false]; } public function testRejectsMissingPasswordInput(): void { @@ -232,8 +239,10 @@ public function testRejectsInvalidPorts(string $option, string $port): void { self::assertStringContainsString($option . ' must be an integer between 1 and 65535', $this->tester->getDisplay()); } - public static function invalidPorts(): array { - return [['--imap-port', ''], ['--smtp-port', '587typo'], ['--sieve-port', '65536']]; + public static function invalidPorts(): \Iterator { + yield ['--imap-port', '']; + yield ['--smtp-port', '587typo']; + yield ['--sieve-port', '65536']; } public function testRequiresPortWhenEnablingSieve(): void { diff --git a/tests/Unit/ConfigLexiconTest.php b/tests/Unit/ConfigLexiconTest.php index 98d35243f0..01a0c1b633 100644 --- a/tests/Unit/ConfigLexiconTest.php +++ b/tests/Unit/ConfigLexiconTest.php @@ -16,7 +16,7 @@ use OCP\Config\Lexicon\Strictness; use OCP\Config\ValueType; -class ConfigLexiconTest extends TestCase { +final class ConfigLexiconTest extends TestCase { private ConfigLexicon $lexicon; diff --git a/tests/Unit/ContextChat/ContextChatProviderTest.php b/tests/Unit/ContextChat/ContextChatProviderTest.php index e9d9a449f3..f2b59807ae 100644 --- a/tests/Unit/ContextChat/ContextChatProviderTest.php +++ b/tests/Unit/ContextChat/ContextChatProviderTest.php @@ -29,7 +29,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; -class ContextChatProviderTest extends TestCase { +final class ContextChatProviderTest extends TestCase { /** @var TaskService|MockObject */ private $taskService; @@ -125,7 +125,7 @@ public function testHandleWithoutContextChat($event): void { /** * @dataProvider provideEvents */ - public function testHandleWithContextChat($event) { + public function testHandleWithContextChat($event): void { $this->contentManager->expects($this->once()) ->method('isContextChatAvailable') ->willReturn(true); diff --git a/tests/Unit/Controller/AccountApiControllerTest.php b/tests/Unit/Controller/AccountApiControllerTest.php index fb051db2fd..9f367bce85 100644 --- a/tests/Unit/Controller/AccountApiControllerTest.php +++ b/tests/Unit/Controller/AccountApiControllerTest.php @@ -21,7 +21,7 @@ use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; -class AccountApiControllerTest extends TestCase { +final class AccountApiControllerTest extends TestCase { private const USER_ID = 'user'; private AccountApiController $controller; @@ -49,7 +49,7 @@ protected function setUp(): void { ); } - public function testListWithoutUser() { + public function testListWithoutUser(): void { $controller = new AccountApiController( 'mail', $this->request, @@ -69,7 +69,7 @@ public function testListWithoutUser() { $this->assertEquals(Http::STATUS_NOT_FOUND, $actual->getStatus()); } - public function testList() { + public function testList(): void { $mailAccount = new MailAccount(); $mailAccount->setId(42); $mailAccount->setEmail('foo@bar.com'); @@ -112,7 +112,7 @@ public function testList() { ], $actual->getData()); } - public function testListWithAliasWithoutName() { + public function testListWithAliasWithoutName(): void { $mailAccount = new MailAccount(); $mailAccount->setId(42); $mailAccount->setEmail('foo@bar.com'); @@ -155,7 +155,7 @@ public function testListWithAliasWithoutName() { ], $actual->getData()); } - public function testListWithDelegatedAccounts() { + public function testListWithDelegatedAccounts(): void { $ownMailAccount = new MailAccount(); $ownMailAccount->setId(42); $ownMailAccount->setEmail('foo@bar.com'); @@ -224,7 +224,7 @@ public function testListWithDelegatedAccounts() { ], $actual->getData()); } - public function testListWithoutAliases() { + public function testListWithoutAliases(): void { $mailAccount = new MailAccount(); $mailAccount->setId(42); $mailAccount->setEmail('foo@bar.com'); diff --git a/tests/Unit/Controller/AccountsControllerTest.php b/tests/Unit/Controller/AccountsControllerTest.php index 0b9053b003..713cbd683c 100644 --- a/tests/Unit/Controller/AccountsControllerTest.php +++ b/tests/Unit/Controller/AccountsControllerTest.php @@ -35,7 +35,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class AccountsControllerTest extends TestCase { +final class AccountsControllerTest extends TestCase { /** @var string */ private $appName; diff --git a/tests/Unit/Controller/AliasesControllerTest.php b/tests/Unit/Controller/AliasesControllerTest.php index 024ce35641..3b65f437a6 100644 --- a/tests/Unit/Controller/AliasesControllerTest.php +++ b/tests/Unit/Controller/AliasesControllerTest.php @@ -1,5 +1,7 @@ 13, diff --git a/tests/Unit/Controller/AvatarControllerTest.php b/tests/Unit/Controller/AvatarControllerTest.php index 99f9cf4cba..5d3dc24952 100644 --- a/tests/Unit/Controller/AvatarControllerTest.php +++ b/tests/Unit/Controller/AvatarControllerTest.php @@ -1,5 +1,7 @@ createServiceMock(InternalAddressController::class, [ 'userId' => null, diff --git a/tests/Unit/Controller/ListControllerTest.php b/tests/Unit/Controller/ListControllerTest.php index 9eb4c7667b..871c3f8b7e 100644 --- a/tests/Unit/Controller/ListControllerTest.php +++ b/tests/Unit/Controller/ListControllerTest.php @@ -24,7 +24,7 @@ use OCP\AppFramework\Http; use OCP\Http\Client\IClient; -class ListControllerTest extends TestCase { +final class ListControllerTest extends TestCase { private ServiceMockObject $serviceMock; private ListController $controller; private string $userId = 'user123'; diff --git a/tests/Unit/Controller/LocalAttachmentsControllerTest.php b/tests/Unit/Controller/LocalAttachmentsControllerTest.php index cc9be08212..1f856e7d9e 100644 --- a/tests/Unit/Controller/LocalAttachmentsControllerTest.php +++ b/tests/Unit/Controller/LocalAttachmentsControllerTest.php @@ -1,5 +1,7 @@ controller = new LocalAttachmentsController('mail', $this->request, $this->service, $this->delegationService, $this->userId); } - public function testCreateWithoutFile() { + public function testCreateWithoutFile(): void { $this->request->expects($this->once()) ->method('getUploadedFile') ->with('attachment') @@ -55,7 +57,7 @@ public function testCreateWithoutFile() { $this->controller->create(); } - public function testCreate() { + public function testCreate(): void { $fileData = [ 'name' => 'cat.jpg', ]; @@ -77,7 +79,7 @@ public function testCreate() { $this->assertEquals(new JSONResponse($attachment, 201), $actual); } - public function testCreateForDelegatedAccount() { + public function testCreateForDelegatedAccount(): void { $fileData = [ 'name' => 'cat.jpg', ]; diff --git a/tests/Unit/Controller/MailboxesApiControllerTest.php b/tests/Unit/Controller/MailboxesApiControllerTest.php index 53e64c0473..2094438384 100644 --- a/tests/Unit/Controller/MailboxesApiControllerTest.php +++ b/tests/Unit/Controller/MailboxesApiControllerTest.php @@ -25,7 +25,7 @@ use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; -class MailboxesApiControllerTest extends TestCase { +final class MailboxesApiControllerTest extends TestCase { private const USER_ID = 'user'; private MailboxesApiController $controller; @@ -60,7 +60,7 @@ protected function setUp(): void { ); } - public function testListMailboxesWithoutUser() { + public function testListMailboxesWithoutUser(): void { $controller = new MailboxesApiController( 'mail', $this->request, @@ -80,7 +80,7 @@ public function testListMailboxesWithoutUser() { $this->assertEquals(Http::STATUS_NOT_FOUND, $actual->getStatus()); } - public function testListMailboxes() { + public function testListMailboxes(): void { $account = $this->createStub(Account::class); $folder = $this->createStub(Folder::class); $accountId = 42; @@ -100,7 +100,7 @@ public function testListMailboxes() { $this->assertEquals([$folder], $actual->getData()); } - public function testListMessagesWithoutUser() { + public function testListMessagesWithoutUser(): void { $controller = new MailboxesApiController( 'mail', $this->request, @@ -176,12 +176,10 @@ public function testListMessagesInvalidMailbox(): void { $this->assertEquals(Http::STATUS_FORBIDDEN, $actual->getStatus()); } - public static function provideLimitData(): array { - return [ - '20' => [20, 20], - '500' => [500, 100], - 'null' => [null, 1], - ]; + public static function provideLimitData(): \Iterator { + yield '20' => [20, 20]; + yield '500' => [500, 100]; + yield 'null' => [null, 1]; } /** @dataProvider provideLimitData */ diff --git a/tests/Unit/Controller/MailboxesControllerTest.php b/tests/Unit/Controller/MailboxesControllerTest.php index b38bc7ad97..26227abf9d 100644 --- a/tests/Unit/Controller/MailboxesControllerTest.php +++ b/tests/Unit/Controller/MailboxesControllerTest.php @@ -27,7 +27,7 @@ use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; -class MailboxesControllerTest extends TestCase { +final class MailboxesControllerTest extends TestCase { /** @var string */ private $appName = 'mail'; @@ -82,7 +82,7 @@ public function setUp(): void { ); } - public function testIndex() { + public function testIndex(): void { $account = $this->createMock(Account::class); $folder = $this->createMock(Folder::class); $accountId = 28; @@ -116,13 +116,13 @@ public function testIndex() { $this->assertEquals($expected, $result); } - public function testShow() { + public function testShow(): void { $this->expectException(NotImplemented::class); $this->controller->show(); } - public function testCreate() { + public function testCreate(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setId(99); @@ -346,7 +346,7 @@ public function testStats(): void { $this->assertEquals($expected, $response); } - public function testUpdate() { + public function testUpdate(): void { $this->expectException(NotImplemented::class); $this->controller->update(); diff --git a/tests/Unit/Controller/MessageApiControllerTest.php b/tests/Unit/Controller/MessageApiControllerTest.php index ff3d8a7665..e237cc5cb2 100644 --- a/tests/Unit/Controller/MessageApiControllerTest.php +++ b/tests/Unit/Controller/MessageApiControllerTest.php @@ -42,7 +42,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class MessageApiControllerTest extends TestCase { +final class MessageApiControllerTest extends TestCase { private string $appName = 'mail'; private string $userId = 'john'; private MockObject|IRequest $request; @@ -452,14 +452,12 @@ public function testSendNoRecipient(): void { $this->assertEquals($expected, $actual); } - public function mailData() { - return [ - [LocalMessage::STATUS_PROCESSED, new DataResponse('', Http::STATUS_OK), 'john sent a message on behalf of john'], - [LocalMessage::STATUS_NO_SENT_MAILBOX, new DataResponse('Configuration error: Cannot send message without sent mailbox.', Http::STATUS_FORBIDDEN), 'john attempted sending a message on behalf of john but no sent mailbox is configured'], - [LocalMessage::STATUS_SMPT_SEND_FAIL, new DataResponse('SMTP error: could not send message. Message sending will be retried. Please check the logs.', Http::STATUS_INTERNAL_SERVER_ERROR), 'john attempted sending a message on behalf of john but SMTP sending failed'], - [LocalMessage::STATUS_IMAP_SENT_MAILBOX_FAIL, new DataResponse('Email was sent but could not be copied to sent mailbox. Copying will be retried. Please check the logs.', Http::STATUS_ACCEPTED), 'john sent a message on behalf of john but copying to sent mailbox failed'], - [LocalMessage::STATUS_TOO_MANY_RECIPIENTS, new DataResponse('An error occurred. Please check the logs.', Http::STATUS_INTERNAL_SERVER_ERROR), 'john attempted sending a message on behalf of john but an unknown error occurred'], - ]; + public function mailData(): \Iterator { + yield [LocalMessage::STATUS_PROCESSED, new DataResponse('', Http::STATUS_OK), 'john sent a message on behalf of john']; + yield [LocalMessage::STATUS_NO_SENT_MAILBOX, new DataResponse('Configuration error: Cannot send message without sent mailbox.', Http::STATUS_FORBIDDEN), 'john attempted sending a message on behalf of john but no sent mailbox is configured']; + yield [LocalMessage::STATUS_SMPT_SEND_FAIL, new DataResponse('SMTP error: could not send message. Message sending will be retried. Please check the logs.', Http::STATUS_INTERNAL_SERVER_ERROR), 'john attempted sending a message on behalf of john but SMTP sending failed']; + yield [LocalMessage::STATUS_IMAP_SENT_MAILBOX_FAIL, new DataResponse('Email was sent but could not be copied to sent mailbox. Copying will be retried. Please check the logs.', Http::STATUS_ACCEPTED), 'john sent a message on behalf of john but copying to sent mailbox failed']; + yield [LocalMessage::STATUS_TOO_MANY_RECIPIENTS, new DataResponse('An error occurred. Please check the logs.', Http::STATUS_INTERNAL_SERVER_ERROR), 'john attempted sending a message on behalf of john but an unknown error occurred']; } /** @@ -497,11 +495,9 @@ public function testSendException($exception, $expected): void { $this->assertEquals($expected, $actual); } - public function exceptionData() { - return [ - [new ServiceException(), new DataResponse('Processing error: could not send message. Please check the logs', Http::STATUS_BAD_REQUEST)], - [new Exception(), new DataResponse('Fatal SMTP error: could not send message, and no resending is possible. Please check the mail server logs.', Http::STATUS_INTERNAL_SERVER_ERROR)], - ]; + public function exceptionData(): \Iterator { + yield [new ServiceException(), new DataResponse('Processing error: could not send message. Please check the logs', Http::STATUS_BAD_REQUEST)]; + yield [new Exception(), new DataResponse('Fatal SMTP error: could not send message, and no resending is possible. Please check the mail server logs.', Http::STATUS_INTERNAL_SERVER_ERROR)]; } public function testWithAttachment(): void { diff --git a/tests/Unit/Controller/MessagesControllerTest.php b/tests/Unit/Controller/MessagesControllerTest.php index a5b225c1e1..1fc03005d6 100644 --- a/tests/Unit/Controller/MessagesControllerTest.php +++ b/tests/Unit/Controller/MessagesControllerTest.php @@ -59,7 +59,7 @@ use Psr\Log\LoggerInterface; use ReflectionObject; -class MessagesControllerTest extends TestCase { +final class MessagesControllerTest extends TestCase { /** @var string */ private $appName; @@ -358,7 +358,7 @@ public function testDownloadEmptyAttachmentIsNotCached(): void { $this->assertSame('no-cache, no-store, must-revalidate', $response->getHeaders()['Cache-Control']); } - public function testSaveSingleAttachment() { + public function testSaveSingleAttachment(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -424,7 +424,7 @@ public function testSaveSingleAttachment() { $this->assertEquals($expected, $response); } - public function testSaveAllAttachments() { + public function testSaveAllAttachments(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -521,7 +521,7 @@ public function testSaveAttachmentTargetPathIsFile(): void { $this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus()); } - public function testDownloadAttachments() { + public function testDownloadAttachments(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -598,7 +598,7 @@ public function testDownloadAttachments() { $this->assertEquals($zipValues, $responseValues); } - public function testDownloadAttachmentsNoAccountError() { + public function testDownloadAttachmentsNoAccountError(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -630,7 +630,7 @@ public function testDownloadAttachmentsNoAccountError() { $this->assertInstanceOf(JSONResponse::class, $response); } - public function testDownloadAttachmentsNoMailboxError() { + public function testDownloadAttachmentsNoMailboxError(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -659,7 +659,7 @@ public function testDownloadAttachmentsNoMailboxError() { $this->assertInstanceOf(JSONResponse::class, $response); } - public function testDownloadAttachmentsNoMessageError() { + public function testDownloadAttachmentsNoMessageError(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -683,7 +683,7 @@ public function testDownloadAttachmentsNoMessageError() { $this->assertInstanceOf(JSONResponse::class, $response); } - public function testSetFlagsUnseen() { + public function testSetFlagsUnseen(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -724,7 +724,7 @@ public function testSetFlagsUnseen() { $this->assertEquals($expected, $response); } - public function testSetTagFailing() { + public function testSetTagFailing(): void { $accountId = 17; $mailboxId = 987; $id = 1; @@ -755,7 +755,7 @@ public function testSetTagFailing() { $this->controller->setTag($id, Tag::LABEL_IMPORTANT); } - public function testSetTagNotFound() { + public function testSetTagNotFound(): void { $accountId = 17; $mailboxId = 987; $id = 1; @@ -789,7 +789,7 @@ public function testSetTagNotFound() { $this->controller->setTag($id, $imapLabel); } - public function testSetTag() { + public function testSetTag(): void { $accountId = 17; $mailboxId = 987; $id = 1; @@ -828,7 +828,7 @@ public function testSetTag() { $this->controller->setTag($id, $tag->getImapLabel()); } - public function testRemoveTagFailing() { + public function testRemoveTagFailing(): void { $accountId = 17; $mailboxId = 987; $id = 1; @@ -859,7 +859,7 @@ public function testRemoveTagFailing() { $this->controller->removeTag($id, Tag::LABEL_IMPORTANT); } - public function testRemoveTagNotFound() { + public function testRemoveTagNotFound(): void { $accountId = 17; $mailboxId = 987; $id = 1; @@ -893,7 +893,7 @@ public function testRemoveTagNotFound() { $this->controller->removeTag($id, $imapLabel); } - public function testRemoveTag() { + public function testRemoveTag(): void { $accountId = 17; $mailboxId = 987; $id = 1; @@ -932,7 +932,7 @@ public function testRemoveTag() { $this->controller->removeTag($id, $tag->getImapLabel()); } - public function testSetFlagsFlagged() { + public function testSetFlagsFlagged(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -973,7 +973,7 @@ public function testSetFlagsFlagged() { $this->assertEquals($expected, $response); } - public function testDestroy() { + public function testDestroy(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -1008,7 +1008,7 @@ public function testDestroy() { $this->assertEquals($expected, $result); } - public function testDestroyWithAccountNotFound() { + public function testDestroyWithAccountNotFound(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -1036,7 +1036,7 @@ public function testDestroyWithAccountNotFound() { $this->assertEquals($expected, $this->controller->destroy($id)); } - public function testDestroyWithFolderOrMessageNotFound() { + public function testDestroyWithFolderOrMessageNotFound(): void { $accountId = 17; $mailboxId = 987; $id = 123; @@ -1158,7 +1158,7 @@ public function testGetThreadThreadRootIdEmptyString(): void { $this->controller->getThread($id); } - public function testExport() { + public function testExport(): void { $accountId = 17; $mailboxId = 13; $folderId = 'testfolder'; @@ -1201,7 +1201,7 @@ public function testExport() { $this->assertEquals($expectedResponse, $actualResponse); } - public function testSaveFile() { + public function testSaveFile(): void { $accountId = 17; $mailboxId = 13; $folderId = 'testfolder'; @@ -1257,7 +1257,7 @@ public function testSaveFile() { $this->assertEquals($expectedResponse, $actualResponse); } - public function testGetDkim() { + public function testGetDkim(): void { $mailAccount = new MailAccount(); $mailAccount->setId(100); $mailAccount->setUserId($this->userId); @@ -1297,12 +1297,10 @@ public function testGetDkim() { $this->assertEquals(['valid' => true], $actualResponse->getData()); } - public static function provideCacheBusterData(): array { - return [ - [null, false], - ['', false], - ['abcdef123', true], - ]; + public static function provideCacheBusterData(): \Iterator { + yield [null, false]; + yield ['', false]; + yield ['abcdef123', true]; } /** @dataProvider provideCacheBusterData */ @@ -1353,12 +1351,10 @@ public function testIndexCacheBuster(?string $cacheBuster, bool $expectCaching): } } - public static function provideLimitData(): array { - return [ - '20' => [20, 20], - '500' => [500, 100], - 'null' => [null, 1], - ]; + public static function provideLimitData(): \Iterator { + yield '20' => [20, 20]; + yield '500' => [500, 100]; + yield 'null' => [null, 1]; } /** @dataProvider provideLimitData */ diff --git a/tests/Unit/Controller/OauthControllerTest.php b/tests/Unit/Controller/OauthControllerTest.php index 979e7cf665..886169a8be 100644 --- a/tests/Unit/Controller/OauthControllerTest.php +++ b/tests/Unit/Controller/OauthControllerTest.php @@ -18,7 +18,7 @@ use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; -class OauthControllerTest extends TestCase { +final class OauthControllerTest extends TestCase { private IRequest&MockObject $request; private AccountService&MockObject $accountService; private OauthStateService&MockObject $oauthStateService; diff --git a/tests/Unit/Controller/OidcIntegrationControllerTest.php b/tests/Unit/Controller/OidcIntegrationControllerTest.php index 488c7c86c5..b36fa9c036 100644 --- a/tests/Unit/Controller/OidcIntegrationControllerTest.php +++ b/tests/Unit/Controller/OidcIntegrationControllerTest.php @@ -29,7 +29,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class OidcIntegrationControllerTest extends TestCase { +final class OidcIntegrationControllerTest extends TestCase { private OidcIntegration&MockObject $oidcIntegration; private AccountService&MockObject $accountService; private LoggerInterface&MockObject $logger; diff --git a/tests/Unit/Controller/OutOfOfficeControllerTest.php b/tests/Unit/Controller/OutOfOfficeControllerTest.php index e766d8d9d6..8d0b86e693 100644 --- a/tests/Unit/Controller/OutOfOfficeControllerTest.php +++ b/tests/Unit/Controller/OutOfOfficeControllerTest.php @@ -1,5 +1,7 @@ outOfOfficeController = $this->serviceMock->getService(); } - public function followSystemDataProvider(): array { - return [ - [false], - [true], - ]; + public function followSystemDataProvider(): \Iterator { + yield [false]; + yield [true]; } /** diff --git a/tests/Unit/Controller/OutboxControllerTest.php b/tests/Unit/Controller/OutboxControllerTest.php index 9d241a5f25..5ca87cdda4 100644 --- a/tests/Unit/Controller/OutboxControllerTest.php +++ b/tests/Unit/Controller/OutboxControllerTest.php @@ -29,7 +29,7 @@ use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; -class OutboxControllerTest extends TestCase { +final class OutboxControllerTest extends TestCase { private string $appName; /** @var OutboxService&MockObject */ diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index bde977f24d..5a3da1932a 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -50,7 +50,7 @@ use Psr\Log\LoggerInterface; use function urlencode; -class PageControllerTest extends TestCase { +final class PageControllerTest extends TestCase { /** @var string */ private $appName; @@ -439,7 +439,7 @@ public function testIndex(): void { $this->assertEquals($expected, $response); } - public function testComposeSimple() { + public function testComposeSimple(): void { $address = 'user@example.com'; $uri = "mailto:$address"; @@ -450,7 +450,7 @@ public function testComposeSimple() { $this->assertEquals($expected, $response); } - public function testComposeWithSubject() { + public function testComposeWithSubject(): void { $address = 'user@example.com'; $subject = 'hello there'; $uri = "mailto:$address?subject=$subject"; @@ -463,7 +463,7 @@ public function testComposeWithSubject() { $this->assertEquals($expected, $response); } - public function testComposeWithCc() { + public function testComposeWithCc(): void { $address = 'user@example.com'; $cc = 'other@example.com'; $uri = "mailto:$address?cc=$cc"; @@ -476,7 +476,7 @@ public function testComposeWithCc() { $this->assertEquals($expected, $response); } - public function testComposeBcc() { + public function testComposeBcc(): void { $bcc = 'blind@example.com'; $uri = "mailto:?bcc=$bcc"; @@ -487,7 +487,7 @@ public function testComposeBcc() { $this->assertEquals($expected, $response); } - public function testComposeWithBcc() { + public function testComposeWithBcc(): void { $address = 'user@example.com'; $bcc = 'blind@example.com'; $uri = "mailto:$address?bcc=$bcc"; @@ -500,7 +500,7 @@ public function testComposeWithBcc() { $this->assertEquals($expected, $response); } - public function testComposeWithMultilineBody() { + public function testComposeWithMultilineBody(): void { $address = 'user@example.com'; $body = 'Hi!\nWhat\'s up?\nAnother line'; $uri = "mailto:$address?body=$body"; diff --git a/tests/Unit/Controller/PreferencesControllerTest.php b/tests/Unit/Controller/PreferencesControllerTest.php index d723ec4198..d8bd4066e5 100644 --- a/tests/Unit/Controller/PreferencesControllerTest.php +++ b/tests/Unit/Controller/PreferencesControllerTest.php @@ -1,5 +1,7 @@ controller = new PreferencesController($request, $this->preferences, 'george'); } - public function testGetPreference() { + public function testGetPreference(): void { $this->preferences->expects($this->once()) ->method('getPreference') ->with('george', 'test') @@ -42,7 +44,7 @@ public function testGetPreference() { $this->assertEquals($expected, $actual); } - public function testSetPreference() { + public function testSetPreference(): void { $this->preferences->expects($this->once()) ->method('setPreference') ->with('george', 'test') diff --git a/tests/Unit/Controller/ProxyControllerTest.php b/tests/Unit/Controller/ProxyControllerTest.php index 51b5c41dd1..cda968f7a1 100644 --- a/tests/Unit/Controller/ProxyControllerTest.php +++ b/tests/Unit/Controller/ProxyControllerTest.php @@ -28,7 +28,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -class ProxyControllerTest extends TestCase { +final class ProxyControllerTest extends TestCase { /** @var string */ private $appName; diff --git a/tests/Unit/Controller/SettingsControllerTest.php b/tests/Unit/Controller/SettingsControllerTest.php index abf7c48f6e..68476368f7 100644 --- a/tests/Unit/Controller/SettingsControllerTest.php +++ b/tests/Unit/Controller/SettingsControllerTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Tests\Integration\TestCase; use OCP\AppFramework\Http\JSONResponse; -class SettingsControllerTest extends TestCase { +final class SettingsControllerTest extends TestCase { /** @var ServiceMockObject */ private $mock; @@ -29,7 +29,7 @@ protected function setUp(): void { $this->controller = $this->mock->getService(); } - public function testProvisioning() { + public function testProvisioning(): void { $this->mock->getParameter('provisioningManager') ->expects($this->once()) ->method('provision') @@ -52,7 +52,7 @@ public function testCreateProvisioning(): void { self::assertEquals(new JSONResponse($provisioning), $response); } - public function testDeprovision() { + public function testDeprovision(): void { $provisioning = new Provisioning(); $this->mock->getParameter('provisioningManager') ->expects($this->once()) diff --git a/tests/Unit/Controller/SieveControllerTest.php b/tests/Unit/Controller/SieveControllerTest.php index 66d958d275..9e540a2606 100644 --- a/tests/Unit/Controller/SieveControllerTest.php +++ b/tests/Unit/Controller/SieveControllerTest.php @@ -19,7 +19,7 @@ use OCP\Security\IRemoteHostValidator; use PHPUnit\Framework\MockObject\MockObject; -class SieveControllerTest extends TestCase { +final class SieveControllerTest extends TestCase { /** @var IRemoteHostValidator|MockObject */ private $remoteHostValidator; diff --git a/tests/Unit/Controller/SmimeCertificatesControllerTest.php b/tests/Unit/Controller/SmimeCertificatesControllerTest.php index 1504079ecc..d4101963e8 100644 --- a/tests/Unit/Controller/SmimeCertificatesControllerTest.php +++ b/tests/Unit/Controller/SmimeCertificatesControllerTest.php @@ -13,7 +13,7 @@ use OCA\Mail\Controller\SmimeCertificatesController; use OCP\AppFramework\Http; -class SmimeCertificatesControllerTest extends TestCase { +final class SmimeCertificatesControllerTest extends TestCase { public function testIndexNullUser(): void { $serviceMock = $this->createServiceMock(SmimeCertificatesController::class, [ 'appName' => 'mail', diff --git a/tests/Unit/Controller/TagsControllerTest.php b/tests/Unit/Controller/TagsControllerTest.php index 2718073a1f..c914f4fc29 100644 --- a/tests/Unit/Controller/TagsControllerTest.php +++ b/tests/Unit/Controller/TagsControllerTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Service\MailManager; use OCA\Mail\Tests\Integration\TestCase; -class TagsControllerTest extends TestCase { +final class TagsControllerTest extends TestCase { /** @var ServiceMockObject */ private $serviceMock; diff --git a/tests/Unit/Controller/ThreadControllerTest.php b/tests/Unit/Controller/ThreadControllerTest.php index 1dbb3dd669..703af489ba 100644 --- a/tests/Unit/Controller/ThreadControllerTest.php +++ b/tests/Unit/Controller/ThreadControllerTest.php @@ -29,7 +29,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class ThreadControllerTest extends TestCase { +final class ThreadControllerTest extends TestCase { /** @var string */ private $appName; @@ -88,7 +88,7 @@ protected function setUp(): void { ); } - public function testMoveForbidden() { + public function testMoveForbidden(): void { $this->mailManager ->method('getMessage') ->willThrowException(new DoesNotExistException('for some reason there is no such record')); diff --git a/tests/Unit/Controller/TrustedSendersControllerTest.php b/tests/Unit/Controller/TrustedSendersControllerTest.php index 89a581fe95..d0a0a11e8b 100644 --- a/tests/Unit/Controller/TrustedSendersControllerTest.php +++ b/tests/Unit/Controller/TrustedSendersControllerTest.php @@ -13,7 +13,7 @@ use OCA\Mail\Controller\TrustedSendersController; use OCP\AppFramework\Http; -class TrustedSendersControllerTest extends TestCase { +final class TrustedSendersControllerTest extends TestCase { public function testSetTrustedNullUser(): void { $serviceMock = $this->createServiceMock(TrustedSendersController::class, [ 'userId' => null, diff --git a/tests/Unit/Dashboard/ImportantMailWidgetTest.php b/tests/Unit/Dashboard/ImportantMailWidgetTest.php index 9c0c0a3448..244e2b499d 100644 --- a/tests/Unit/Dashboard/ImportantMailWidgetTest.php +++ b/tests/Unit/Dashboard/ImportantMailWidgetTest.php @@ -25,7 +25,7 @@ use OCP\IUserManager; use PHPUnit\Framework\MockObject\MockObject; -class ImportantMailWidgetTest extends TestCase { +final class ImportantMailWidgetTest extends TestCase { private IL10N&MockObject $l10n; private IURLGenerator&MockObject $urlGenerator; diff --git a/tests/Unit/Db/LocalAttachmentTest.php b/tests/Unit/Db/LocalAttachmentTest.php index f8eae85136..98d9706a77 100644 --- a/tests/Unit/Db/LocalAttachmentTest.php +++ b/tests/Unit/Db/LocalAttachmentTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\LocalAttachment; -class LocalAttachmentTest extends TestCase { +final class LocalAttachmentTest extends TestCase { public function testIsDispositionAttachmentOrInlineWithAttachment(): void { $attachment = new LocalAttachment(); $attachment->setDisposition(LocalAttachment::DISPOSITION_ATTACHMENT); diff --git a/tests/Unit/Db/MailAccountTest.php b/tests/Unit/Db/MailAccountTest.php index c167822915..862ad50578 100644 --- a/tests/Unit/Db/MailAccountTest.php +++ b/tests/Unit/Db/MailAccountTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\MailAccount; -class MailAccountTest extends TestCase { +final class MailAccountTest extends TestCase { public function testDefaultsToImap(): void { $account = new MailAccount(); diff --git a/tests/Unit/Db/MailboxTest.php b/tests/Unit/Db/MailboxTest.php index f1c4c76cea..5b94259540 100644 --- a/tests/Unit/Db/MailboxTest.php +++ b/tests/Unit/Db/MailboxTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\Mailbox; -class MailboxTest extends TestCase { +final class MailboxTest extends TestCase { private Mailbox $mailbox; protected function setUp(): void { @@ -21,12 +21,10 @@ protected function setUp(): void { $this->mailbox = new Mailbox(); } - public static function provideCacheBusterData(): array { - return [ - ['new', 'changed', 'vanished', null, 'bbddae86e09069fc10c9f2ac401363b4'], - [null, null, null, null, 'dca1f7641c34734a8cd1c7b1c45abf73'], - [null, null, null, 'state', '3cc6800869b5dcd6495d309a4bd16273'], - ]; + public static function provideCacheBusterData(): \Iterator { + yield ['new', 'changed', 'vanished', null, 'bbddae86e09069fc10c9f2ac401363b4']; + yield [null, null, null, null, 'dca1f7641c34734a8cd1c7b1c45abf73']; + yield [null, null, null, 'state', '3cc6800869b5dcd6495d309a4bd16273']; } /** @dataProvider provideCacheBusterData */ @@ -66,13 +64,11 @@ public function testJsonSerializeCacheBuster( $this->assertEquals($expectedCacheBuster, $json['cacheBuster']); } - public static function provideCachedData(): array { - return [ - ['new', 'changed', 'vanished', null, true], - [null, null, null, 'state', true], - ['new', null, 'vanished', null, false], - [null, null, null, null, false], - ]; + public static function provideCachedData(): \Iterator { + yield ['new', 'changed', 'vanished', null, true]; + yield [null, null, null, 'state', true]; + yield ['new', null, 'vanished', null, false]; + yield [null, null, null, null, false]; } /** @dataProvider provideCachedData */ diff --git a/tests/Unit/Db/MessageRetentionTest.php b/tests/Unit/Db/MessageRetentionTest.php index e3aae5b63b..7d7fd7cbbe 100644 --- a/tests/Unit/Db/MessageRetentionTest.php +++ b/tests/Unit/Db/MessageRetentionTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\MessageRetention; -class MessageRetentionTest extends TestCase { +final class MessageRetentionTest extends TestCase { private MessageRetention $messageRetention; protected function setUp(): void { diff --git a/tests/Unit/Db/MessageTagsTest.php b/tests/Unit/Db/MessageTagsTest.php index e97d23048a..95aa16b0dc 100644 --- a/tests/Unit/Db/MessageTagsTest.php +++ b/tests/Unit/Db/MessageTagsTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\MessageTags; -class MessageTagsTest extends TestCase { +final class MessageTagsTest extends TestCase { private MessageTags $messageTags; protected function setUp(): void { diff --git a/tests/Unit/Db/MessageTest.php b/tests/Unit/Db/MessageTest.php index 924a689f22..0d50d1fb47 100644 --- a/tests/Unit/Db/MessageTest.php +++ b/tests/Unit/Db/MessageTest.php @@ -13,7 +13,7 @@ use OCA\Mail\Db\Message; use OCA\Mail\Service\Avatar\Avatar; -class MessageTest extends TestCase { +final class MessageTest extends TestCase { public function testNewForMessageId(): void { $expected = ''; diff --git a/tests/Unit/Db/OidcProviderMapperTest.php b/tests/Unit/Db/OidcProviderMapperTest.php index 503bec87da..462b9c53b0 100644 --- a/tests/Unit/Db/OidcProviderMapperTest.php +++ b/tests/Unit/Db/OidcProviderMapperTest.php @@ -17,7 +17,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; -class OidcProviderMapperTest extends TestCase { +final class OidcProviderMapperTest extends TestCase { private IDBConnection&MockObject $db; private OidcProviderMapper $mapper; @@ -201,14 +201,12 @@ public function testValidateRejectsZeroPorts(): void { } } - public static function invalidPortProvider(): array { - return [ - 'negative' => [-1], - 'above range' => [65536], - 'far above range' => [99999999], - 'not a number' => ['imap'], - 'missing' => [null], - ]; + public static function invalidPortProvider(): \Iterator { + yield 'negative' => [-1]; + yield 'above range' => [65536]; + yield 'far above range' => [99999999]; + yield 'not a number' => ['imap']; + yield 'missing' => [null]; } /** diff --git a/tests/Unit/Db/OidcProviderTest.php b/tests/Unit/Db/OidcProviderTest.php index ec817a0f26..92e1187401 100644 --- a/tests/Unit/Db/OidcProviderTest.php +++ b/tests/Unit/Db/OidcProviderTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\OidcProvider; -class OidcProviderTest extends TestCase { +final class OidcProviderTest extends TestCase { private function fullProvider(): OidcProvider { $provider = new OidcProvider(); $provider->setId(3); diff --git a/tests/Unit/Db/ProvisioningMapperTest.php b/tests/Unit/Db/ProvisioningMapperTest.php index b3dba8ba90..0b10cddbe6 100644 --- a/tests/Unit/Db/ProvisioningMapperTest.php +++ b/tests/Unit/Db/ProvisioningMapperTest.php @@ -16,7 +16,7 @@ use OCP\IDBConnection; use Psr\Log\NullLogger; -class ProvisioningMapperTest extends TestCase { +final class ProvisioningMapperTest extends TestCase { private ProvisioningMapper $mapper; diff --git a/tests/Unit/Db/ProvisioningTest.php b/tests/Unit/Db/ProvisioningTest.php index 12f3fc0e01..2afaa73a33 100644 --- a/tests/Unit/Db/ProvisioningTest.php +++ b/tests/Unit/Db/ProvisioningTest.php @@ -16,7 +16,7 @@ /** * @covers \OCA\Mail\Db\Provisioning */ -class ProvisioningTest extends TestCase { +final class ProvisioningTest extends TestCase { private function createProvisioning(): Provisioning { $provisioning = new Provisioning(); diff --git a/tests/Unit/Db/TrustedSenderTest.php b/tests/Unit/Db/TrustedSenderTest.php index 4e2acde3f6..645ca21693 100644 --- a/tests/Unit/Db/TrustedSenderTest.php +++ b/tests/Unit/Db/TrustedSenderTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Db\TrustedSender; -class TrustedSenderTest extends TestCase { +final class TrustedSenderTest extends TestCase { private TrustedSender $trustedSender; protected function setUp(): void { diff --git a/tests/Unit/Dns/ResolverTest.php b/tests/Unit/Dns/ResolverTest.php index 9b10ff3f87..4cfd96332a 100644 --- a/tests/Unit/Dns/ResolverTest.php +++ b/tests/Unit/Dns/ResolverTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Dns\Resolver; -class ResolverTest extends TestCase { +final class ResolverTest extends TestCase { private Resolver $resolver; protected function setUp(): void { @@ -21,12 +21,10 @@ protected function setUp(): void { $this->resolver = new Resolver(); } - public function domainSplitData(): array { - return [ - ['nextcloud.com', false], - ['test.ac.at', false], - ['ac.at', true], - ]; + public function domainSplitData(): \Iterator { + yield ['nextcloud.com', false]; + yield ['test.ac.at', false]; + yield ['ac.at', true]; } /** diff --git a/tests/Unit/Events/BeforeImapClientCreatedTest.php b/tests/Unit/Events/BeforeImapClientCreatedTest.php index 1803ca29d4..76a08364d7 100644 --- a/tests/Unit/Events/BeforeImapClientCreatedTest.php +++ b/tests/Unit/Events/BeforeImapClientCreatedTest.php @@ -13,7 +13,7 @@ use OCA\Mail\Account; use OCA\Mail\Events\BeforeImapClientCreated; -class BeforeImapClientCreatedTest extends TestCase { +final class BeforeImapClientCreatedTest extends TestCase { public function testConstructorAndGetter(): void { $account = $this->createStub(Account::class); diff --git a/tests/Unit/Events/BeforeMessageDeletedEventTest.php b/tests/Unit/Events/BeforeMessageDeletedEventTest.php index 5590680665..6b07476763 100644 --- a/tests/Unit/Events/BeforeMessageDeletedEventTest.php +++ b/tests/Unit/Events/BeforeMessageDeletedEventTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Db\Mailbox; use OCA\Mail\Events\BeforeMessageDeletedEvent; -class BeforeMessageDeletedEventTest extends TestCase { +final class BeforeMessageDeletedEventTest extends TestCase { public function testConstructorAndGetters(): void { $account = $this->createStub(Account::class); diff --git a/tests/Unit/Events/DraftMessageCreatedEventTest.php b/tests/Unit/Events/DraftMessageCreatedEventTest.php index dbccdd209e..320204ddba 100644 --- a/tests/Unit/Events/DraftMessageCreatedEventTest.php +++ b/tests/Unit/Events/DraftMessageCreatedEventTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Db\Message; use OCA\Mail\Events\DraftMessageCreatedEvent; -class DraftMessageCreatedEventTest extends TestCase { +final class DraftMessageCreatedEventTest extends TestCase { public function testConstructorAndGetters(): void { $account = $this->createStub(Account::class); $draft = $this->createStub(Message::class); diff --git a/tests/Unit/Events/DraftSavedEventTest.php b/tests/Unit/Events/DraftSavedEventTest.php index f8ee88bc41..817dec660b 100644 --- a/tests/Unit/Events/DraftSavedEventTest.php +++ b/tests/Unit/Events/DraftSavedEventTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Events\DraftSavedEvent; use OCA\Mail\Model\NewMessageData; -class DraftSavedEventTest extends TestCase { +final class DraftSavedEventTest extends TestCase { public function testConstructorWithAllParams(): void { $account = $this->createStub(Account::class); $newMessageData = $this->createStub(NewMessageData::class); diff --git a/tests/Unit/Events/MailboxesSynchronizedEventTest.php b/tests/Unit/Events/MailboxesSynchronizedEventTest.php index 9ac0ea4d6c..8c026bfde3 100644 --- a/tests/Unit/Events/MailboxesSynchronizedEventTest.php +++ b/tests/Unit/Events/MailboxesSynchronizedEventTest.php @@ -13,7 +13,7 @@ use OCA\Mail\Account; use OCA\Mail\Events\MailboxesSynchronizedEvent; -class MailboxesSynchronizedEventTest extends TestCase { +final class MailboxesSynchronizedEventTest extends TestCase { public function testConstructorAndGetter(): void { $account = $this->createStub(Account::class); diff --git a/tests/Unit/Events/MessageDeletedEventTest.php b/tests/Unit/Events/MessageDeletedEventTest.php index a5490bc076..a023f9b1f7 100644 --- a/tests/Unit/Events/MessageDeletedEventTest.php +++ b/tests/Unit/Events/MessageDeletedEventTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Db\Mailbox; use OCA\Mail\Events\MessageDeletedEvent; -class MessageDeletedEventTest extends TestCase { +final class MessageDeletedEventTest extends TestCase { public function testConstructorAndGetters(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); diff --git a/tests/Unit/Events/MessageFlaggedEventTest.php b/tests/Unit/Events/MessageFlaggedEventTest.php index 4b5f9927a4..60c8dd30d6 100644 --- a/tests/Unit/Events/MessageFlaggedEventTest.php +++ b/tests/Unit/Events/MessageFlaggedEventTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Db\Message; use OCA\Mail\Events\MessageFlaggedEvent; -class MessageFlaggedEventTest extends TestCase { +final class MessageFlaggedEventTest extends TestCase { public function testConstructorAndGetters(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); diff --git a/tests/Unit/Events/MessageSentEventTest.php b/tests/Unit/Events/MessageSentEventTest.php index 664c9fabdf..e65853c5f3 100644 --- a/tests/Unit/Events/MessageSentEventTest.php +++ b/tests/Unit/Events/MessageSentEventTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Db\LocalMessage; use OCA\Mail\Events\MessageSentEvent; -class MessageSentEventTest extends TestCase { +final class MessageSentEventTest extends TestCase { public function testConstructorAndGetters(): void { $account = $this->createStub(Account::class); $localMessage = $this->createStub(LocalMessage::class); diff --git a/tests/Unit/Events/NewMessageReceivedEventTest.php b/tests/Unit/Events/NewMessageReceivedEventTest.php index dc1f343a43..d9168b1311 100644 --- a/tests/Unit/Events/NewMessageReceivedEventTest.php +++ b/tests/Unit/Events/NewMessageReceivedEventTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Db\Message; use OCA\Mail\Events\NewMessageReceivedEvent; -class NewMessageReceivedEventTest extends TestCase { +final class NewMessageReceivedEventTest extends TestCase { public function testConstructorAndGetter(): void { $uri = 'imap://user@example.com/INBOX;UID=123'; $account = $this->createStub(Account::class); diff --git a/tests/Unit/Events/NewMessagesSynchronizedTest.php b/tests/Unit/Events/NewMessagesSynchronizedTest.php index 7f3d54c6fc..42eb1f5524 100644 --- a/tests/Unit/Events/NewMessagesSynchronizedTest.php +++ b/tests/Unit/Events/NewMessagesSynchronizedTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Db\Message; use OCA\Mail\Events\NewMessagesSynchronized; -class NewMessagesSynchronizedTest extends TestCase { +final class NewMessagesSynchronizedTest extends TestCase { public function testConstructorAndGetters(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); diff --git a/tests/Unit/Events/OutboxMessageCreatedEventTest.php b/tests/Unit/Events/OutboxMessageCreatedEventTest.php index 7132c9138d..a2d6a4c22d 100644 --- a/tests/Unit/Events/OutboxMessageCreatedEventTest.php +++ b/tests/Unit/Events/OutboxMessageCreatedEventTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Db\Message; use OCA\Mail\Events\OutboxMessageCreatedEvent; -class OutboxMessageCreatedEventTest extends TestCase { +final class OutboxMessageCreatedEventTest extends TestCase { public function testConstructorAndGetters(): void { $account = $this->createStub(Account::class); $message = $this->createStub(Message::class); diff --git a/tests/Unit/Events/SynchronizationEventTest.php b/tests/Unit/Events/SynchronizationEventTest.php index b4cc3380cf..4a10620c56 100644 --- a/tests/Unit/Events/SynchronizationEventTest.php +++ b/tests/Unit/Events/SynchronizationEventTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Events\SynchronizationEvent; use Psr\Log\LoggerInterface; -class SynchronizationEventTest extends TestCase { +final class SynchronizationEventTest extends TestCase { public function testConstructorAndGetters(): void { $account = $this->createStub(Account::class); $logger = $this->createStub(LoggerInterface::class); diff --git a/tests/Unit/FunctionsTest.php b/tests/Unit/FunctionsTest.php index 5b640379ec..1d1212765d 100644 --- a/tests/Unit/FunctionsTest.php +++ b/tests/Unit/FunctionsTest.php @@ -13,7 +13,7 @@ use function OCA\Mail\array_flat_map; use function OCA\Mail\chunk_uid_sequence; -class FunctionsTest extends TestCase { +final class FunctionsTest extends TestCase { public function testFlatMapEmpty(): void { $map = function () { }; diff --git a/tests/Unit/Horde/MimeHeadersTest.php b/tests/Unit/Horde/MimeHeadersTest.php index 62ccf0a49a..70275552c1 100644 --- a/tests/Unit/Horde/MimeHeadersTest.php +++ b/tests/Unit/Horde/MimeHeadersTest.php @@ -17,7 +17,7 @@ * Ensures that Horde_Mime_Headers and its header element parameters * are accessible case-insensitively. */ -class MimeHeadersTest extends TestCase { +final class MimeHeadersTest extends TestCase { private Horde_Mime_Headers $headers; protected function setUp(): void { diff --git a/tests/Unit/Html/ParserTest.php b/tests/Unit/Html/ParserTest.php index 3e76d261dd..884cc500e1 100644 --- a/tests/Unit/Html/ParserTest.php +++ b/tests/Unit/Html/ParserTest.php @@ -13,7 +13,7 @@ use DOMDocument; use OCA\Mail\Html\Parser; -class ParserTest extends TestCase { +final class ParserTest extends TestCase { public function testParseToDomDocument(): void { $html = '

Test content

'; diff --git a/tests/Unit/Html/ProxyHmacGeneratorTest.php b/tests/Unit/Html/ProxyHmacGeneratorTest.php index 4034e49764..c69c568153 100644 --- a/tests/Unit/Html/ProxyHmacGeneratorTest.php +++ b/tests/Unit/Html/ProxyHmacGeneratorTest.php @@ -15,7 +15,7 @@ use OCP\Security\ICrypto; use PHPUnit\Framework\MockObject\MockObject; -class ProxyHmacGeneratorTest extends TestCase { +final class ProxyHmacGeneratorTest extends TestCase { private ProxyHmacGenerator $generator; private IConfig|MockObject $config; private ICrypto|MockObject $crypto; diff --git a/tests/Unit/Http/AttachmentDownloadResponseTest.php b/tests/Unit/Http/AttachmentDownloadResponseTest.php index f63ef75886..cb320d7780 100644 --- a/tests/Unit/Http/AttachmentDownloadResponseTest.php +++ b/tests/Unit/Http/AttachmentDownloadResponseTest.php @@ -1,5 +1,7 @@ getHeaders(); $this->assertEquals($content, $resp->render()); @@ -26,9 +28,7 @@ public function testIt(string $content, string $filename, string $contentType) { $this->assertTrue($pos > 0); } - public function providesResponseData() { - return [ - ['1234567890', 'test.txt', 'text/plain'] - ]; + public function providesResponseData(): \Iterator { + yield ['1234567890', 'test.txt', 'text/plain']; } } diff --git a/tests/Unit/Http/AvatarDownloadResponseTest.php b/tests/Unit/Http/AvatarDownloadResponseTest.php index 269d4a605d..3ab37a0d14 100644 --- a/tests/Unit/Http/AvatarDownloadResponseTest.php +++ b/tests/Unit/Http/AvatarDownloadResponseTest.php @@ -1,5 +1,7 @@ assertEquals('application/octet-stream', $response->getHeaders()['Content-Type']); diff --git a/tests/Unit/Http/HtmlResponseTest.php b/tests/Unit/Http/HtmlResponseTest.php index d50892d3f5..02d750e28e 100644 --- a/tests/Unit/Http/HtmlResponseTest.php +++ b/tests/Unit/Http/HtmlResponseTest.php @@ -1,5 +1,7 @@ assertEquals($content, $plainResp->render()); } - public function providesResponseData() { - return [ - ['1234567890'] - ]; + public function providesResponseData(): \Iterator { + yield ['1234567890']; } } diff --git a/tests/Unit/Http/Middleware/ErrorMiddlewareTest.php b/tests/Unit/Http/Middleware/ErrorMiddlewareTest.php index a0902fa1ab..a83ce9a937 100644 --- a/tests/Unit/Http/Middleware/ErrorMiddlewareTest.php +++ b/tests/Unit/Http/Middleware/ErrorMiddlewareTest.php @@ -26,7 +26,7 @@ use Psr\Log\LoggerInterface; use Throwable; -class ErrorMiddlewareTest extends TestCase { +final class ErrorMiddlewareTest extends TestCase { /** @var IConfig|MockObject */ private $config; @@ -48,7 +48,7 @@ protected function setUp(): void { ); } - public function testDoesNotChangeSuccessfulResponses() { + public function testDoesNotChangeSuccessfulResponses(): void { $response = new JSONResponse(); $controller = $this->createStub(Controller::class); @@ -57,7 +57,7 @@ public function testDoesNotChangeSuccessfulResponses() { $this->assertSame($response, $after); } - public function testDoesNotChangeUntaggedMethodResponses() { + public function testDoesNotChangeUntaggedMethodResponses(): void { $request = $this->createStub(IRequest::class); $controller = new class($request) extends Controller { public function __construct(IRequest $request) { @@ -72,18 +72,16 @@ public function foo() { $this->middleware->afterException($controller, 'foo', $exception); } - public function trappedErrorsData() { - return [ - [new DoesNotExistException('does not exist'), false, Http::STATUS_NOT_FOUND], - [new ServiceException(), true, Http::STATUS_INTERNAL_SERVER_ERROR], - [new NotImplemented(), false, Http::STATUS_NOT_IMPLEMENTED], - ]; + public function trappedErrorsData(): \Iterator { + yield [new DoesNotExistException('does not exist'), false, Http::STATUS_NOT_FOUND]; + yield [new ServiceException(), true, Http::STATUS_INTERNAL_SERVER_ERROR]; + yield [new NotImplemented(), false, Http::STATUS_NOT_IMPLEMENTED]; } /** * @dataProvider trappedErrorsData */ - public function testTrapsErrors($exception, $shouldLog, $expectedStatus) { + public function testTrapsErrors($exception, $shouldLog, $expectedStatus): void { $request = $this->createStub(IRequest::class); $controller = new class($request) extends Controller { public function __construct(IRequest $request) { @@ -105,7 +103,7 @@ public function foo() { $this->assertEquals($expectedStatus, $response->getStatus()); } - public function testSerializesRecursively() { + public function testSerializesRecursively(): void { $inner = new Exception(); $outer = new ServiceException('Test', 0, $inner); $request = $this->createStub(IRequest::class); @@ -129,14 +127,12 @@ public function foo() { $this->assertInstanceOf(JSONResponse::class, $response); } - public function temporaryExceptionsData(): array { - return [ - [new ServiceException('not temporary'), false], - [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception('', Horde_Imap_Client_Exception::DISCONNECT)), true], - [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception('', Horde_Imap_Client_Exception::SERVER_CONNECT)), false], - [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception('', Horde_Imap_Client_Exception::SERVER_READERROR)), true], - [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception('', Horde_Imap_Client_Exception::SERVER_WRITEERROR)), true], - ]; + public function temporaryExceptionsData(): \Iterator { + yield [new ServiceException('not temporary'), false]; + yield [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception('', Horde_Imap_Client_Exception::DISCONNECT)), true]; + yield [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception('', Horde_Imap_Client_Exception::SERVER_CONNECT)), false]; + yield [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception('', Horde_Imap_Client_Exception::SERVER_READERROR)), true]; + yield [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception('', Horde_Imap_Client_Exception::SERVER_WRITEERROR)), true]; } /** diff --git a/tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php b/tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php index 689b832539..1a743eb553 100644 --- a/tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php +++ b/tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php @@ -22,7 +22,7 @@ use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; -class ProvisioningMiddlewareTest extends TestCase { +final class ProvisioningMiddlewareTest extends TestCase { /** @var IUserSession|MockObject */ private $userSession; @@ -49,7 +49,7 @@ protected function setUp(): void { ); } - public function testBeforeControllerNotLoggedIn() { + public function testBeforeControllerNotLoggedIn(): void { $this->credentialStore->expects($this->never()) ->method('getLoginCredentials'); $this->provisioningManager->expects($this->never()) @@ -61,7 +61,7 @@ public function testBeforeControllerNotLoggedIn() { ); } - public function testBeforeControllerNoCredentialsAvailable() { + public function testBeforeControllerNoCredentialsAvailable(): void { $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com' ]); @@ -87,7 +87,7 @@ public function testBeforeControllerNoCredentialsAvailable() { ); } - public function testBeforeControllerNoPasswordAvailable() { + public function testBeforeControllerNoPasswordAvailable(): void { $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com' ]); @@ -117,7 +117,7 @@ public function testBeforeControllerNoPasswordAvailable() { ); } - public function testBeforeControllerPasswordlessSignin() { + public function testBeforeControllerPasswordlessSignin(): void { $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com' ]); @@ -145,7 +145,7 @@ public function testBeforeControllerPasswordlessSignin() { ); } - public function testBeforeControllerNoConfigAvailable() { + public function testBeforeControllerNoConfigAvailable(): void { $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com' ]); @@ -166,7 +166,7 @@ public function testBeforeControllerNoConfigAvailable() { ); } - public function testBeforeController() { + public function testBeforeController(): void { $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com' ]); diff --git a/tests/Unit/Http/ProxyDownloadResponseTest.php b/tests/Unit/Http/ProxyDownloadResponseTest.php index a24d3c403d..0ab803cdb6 100644 --- a/tests/Unit/Http/ProxyDownloadResponseTest.php +++ b/tests/Unit/Http/ProxyDownloadResponseTest.php @@ -1,5 +1,7 @@ getHeaders(); $this->assertEquals($content, $resp->render()); @@ -29,9 +31,7 @@ public function testIt($content, $filename, $contentType) { $this->assertTrue($pos > 0); } - public function providesResponseData() { - return [ - ['1234567890', 'test.txt', 'text/plain'] - ]; + public function providesResponseData(): \Iterator { + yield ['1234567890', 'test.txt', 'text/plain']; } } diff --git a/tests/Unit/IMAP/Charset/ConverterTest.php b/tests/Unit/IMAP/Charset/ConverterTest.php index 107ebb499b..978b53c7aa 100644 --- a/tests/Unit/IMAP/Charset/ConverterTest.php +++ b/tests/Unit/IMAP/Charset/ConverterTest.php @@ -16,7 +16,7 @@ use function fwrite; use function mb_convert_encoding; -class ConverterTest extends TestCase { +final class ConverterTest extends TestCase { public Converter $converter; protected function setUp(): void { diff --git a/tests/Unit/IMAP/FolderMapperTest.php b/tests/Unit/IMAP/FolderMapperTest.php index a1429ea97a..8de95b2713 100644 --- a/tests/Unit/IMAP/FolderMapperTest.php +++ b/tests/Unit/IMAP/FolderMapperTest.php @@ -22,7 +22,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class FolderMapperTest extends TestCase { +final class FolderMapperTest extends TestCase { /** @var FolderMapper */ private $mapper; @@ -282,7 +282,7 @@ public function testGetFolderStatusInaccessibleMailbox(): void { self::assertNull($stats); } - public function testDetectSpecialUseFromAttributes() { + public function testDetectSpecialUseFromAttributes(): void { $folders = [ $this->createMock(Folder::class), ]; @@ -327,10 +327,8 @@ public function testDetectSpecialUseFromFolderName(?string $delimiter, int $coun $this->mapper->detectFolderSpecialUse($folders); } - public function dataDetectSpecialUseFromFolderName(): array { - return [ - 'delimiter .' => ['.', 2], - 'delimiter null' => [null, 1], - ]; + public function dataDetectSpecialUseFromFolderName(): \Iterator { + yield 'delimiter .' => ['.', 2]; + yield 'delimiter null' => [null, 1]; } } diff --git a/tests/Unit/IMAP/HordeImapClientTest.php b/tests/Unit/IMAP/HordeImapClientTest.php index fe7668f721..88fe3fa598 100644 --- a/tests/Unit/IMAP/HordeImapClientTest.php +++ b/tests/Unit/IMAP/HordeImapClientTest.php @@ -36,7 +36,7 @@ protected function imapLogin() { } } -class HordeImapClientTest extends TestCase { +final class HordeImapClientTest extends TestCase { private IMemcacheWithTTL|MockObject $cache; private ITimeFactory|MockObject $timeFactory; private TestableHordeImapClient $client; diff --git a/tests/Unit/IMAP/ImapFlagTest.php b/tests/Unit/IMAP/ImapFlagTest.php index 3abc3e0740..d3fe0af7e3 100644 --- a/tests/Unit/IMAP/ImapFlagTest.php +++ b/tests/Unit/IMAP/ImapFlagTest.php @@ -13,7 +13,7 @@ use OCA\Mail\IMAP\ImapFlag; use PHPUnit\Framework\Attributes\DataProvider; -class ImapFlagTest extends TestCase { +final class ImapFlagTest extends TestCase { private ImapFlag $imapFlag; diff --git a/tests/Unit/IMAP/ImapMailboxConnectorTest.php b/tests/Unit/IMAP/ImapMailboxConnectorTest.php index c9862ff7bd..f4de91fd02 100644 --- a/tests/Unit/IMAP/ImapMailboxConnectorTest.php +++ b/tests/Unit/IMAP/ImapMailboxConnectorTest.php @@ -24,7 +24,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class ImapMailboxConnectorTest extends TestCase { +final class ImapMailboxConnectorTest extends TestCase { private ProtocolFactory&MockObject $protocolFactory; private MailboxSync&MockObject $mailboxSync; private FolderMapper&MockObject $folderMapper; diff --git a/tests/Unit/IMAP/ImapMessageConnectorTest.php b/tests/Unit/IMAP/ImapMessageConnectorTest.php index 653b32bb2c..b70364c638 100644 --- a/tests/Unit/IMAP/ImapMessageConnectorTest.php +++ b/tests/Unit/IMAP/ImapMessageConnectorTest.php @@ -34,7 +34,7 @@ * connection to the mail server is leaked (see moveMessages/deleteMessages/flagMessages/ * tagMessages/isPermflagsEnabled). */ -class ImapMessageConnectorTest extends TestCase { +final class ImapMessageConnectorTest extends TestCase { private ProtocolFactory&MockObject $protocolFactory; private ImapToDbSynchronizer&MockObject $synchronizer; private FolderMapper&MockObject $imapMailboxMapper; @@ -68,11 +68,9 @@ protected function setUp(): void { ->willReturn($this->client); } - public static function bodyLoadingOptions(): array { - return [ - 'without body' => [false], - 'with body' => [true], - ]; + public static function bodyLoadingOptions(): \Iterator { + yield 'without body' => [false]; + yield 'with body' => [true]; } /** @dataProvider bodyLoadingOptions */ diff --git a/tests/Unit/IMAP/ImapTransmissionConnectorTest.php b/tests/Unit/IMAP/ImapTransmissionConnectorTest.php index 147033ea86..78a4c99362 100644 --- a/tests/Unit/IMAP/ImapTransmissionConnectorTest.php +++ b/tests/Unit/IMAP/ImapTransmissionConnectorTest.php @@ -44,7 +44,7 @@ use Psr\Log\LoggerInterface; use ReflectionMethod; -class ImapTransmissionConnectorTest extends TestCase { +final class ImapTransmissionConnectorTest extends TestCase { private ProtocolFactory|MockObject $protocolFactory; private TransmissionService|MockObject $transmissionService; @@ -219,7 +219,7 @@ public function testBuildAttachmentMimePartImipOmitsContentDisposition(): void { $this->assertEquals('', $part->getDisposition()); } - public function testApplySmimeSignature() { + public function testApplySmimeSignature(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); @@ -241,7 +241,7 @@ public function testApplySmimeSignature() { $this->assertEquals(LocalMessage::STATUS_RAW, $localMessage->getStatus()); } - public function testApplySmimeSignatureNoCertId() { + public function testApplySmimeSignatureNoCertId(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); @@ -260,7 +260,7 @@ public function testApplySmimeSignatureNoCertId() { $this->assertEquals(LocalMessage::STATUS_SMIME_SIGN_NO_CERT_ID, $localMessage->getStatus()); } - public function testApplySmimeSignatureNoCertFound() { + public function testApplySmimeSignatureNoCertFound(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); @@ -281,7 +281,7 @@ public function testApplySmimeSignatureNoCertFound() { $this->assertEquals(LocalMessage::STATUS_SMIME_SIGN_CERT, $localMessage->getStatus()); } - public function testApplySmimeSignatureFailedSigning() { + public function testApplySmimeSignatureFailedSigning(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); @@ -305,7 +305,7 @@ public function testApplySmimeSignatureFailedSigning() { $this->assertEquals(LocalMessage::STATUS_SMIME_SIGN_FAIL, $localMessage->getStatus()); } - public function testApplySmimeEncryption() { + public function testApplySmimeEncryption(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); @@ -333,7 +333,7 @@ public function testApplySmimeEncryption() { $this->assertEquals(LocalMessage::STATUS_RAW, $localMessage->getStatus()); } - public function testApplySmimeEncryptionNoCertId() { + public function testApplySmimeEncryptionNoCertId(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); @@ -350,7 +350,7 @@ public function testApplySmimeEncryptionNoCertId() { $this->assertEquals(LocalMessage::STATUS_SMIME_ENCRYPT_NO_CERT_ID, $localMessage->getStatus()); } - public function testApplySmimeEncryptionNoAddressCerts() { + public function testApplySmimeEncryptionNoAddressCerts(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); @@ -376,7 +376,7 @@ public function testApplySmimeEncryptionNoAddressCerts() { $this->assertEquals(LocalMessage::STATUS_SMIME_ENCRYT_FAIL, $localMessage->getStatus()); } - public function testApplySmimeEncryptionNoCert() { + public function testApplySmimeEncryptionNoCert(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); @@ -405,7 +405,7 @@ public function testApplySmimeEncryptionNoCert() { $this->assertEquals(LocalMessage::STATUS_SMIME_ENCRYPT_CERT, $localMessage->getStatus()); } - public function testApplySmimeEncryptionEncryptFail() { + public function testApplySmimeEncryptionEncryptFail(): void { $send = new \Horde_Mime_Part(); $send->setContents('Test'); $localMessage = new LocalMessage(); diff --git a/tests/Unit/IMAP/MailboxSyncTest.php b/tests/Unit/IMAP/MailboxSyncTest.php index 0e2d8ff779..33077d1c1c 100644 --- a/tests/Unit/IMAP/MailboxSyncTest.php +++ b/tests/Unit/IMAP/MailboxSyncTest.php @@ -32,7 +32,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\NullLogger; -class MailboxSyncTest extends TestCase { +final class MailboxSyncTest extends TestCase { /** @var MailboxMapper|MockObject */ private $mailboxMapper; @@ -78,7 +78,7 @@ protected function setUp(): void { ); } - public function testSyncSkipped() { + public function testSyncSkipped(): void { $account = $this->createMock(Account::class); $mailAccount = new MailAccount(); $mailAccount->setLastMailboxSync(100000 - 100); diff --git a/tests/Unit/IMAP/MessageMapperTest.php b/tests/Unit/IMAP/MessageMapperTest.php index a05219e767..52e51b8ea6 100644 --- a/tests/Unit/IMAP/MessageMapperTest.php +++ b/tests/Unit/IMAP/MessageMapperTest.php @@ -33,7 +33,7 @@ use Psr\Log\LoggerInterface; use function range; -class MessageMapperTest extends TestCase { +final class MessageMapperTest extends TestCase { /** @var LoggerInterface|MockObject */ private $logger; @@ -653,7 +653,7 @@ public function testFindAllNoUidCandidates(): void { self::assertEmpty($result['messages']); } - public function testGetFlagged() { + public function testGetFlagged(): void { /** @var Horde_Imap_Client_Socket|MockObject $imapClient */ $imapClient = $this->createMock(Horde_Imap_Client_Socket::class); $mailbox = new Mailbox(); @@ -677,7 +677,7 @@ public function testGetFlagged() { $this->assertEquals($result, [1]); } - public function testGetFlaggedNoMatches() { + public function testGetFlaggedNoMatches(): void { /** @var Horde_Imap_Client_Socket|MockObject $imapClient */ $imapClient = $this->createMock(Horde_Imap_Client_Socket::class); $mailbox = new Mailbox(); @@ -700,7 +700,7 @@ public function testGetFlaggedNoMatches() { $this->assertEquals($result, []); } - public function testGetFlaggedSearchResultUnexpectedStructure() { + public function testGetFlaggedSearchResultUnexpectedStructure(): void { /** @var Horde_Imap_Client_Socket|MockObject $imapClient */ $imapClient = $this->createMock(Horde_Imap_Client_Socket::class); $mailbox = new Mailbox(); @@ -809,17 +809,15 @@ public function testGetBodyStructureUsesMessageHeaderFallback(): void { $this->assertEquals($bodyText, $data[$messageId]->getPreviewText()); } - public function isImipMessageProvider(): array { - return [ - 'google request' => ['request_google', true], - 'outlook.com request' => ['request_outlook_com', true], - // Proton Mail Bridge strips the `method=` parameter from the - // text/calendar Content-Type header during E2E re-assembly. The - // message is still an iMIP REQUEST — the method lives in the ICS - // body. Must still be flagged as iMIP so downstream processing - // picks it up. - 'proton bridge request (method= stripped)' => ['request_proton_bridge', true], - ]; + public function isImipMessageProvider(): \Iterator { + yield 'google request' => ['request_google', true]; + yield 'outlook.com request' => ['request_outlook_com', true]; + // Proton Mail Bridge strips the `method=` parameter from the + // text/calendar Content-Type header during E2E re-assembly. The + // message is still an iMIP REQUEST — the method lives in the ICS + // body. Must still be flagged as iMIP so downstream processing + // picks it up. + yield 'proton bridge request (method= stripped)' => ['request_proton_bridge', true]; } public function testGetAttachmentFilenameFromContentDisposition(): void { diff --git a/tests/Unit/IMAP/PreviewEnhancerTest.php b/tests/Unit/IMAP/PreviewEnhancerTest.php index 02591ceaea..055661f077 100644 --- a/tests/Unit/IMAP/PreviewEnhancerTest.php +++ b/tests/Unit/IMAP/PreviewEnhancerTest.php @@ -23,7 +23,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class PreviewEnhancerTest extends TestCase { +final class PreviewEnhancerTest extends TestCase { /** @var ProtocolFactory|MockObject */ private $protocolFactory; diff --git a/tests/Unit/IMAP/Sync/RequestTest.php b/tests/Unit/IMAP/Sync/RequestTest.php index 1335d9e8ca..f5d621e5c1 100644 --- a/tests/Unit/IMAP/Sync/RequestTest.php +++ b/tests/Unit/IMAP/Sync/RequestTest.php @@ -1,5 +1,7 @@ request = new Request($this->requestId, $this->mailbox, $this->syncToken, []); } - public function testGetId() { + public function testGetId(): void { $this->assertEquals($this->requestId, $this->request->getId()); } - public function testGetMailbox() { + public function testGetMailbox(): void { $this->assertEquals($this->mailbox, $this->request->getMailbox()); } - public function testGetSyncToken() { + public function testGetSyncToken(): void { $this->assertEquals($this->syncToken, $this->request->getToken()); } } diff --git a/tests/Unit/IMAP/Sync/ResponseTest.php b/tests/Unit/IMAP/Sync/ResponseTest.php index 00ee00bdc6..f1b61405f4 100644 --- a/tests/Unit/IMAP/Sync/ResponseTest.php +++ b/tests/Unit/IMAP/Sync/ResponseTest.php @@ -1,5 +1,7 @@ provider(); $this->providerMapper->expects($this->once()) diff --git a/tests/Unit/Integration/OidcIntegration/OidcConnectTest.php b/tests/Unit/Integration/OidcIntegration/OidcConnectTest.php index 53693b910a..13f5449521 100644 --- a/tests/Unit/Integration/OidcIntegration/OidcConnectTest.php +++ b/tests/Unit/Integration/OidcIntegration/OidcConnectTest.php @@ -15,7 +15,7 @@ /** * Exchanging an authorization code for tokens. */ -class OidcConnectTest extends OidcIntegrationTestCase { +final class OidcConnectTest extends OidcIntegrationTestCase { public function testFinishConnectStoresTokens(): void { $provider = $this->provider(); $account = $this->account('alice@example.com'); diff --git a/tests/Unit/Integration/OidcIntegration/OidcEndpointsTest.php b/tests/Unit/Integration/OidcIntegration/OidcEndpointsTest.php index 607ce26873..d03d7453b9 100644 --- a/tests/Unit/Integration/OidcIntegration/OidcEndpointsTest.php +++ b/tests/Unit/Integration/OidcIntegration/OidcEndpointsTest.php @@ -16,7 +16,7 @@ /** * Resolving authorization/token/introspection endpoints from discovery or manual config. */ -class OidcEndpointsTest extends OidcIntegrationTestCase { +final class OidcEndpointsTest extends OidcIntegrationTestCase { public function testGetDiscoveryUsesCache(): void { $provider = $this->provider(); $this->cache->method('get') diff --git a/tests/Unit/Integration/OidcIntegration/OidcProviderCrudTest.php b/tests/Unit/Integration/OidcIntegration/OidcProviderCrudTest.php index d5347458a2..edec49554d 100644 --- a/tests/Unit/Integration/OidcIntegration/OidcProviderCrudTest.php +++ b/tests/Unit/Integration/OidcIntegration/OidcProviderCrudTest.php @@ -16,7 +16,7 @@ /** * Admin CRUD for the configured providers. */ -class OidcProviderCrudTest extends OidcIntegrationTestCase { +final class OidcProviderCrudTest extends OidcIntegrationTestCase { public function testGetProvidersDelegatesToMapper(): void { $this->providerMapper->expects($this->once()) ->method('getAll') diff --git a/tests/Unit/Integration/OidcIntegration/OidcReauthTest.php b/tests/Unit/Integration/OidcIntegration/OidcReauthTest.php index cdaa88ff46..4488f54c70 100644 --- a/tests/Unit/Integration/OidcIntegration/OidcReauthTest.php +++ b/tests/Unit/Integration/OidcIntegration/OidcReauthTest.php @@ -15,7 +15,7 @@ /** * Detecting a grant that can no longer be renewed, so the user is asked to reconnect. */ -class OidcReauthTest extends OidcIntegrationTestCase { +final class OidcReauthTest extends OidcIntegrationTestCase { public function testRefreshFlagsReauthWhenNoRefreshTokenIssued(): void { $account = $this->expiredAccount(null); $this->providerMapper->method('findByEmailDomain')->willReturn($this->provider()); diff --git a/tests/Unit/Integration/OidcIntegration/OidcRefreshTest.php b/tests/Unit/Integration/OidcIntegration/OidcRefreshTest.php index 5b0083113e..4debc34977 100644 --- a/tests/Unit/Integration/OidcIntegration/OidcRefreshTest.php +++ b/tests/Unit/Integration/OidcIntegration/OidcRefreshTest.php @@ -15,7 +15,7 @@ /** * Renewing the access token with the stored refresh token. */ -class OidcRefreshTest extends OidcIntegrationTestCase { +final class OidcRefreshTest extends OidcIntegrationTestCase { public function testRefreshNoopWhenNotAuthorized(): void { $account = $this->account('alice@example.com'); diff --git a/tests/Unit/JMAP/Exception/JmapExceptionTest.php b/tests/Unit/JMAP/Exception/JmapExceptionTest.php index fa240094e7..16d0721af4 100644 --- a/tests/Unit/JMAP/Exception/JmapExceptionTest.php +++ b/tests/Unit/JMAP/Exception/JmapExceptionTest.php @@ -13,17 +13,15 @@ use JmapClient\Responses\ResponseException; use OCA\Mail\JMAP\Exception\JmapException; -class JmapExceptionTest extends TestCase { - public static function transientProvider(): array { - return [ - 'server failure' => [ResponseException::SERVER_FAIL, false, true], - 'server unavailable' => [ResponseException::SERVER_UNAVAILABLE, false, true], - 'partial server failure' => [ResponseException::SERVER_PARTIAL_FAIL, false, true], - 'rate limit' => ['rateLimit', false, true], - 'permanent rejection' => ['forbiddenToSend', false, false], - 'unknown type' => ['somethingNew', false, false], - 'uncertain outcome' => [ResponseException::SERVER_FAIL, true, false], - ]; +final class JmapExceptionTest extends TestCase { + public static function transientProvider(): \Iterator { + yield 'server failure' => [ResponseException::SERVER_FAIL, false, true]; + yield 'server unavailable' => [ResponseException::SERVER_UNAVAILABLE, false, true]; + yield 'partial server failure' => [ResponseException::SERVER_PARTIAL_FAIL, false, true]; + yield 'rate limit' => ['rateLimit', false, true]; + yield 'permanent rejection' => ['forbiddenToSend', false, false]; + yield 'unknown type' => ['somethingNew', false, false]; + yield 'uncertain outcome' => [ResponseException::SERVER_FAIL, true, false]; } /** diff --git a/tests/Unit/JMAP/JmapClientAdapterTest.php b/tests/Unit/JMAP/JmapClientAdapterTest.php index 220d172d60..9dbe42cc20 100644 --- a/tests/Unit/JMAP/JmapClientAdapterTest.php +++ b/tests/Unit/JMAP/JmapClientAdapterTest.php @@ -17,7 +17,7 @@ use OCP\Http\Client\IResponse; use PHPUnit\Framework\MockObject\MockObject; -class JmapClientAdapterTest extends TestCase { +final class JmapClientAdapterTest extends TestCase { private IClient&MockObject $ncClient; private HttpFactory $factory; private JmapClientAdapter $client; diff --git a/tests/Unit/JMAP/JmapClientFactoryTest.php b/tests/Unit/JMAP/JmapClientFactoryTest.php index 9b9a2feeed..7ae2b732f3 100644 --- a/tests/Unit/JMAP/JmapClientFactoryTest.php +++ b/tests/Unit/JMAP/JmapClientFactoryTest.php @@ -21,7 +21,7 @@ use OCP\Security\ICrypto; use PHPUnit\Framework\MockObject\MockObject; -class JmapClientFactoryTest extends TestCase { +final class JmapClientFactoryTest extends TestCase { private ICrypto&MockObject $crypto; private IConfig&MockObject $config; private IClientService&MockObject $clientService; diff --git a/tests/Unit/JMAP/JmapMailboxAdapterTest.php b/tests/Unit/JMAP/JmapMailboxAdapterTest.php index 1e3b4ecb39..106f2fa8f9 100644 --- a/tests/Unit/JMAP/JmapMailboxAdapterTest.php +++ b/tests/Unit/JMAP/JmapMailboxAdapterTest.php @@ -15,7 +15,7 @@ use OCA\Mail\JMAP\JmapMailboxAdapter; use PHPUnit\Framework\MockObject\MockObject; -class JmapMailboxAdapterTest extends TestCase { +final class JmapMailboxAdapterTest extends TestCase { private JmapMailboxAdapter $adapter; protected function setUp(): void { diff --git a/tests/Unit/JMAP/JmapMailboxConnectorTest.php b/tests/Unit/JMAP/JmapMailboxConnectorTest.php index 636c06aa02..873bf5a5dc 100644 --- a/tests/Unit/JMAP/JmapMailboxConnectorTest.php +++ b/tests/Unit/JMAP/JmapMailboxConnectorTest.php @@ -20,7 +20,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class JmapMailboxConnectorTest extends TestCase { +final class JmapMailboxConnectorTest extends TestCase { private JmapOperationsService&MockObject $jmapOperationsService; private MailboxMapper&MockObject $mailboxMapper; private JmapMailboxConnector $connector; diff --git a/tests/Unit/JMAP/JmapMessageAdapterTest.php b/tests/Unit/JMAP/JmapMessageAdapterTest.php index 3a2d951ff1..1b9281abff 100644 --- a/tests/Unit/JMAP/JmapMessageAdapterTest.php +++ b/tests/Unit/JMAP/JmapMessageAdapterTest.php @@ -19,7 +19,7 @@ use OCA\Mail\Service\Html; use PHPUnit\Framework\MockObject\MockObject; -class JmapMessageAdapterTest extends TestCase { +final class JmapMessageAdapterTest extends TestCase { private JmapMessageAdapter $adapter; protected function setUp(): void { @@ -216,13 +216,11 @@ public function testFallsBackToSenderWhenFromMissing(): void { self::assertSame('sender@example.com', $from->getEmail()); } - public static function aiGeneratedHeaderProvider(): array { - return [ - 'absent' => [null, false], - 'set' => ['1', true], - 'set with whitespace' => [' 1 ', true], - 'other value' => ['0', false], - ]; + public static function aiGeneratedHeaderProvider(): \Iterator { + yield 'absent' => [null, false]; + yield 'set' => ['1', true]; + yield 'set with whitespace' => [' 1 ', true]; + yield 'other value' => ['0', false]; } /** diff --git a/tests/Unit/JMAP/JmapMessageConnectorTest.php b/tests/Unit/JMAP/JmapMessageConnectorTest.php index ee99909a2b..7fedeed398 100644 --- a/tests/Unit/JMAP/JmapMessageConnectorTest.php +++ b/tests/Unit/JMAP/JmapMessageConnectorTest.php @@ -22,7 +22,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class JmapMessageConnectorTest extends TestCase { +final class JmapMessageConnectorTest extends TestCase { private JmapOperationsService&MockObject $jmapOperationsService; private JmapMessageConnector $connector; private Account&MockObject $account; diff --git a/tests/Unit/JMAP/JmapTransmissionConnectorTest.php b/tests/Unit/JMAP/JmapTransmissionConnectorTest.php index b9b80811bf..1549c23311 100644 --- a/tests/Unit/JMAP/JmapTransmissionConnectorTest.php +++ b/tests/Unit/JMAP/JmapTransmissionConnectorTest.php @@ -30,7 +30,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class JmapTransmissionConnectorTest extends TestCase { +final class JmapTransmissionConnectorTest extends TestCase { private JmapOperationsService|MockObject $jmapOperationsService; private TransmissionService|MockObject $transmissionService; @@ -191,16 +191,14 @@ public function testSendMessage(): void { $this->assertSame(LocalMessage::STATUS_PROCESSED, $message->getStatus()); } - public static function sendFailureProvider(): array { - return [ - 'transient server error' => [new JmapException('', ResponseException::SERVER_UNAVAILABLE), LocalMessage::STATUS_SMPT_SEND_FAIL], - 'rate limit' => [new JmapException('', 'rateLimit'), LocalMessage::STATUS_RATELIMIT], - 'too many recipients' => [new JmapException('', 'tooManyRecipients'), LocalMessage::STATUS_TOO_MANY_RECIPIENTS], - 'permanent rejection' => [new JmapException('', 'forbiddenToSend'), LocalMessage::STATUS_ERROR], - 'unknown error type' => [new JmapException('', 'somethingNew'), LocalMessage::STATUS_ERROR], - 'delivery uncertain' => [new JmapException('', ResponseException::SERVER_FAIL, true), LocalMessage::STATUS_ERROR], - 'not submitted' => [new ServiceException('upload failed'), LocalMessage::STATUS_SMPT_SEND_FAIL], - ]; + public static function sendFailureProvider(): \Iterator { + yield 'transient server error' => [new JmapException('', ResponseException::SERVER_UNAVAILABLE), LocalMessage::STATUS_SMPT_SEND_FAIL]; + yield 'rate limit' => [new JmapException('', 'rateLimit'), LocalMessage::STATUS_RATELIMIT]; + yield 'too many recipients' => [new JmapException('', 'tooManyRecipients'), LocalMessage::STATUS_TOO_MANY_RECIPIENTS]; + yield 'permanent rejection' => [new JmapException('', 'forbiddenToSend'), LocalMessage::STATUS_ERROR]; + yield 'unknown error type' => [new JmapException('', 'somethingNew'), LocalMessage::STATUS_ERROR]; + yield 'delivery uncertain' => [new JmapException('', ResponseException::SERVER_FAIL, true), LocalMessage::STATUS_ERROR]; + yield 'not submitted' => [new ServiceException('upload failed'), LocalMessage::STATUS_SMPT_SEND_FAIL]; } /** diff --git a/tests/Unit/Job/FollowUpClassifierJobTest.php b/tests/Unit/Job/FollowUpClassifierJobTest.php index 1315676079..97dbe7ebdd 100644 --- a/tests/Unit/Job/FollowUpClassifierJobTest.php +++ b/tests/Unit/Job/FollowUpClassifierJobTest.php @@ -26,7 +26,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class FollowUpClassifierJobTest extends TestCase { +final class FollowUpClassifierJobTest extends TestCase { private ProtocolFactory&MockObject $protocolFactory; private FollowUpClassifierJob $job; diff --git a/tests/Unit/Job/PreviewEnhancementProcessingJobTest.php b/tests/Unit/Job/PreviewEnhancementProcessingJobTest.php index ba01304d61..edfc76e593 100644 --- a/tests/Unit/Job/PreviewEnhancementProcessingJobTest.php +++ b/tests/Unit/Job/PreviewEnhancementProcessingJobTest.php @@ -1,5 +1,7 @@ 1]; } - public function testRun() { + public function testRun(): void { $mailbox = new Mailbox(); $mailbox->setId(self::$argument['mailboxId']); $mailbox->setName('INBOX'); @@ -109,7 +109,7 @@ public function testRun() { $this->job->run(self::$argument); } - public function testRunNoMailbox() { + public function testRunNoMailbox(): void { $e = new DoesNotExistException('does not exist'); $this->mailboxMapper->expects($this->once()) @@ -134,7 +134,7 @@ public function testRunNoMailbox() { $this->job->run(self::$argument); } - public function testRunNoAccount() { + public function testRunNoAccount(): void { $mailbox = new Mailbox(); $mailbox->setId(self::$argument['mailboxId']); $mailbox->setName('INBOX'); @@ -165,7 +165,7 @@ public function testRunNoAccount() { $this->job->run(self::$argument); } - public function testNoPermflags() { + public function testNoPermflags(): void { $mailbox = new Mailbox(); $mailbox->setId(self::$argument['mailboxId']); $mailbox->setName('INBOX'); @@ -195,7 +195,7 @@ public function testNoPermflags() { $this->job->run(self::$argument); } - public function testErrorOnMigrateOnImap() { + public function testErrorOnMigrateOnImap(): void { $mailbox = new Mailbox(); $mailbox->setId(self::$argument['mailboxId']); $mailbox->setName('INBOX'); @@ -232,7 +232,7 @@ public function testErrorOnMigrateOnImap() { $this->job->run(self::$argument); } - public function testErrorOnMigrateDbToImap() { + public function testErrorOnMigrateDbToImap(): void { $mailbox = new Mailbox(); $mailbox->setId(self::$argument['mailboxId']); $mailbox->setName('INBOX'); @@ -269,7 +269,7 @@ public function testErrorOnMigrateDbToImap() { $this->job->run(self::$argument); } - public function testErrorOnOnBoth() { + public function testErrorOnOnBoth(): void { $mailbox = new Mailbox(); $mailbox->setId(self::$argument['mailboxId']); $mailbox->setName('INBOX'); diff --git a/tests/Unit/Job/TrashRetentionJobTest.php b/tests/Unit/Job/TrashRetentionJobTest.php index 14bb40fd94..adf0803077 100644 --- a/tests/Unit/Job/TrashRetentionJobTest.php +++ b/tests/Unit/Job/TrashRetentionJobTest.php @@ -27,7 +27,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class TrashRetentionJobTest extends TestCase { +final class TrashRetentionJobTest extends TestCase { private ProtocolFactory&MockObject $protocolFactory; private const ARGUMENT = null; @@ -79,7 +79,7 @@ protected function setUp(): void { ); } - public function testRun() { + public function testRun(): void { $dbAccount = new MailAccount(); $dbAccount->setTrashRetentionDays(60); $dbAccount->setTrashMailboxId(42); @@ -114,7 +114,7 @@ public function testRun() { $this->job->run(self::ARGUMENT); } - public function testRunWithoutRetention() { + public function testRunWithoutRetention(): void { $dbAccount = new MailAccount(); $dbAccount->setTrashRetentionDays(null); @@ -129,7 +129,7 @@ public function testRunWithoutRetention() { $this->job->run(self::ARGUMENT); } - public function testRunWith0DaysRetention() { + public function testRunWith0DaysRetention(): void { $dbAccount = new MailAccount(); $dbAccount->setTrashRetentionDays(0); @@ -142,7 +142,7 @@ public function testRunWith0DaysRetention() { $this->job->run(self::ARGUMENT); } - public function testRunWithNegativeRetention() { + public function testRunWithNegativeRetention(): void { $dbAccount = new MailAccount(); $dbAccount->setTrashRetentionDays(-1); @@ -155,7 +155,7 @@ public function testRunWithNegativeRetention() { $this->job->run(self::ARGUMENT); } - public function testRunWithoutTrash() { + public function testRunWithoutTrash(): void { $dbAccount = new MailAccount(); $dbAccount->setTrashRetentionDays(60); $dbAccount->setTrashMailboxId(null); @@ -171,7 +171,7 @@ public function testRunWithoutTrash() { $this->job->run(self::ARGUMENT); } - public function testRunWithNonExistingTrash() { + public function testRunWithNonExistingTrash(): void { $dbAccount = new MailAccount(); $dbAccount->setTrashRetentionDays(60); $dbAccount->setTrashMailboxId(42); @@ -189,7 +189,7 @@ public function testRunWithNonExistingTrash() { $this->job->run(self::ARGUMENT); } - public function testRunRetentionCleanupCalledAfterDelete() { + public function testRunRetentionCleanupCalledAfterDelete(): void { $dbAccount = new MailAccount(); $dbAccount->setTrashRetentionDays(60); $dbAccount->setTrashMailboxId(42); diff --git a/tests/Unit/Listener/AddressCollectionListenerTest.php b/tests/Unit/Listener/AddressCollectionListenerTest.php index fc87300f90..be0c0fb63c 100644 --- a/tests/Unit/Listener/AddressCollectionListenerTest.php +++ b/tests/Unit/Listener/AddressCollectionListenerTest.php @@ -26,7 +26,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class AddressCollectionListenerTest extends TestCase { +final class AddressCollectionListenerTest extends TestCase { /** @var IUserPreferences|MockObject */ private $preferences; @@ -57,7 +57,7 @@ protected function setUp(): void { ); } - public function testHandleUnrelated() { + public function testHandleUnrelated(): void { $event = new Event(); $this->addressCollector->expects($this->never()) ->method('addAddresses'); @@ -68,7 +68,7 @@ public function testHandleUnrelated() { $this->addToAssertionCount(1); } - public function testHandleOptOut() { + public function testHandleOptOut(): void { $account = $this->createConfiguredMock(Account::class, [ 'getUserId' => 'test' ]); @@ -83,7 +83,7 @@ public function testHandleOptOut() { $this->listener->handle($event); } - public function testHandle() { + public function testHandle(): void { /** @var Account|MockObject $account */ $account = $this->createConfiguredMock(Account::class, [ 'getUserId' => 'test' diff --git a/tests/Unit/Listener/DeleteDraftListenerTest.php b/tests/Unit/Listener/DeleteDraftListenerTest.php index f6cd49e2dc..7f4ccdfc5c 100644 --- a/tests/Unit/Listener/DeleteDraftListenerTest.php +++ b/tests/Unit/Listener/DeleteDraftListenerTest.php @@ -29,7 +29,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class DeleteDraftListenerTest extends TestCase { +final class DeleteDraftListenerTest extends TestCase { /** @var ProtocolFactory|MockObject */ private $protocolFactory; diff --git a/tests/Unit/Listener/FollowUpClassifierListenerTest.php b/tests/Unit/Listener/FollowUpClassifierListenerTest.php index 29c38843b8..5955b9ef0c 100644 --- a/tests/Unit/Listener/FollowUpClassifierListenerTest.php +++ b/tests/Unit/Listener/FollowUpClassifierListenerTest.php @@ -24,7 +24,7 @@ use OCP\BackgroundJob\IJobList; use OCP\TaskProcessing\TaskTypes\TextToText; -class FollowUpClassifierListenerTest extends TestCase { +final class FollowUpClassifierListenerTest extends TestCase { private FollowUpClassifierListener $listener; /** @var IJobList|MockObject */ diff --git a/tests/Unit/Listener/HamReportListenerTest.php b/tests/Unit/Listener/HamReportListenerTest.php index abb67f8d89..b42855c69c 100644 --- a/tests/Unit/Listener/HamReportListenerTest.php +++ b/tests/Unit/Listener/HamReportListenerTest.php @@ -21,7 +21,7 @@ use OCA\Mail\Listener\SpamReportListener; use OCP\EventDispatcher\Event; -class HamReportListenerTest extends TestCase { +final class HamReportListenerTest extends TestCase { /** @var ServiceMockObject */ private $serviceMock; diff --git a/tests/Unit/Listener/InteractionListenerTest.php b/tests/Unit/Listener/InteractionListenerTest.php index ed7d523543..cf6383a38b 100644 --- a/tests/Unit/Listener/InteractionListenerTest.php +++ b/tests/Unit/Listener/InteractionListenerTest.php @@ -21,7 +21,7 @@ use OCP\IUser; use function class_exists; -class InteractionListenerTest extends TestCase { +final class InteractionListenerTest extends TestCase { /** @var ServiceMockObject */ private $serviceMock; diff --git a/tests/Unit/Listener/MailboxesSynchronizedSpecialMailboxesUpdaterTest.php b/tests/Unit/Listener/MailboxesSynchronizedSpecialMailboxesUpdaterTest.php index 36f079a247..645a99b701 100644 --- a/tests/Unit/Listener/MailboxesSynchronizedSpecialMailboxesUpdaterTest.php +++ b/tests/Unit/Listener/MailboxesSynchronizedSpecialMailboxesUpdaterTest.php @@ -19,7 +19,7 @@ use OCA\Mail\Listener\MailboxesSynchronizedSpecialMailboxesUpdater; use Psr\Log\LoggerInterface; -class MailboxesSynchronizedSpecialMailboxesUpdaterTest extends TestCase { +final class MailboxesSynchronizedSpecialMailboxesUpdaterTest extends TestCase { private MailAccountMapper $mailAccountMapper; private MailboxMapper $mailboxMapper; private MailboxesSynchronizedSpecialMailboxesUpdater $listener; diff --git a/tests/Unit/Listener/MessageCacheUpdaterListenerTest.php b/tests/Unit/Listener/MessageCacheUpdaterListenerTest.php index aeb8ad73c0..2b7b93222c 100644 --- a/tests/Unit/Listener/MessageCacheUpdaterListenerTest.php +++ b/tests/Unit/Listener/MessageCacheUpdaterListenerTest.php @@ -19,7 +19,7 @@ use OCA\Mail\Listener\MessageCacheUpdaterListener; use OCP\EventDispatcher\Event; -class MessageCacheUpdaterListenerTest extends TestCase { +final class MessageCacheUpdaterListenerTest extends TestCase { /** @var ServiceMockObject */ private $serviceMock; @@ -33,7 +33,7 @@ protected function setUp(): void { $this->listener = $this->serviceMock->getService(); } - public function testHandleUnrelated() { + public function testHandleUnrelated(): void { $event = new Event(); $this->serviceMock->getParameter('mapper') ->expects($this->never()) @@ -42,7 +42,7 @@ public function testHandleUnrelated() { $this->listener->handle($event); } - public function testHandleMessageFlagged() { + public function testHandleMessageFlagged(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); $message = new Message(); @@ -64,7 +64,7 @@ public function testHandleMessageFlagged() { $this->assertTrue($message->getFlagJunk()); } - public function testHandleMessageFlaggedTag() { + public function testHandleMessageFlaggedTag(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); $message = new Message(); diff --git a/tests/Unit/Listener/MessageKnownSinceListenerTest.php b/tests/Unit/Listener/MessageKnownSinceListenerTest.php index 8d350270b2..9c00423c4b 100644 --- a/tests/Unit/Listener/MessageKnownSinceListenerTest.php +++ b/tests/Unit/Listener/MessageKnownSinceListenerTest.php @@ -21,7 +21,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use PHPUnit\Framework\MockObject\MockObject; -class MessageKnownSinceListenerTest extends TestCase { +final class MessageKnownSinceListenerTest extends TestCase { /** @var MessageRetentionMapper|MockObject */ private $messageRetentionMapper; diff --git a/tests/Unit/Listener/MoveJunkListenerTest.php b/tests/Unit/Listener/MoveJunkListenerTest.php index 557d91de54..45ef3ce39a 100644 --- a/tests/Unit/Listener/MoveJunkListenerTest.php +++ b/tests/Unit/Listener/MoveJunkListenerTest.php @@ -23,7 +23,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\Test\TestLogger; -class MoveJunkListenerTest extends TestCase { +final class MoveJunkListenerTest extends TestCase { private MailManager $mailManager; private MailboxMapper $mailboxMapper; private LoggerInterface $logger; diff --git a/tests/Unit/Listener/NewMessagesSummarizeListenerTest.php b/tests/Unit/Listener/NewMessagesSummarizeListenerTest.php index 7201c18655..8bda5df7cf 100644 --- a/tests/Unit/Listener/NewMessagesSummarizeListenerTest.php +++ b/tests/Unit/Listener/NewMessagesSummarizeListenerTest.php @@ -25,7 +25,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\Test\TestLogger; -class NewMessagesSummarizeListenerTest extends TestCase { +final class NewMessagesSummarizeListenerTest extends TestCase { private const NOW = 1_750_000_000; private LoggerInterface $logger; @@ -102,16 +102,14 @@ public function testLlmDisabled(): void { $this->listener->handle($event); } - public static function provideSkippedSpecialUses(): array { - return [ - 'all' => ['["all"]'], - 'archive' => ['["archive"]'], - 'drafts' => ['["drafts"]'], - 'flagged' => ['["flagged"]'], - 'junk' => ['["junk"]'], - 'sent' => ['["sent"]'], - 'trash' => ['["trash"]'], - ]; + public static function provideSkippedSpecialUses(): \Iterator { + yield 'all' => ['["all"]']; + yield 'archive' => ['["archive"]']; + yield 'drafts' => ['["drafts"]']; + yield 'flagged' => ['["flagged"]']; + yield 'junk' => ['["junk"]']; + yield 'sent' => ['["sent"]']; + yield 'trash' => ['["trash"]']; } /** @@ -127,15 +125,13 @@ public function testSkipsSpecialUseMailbox(string $specialUse): void { $this->listener->handle($event); } - public static function provideAccountMailboxSetters(): array { - return [ - 'archive' => ['setArchiveMailboxId'], - 'drafts' => ['setDraftsMailboxId'], - 'junk' => ['setJunkMailboxId'], - 'sent' => ['setSentMailboxId'], - 'snooze' => ['setSnoozeMailboxId'], - 'trash' => ['setTrashMailboxId'], - ]; + public static function provideAccountMailboxSetters(): \Iterator { + yield 'archive' => ['setArchiveMailboxId']; + yield 'drafts' => ['setDraftsMailboxId']; + yield 'junk' => ['setJunkMailboxId']; + yield 'sent' => ['setSentMailboxId']; + yield 'snooze' => ['setSnoozeMailboxId']; + yield 'trash' => ['setTrashMailboxId']; } /** diff --git a/tests/Unit/Listener/OauthTokenRefreshListenerTest.php b/tests/Unit/Listener/OauthTokenRefreshListenerTest.php index a1959c1f60..be09a5a535 100644 --- a/tests/Unit/Listener/OauthTokenRefreshListenerTest.php +++ b/tests/Unit/Listener/OauthTokenRefreshListenerTest.php @@ -21,7 +21,7 @@ use OCP\EventDispatcher\Event; use PHPUnit\Framework\MockObject\MockObject; -class OauthTokenRefreshListenerTest extends TestCase { +final class OauthTokenRefreshListenerTest extends TestCase { private GoogleIntegration&MockObject $googleIntegration; private MicrosoftIntegration&MockObject $microsoftIntegration; private OidcIntegration&MockObject $oidcIntegration; diff --git a/tests/Unit/Listener/OptionalIndicesListenerTest.php b/tests/Unit/Listener/OptionalIndicesListenerTest.php index dc650e1ded..4472e0be53 100644 --- a/tests/Unit/Listener/OptionalIndicesListenerTest.php +++ b/tests/Unit/Listener/OptionalIndicesListenerTest.php @@ -18,7 +18,7 @@ use OCP\IDBConnection; use PHPUnit\Framework\MockObject\MockObject; -class OptionalIndicesListenerTest extends TestCase { +final class OptionalIndicesListenerTest extends TestCase { private IConfig&MockObject $config; private IDBConnection&MockObject $connection; diff --git a/tests/Unit/Listener/SpamReportListenerTest.php b/tests/Unit/Listener/SpamReportListenerTest.php index 91480121d3..3432895ac5 100644 --- a/tests/Unit/Listener/SpamReportListenerTest.php +++ b/tests/Unit/Listener/SpamReportListenerTest.php @@ -20,7 +20,7 @@ use OCA\Mail\Listener\SpamReportListener; use OCP\EventDispatcher\Event; -class SpamReportListenerTest extends TestCase { +final class SpamReportListenerTest extends TestCase { /** @var ServiceMockObject */ private $serviceMock; diff --git a/tests/Unit/Listener/TaskProcessingListenerTest.php b/tests/Unit/Listener/TaskProcessingListenerTest.php index a31b41dd15..66f40fa3fd 100644 --- a/tests/Unit/Listener/TaskProcessingListenerTest.php +++ b/tests/Unit/Listener/TaskProcessingListenerTest.php @@ -20,7 +20,7 @@ use OCP\TaskProcessing\TaskTypes\TextToTextSummary; use Psr\Log\LoggerInterface; -class TaskProcessingListenerTest extends TestCase { +final class TaskProcessingListenerTest extends TestCase { /** @var TaskProcessingListener */ private $listener; diff --git a/tests/Unit/Listener/UserDeletedListenerTest.php b/tests/Unit/Listener/UserDeletedListenerTest.php index 1175b7f1e5..57570dfa86 100644 --- a/tests/Unit/Listener/UserDeletedListenerTest.php +++ b/tests/Unit/Listener/UserDeletedListenerTest.php @@ -23,7 +23,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class UserDeletedListenerTest extends TestCase { +final class UserDeletedListenerTest extends TestCase { private AccountService&MockObject $accountService; private TextBlockService&MockObject $textBlockService; diff --git a/tests/Unit/Migration/FixCollectedAddressesTest.php b/tests/Unit/Migration/FixCollectedAddressesTest.php index b681f371ef..7767d3a287 100644 --- a/tests/Unit/Migration/FixCollectedAddressesTest.php +++ b/tests/Unit/Migration/FixCollectedAddressesTest.php @@ -1,5 +1,7 @@ repairStep = new FixCollectedAddresses($this->mapper); } - public function testRunNothingToMigrate() { + public function testRunNothingToMigrate(): void { $address1 = new CollectedAddress(); $address1->setId(100); $address1->setEmail('user1@domain1.com'); @@ -61,7 +63,7 @@ public function testRunNothingToMigrate() { $this->repairStep->run($this->output); } - public function testRunMigrateOne() { + public function testRunMigrateOne(): void { $address1 = new CollectedAddress(); $address1->setId(100); $address1->setEmail('"User 1" '); @@ -92,7 +94,7 @@ public function testRunMigrateOne() { $this->assertEquals('User 1', $address1->getDisplayName()); } - public function testRunDeleteFaulty() { + public function testRunDeleteFaulty(): void { $address1 = new CollectedAddress(); $address1->setId(100); $address1->setEmail('"User 1 >>'); diff --git a/tests/Unit/Migration/MigrateImportantFromImapAndDbTest.php b/tests/Unit/Migration/MigrateImportantFromImapAndDbTest.php index 9274b37760..8a4a7a8c91 100644 --- a/tests/Unit/Migration/MigrateImportantFromImapAndDbTest.php +++ b/tests/Unit/Migration/MigrateImportantFromImapAndDbTest.php @@ -1,5 +1,7 @@ createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); $uids = [1,2,3]; @@ -69,7 +71,7 @@ public function testMigrateImportantOnImap() { $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } - public function testMigrateImportantOnImapNoUids() { + public function testMigrateImportantOnImapNoUids(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); $uids = []; @@ -86,7 +88,7 @@ public function testMigrateImportantOnImapNoUids() { $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } - public function testMigrateImportantOnImapExceptionGetFlagged() { + public function testMigrateImportantOnImapExceptionGetFlagged(): void { $account = $this->createStub(Account::class); $mailbox = $this->createStub(Mailbox::class); $e = new Horde_Imap_Client_Exception('', 0); @@ -104,7 +106,7 @@ public function testMigrateImportantOnImapExceptionGetFlagged() { $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } - public function testMigrateImportantOnImapExceptionOnFlag() { + public function testMigrateImportantOnImapExceptionOnFlag(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setName('INBOX'); @@ -146,7 +148,7 @@ public function migrateImportantFromDb() { $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } - public function testMigrateImportantFromDbNoUids() { + public function testMigrateImportantFromDbNoUids(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setId(1); @@ -164,7 +166,7 @@ public function testMigrateImportantFromDbNoUids() { $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } - public function testMigrateImportantFromDbExceptionOnFlag() { + public function testMigrateImportantFromDbExceptionOnFlag(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setId(1); diff --git a/tests/Unit/Migration/Version5120Date20260820000000Test.php b/tests/Unit/Migration/Version5120Date20260820000000Test.php index 90178ec4a2..bb74b21afe 100644 --- a/tests/Unit/Migration/Version5120Date20260820000000Test.php +++ b/tests/Unit/Migration/Version5120Date20260820000000Test.php @@ -17,7 +17,7 @@ use OCP\Migration\IOutput; use PHPUnit\Framework\MockObject\MockObject; -class Version5120Date20260820000000Test extends TestCase { +final class Version5120Date20260820000000Test extends TestCase { private IAppConfig&MockObject $appConfig; private IOutput&MockObject $output; diff --git a/tests/Unit/Model/EventDataTest.php b/tests/Unit/Model/EventDataTest.php index b664f6e8e0..c462d24be7 100644 --- a/tests/Unit/Model/EventDataTest.php +++ b/tests/Unit/Model/EventDataTest.php @@ -12,7 +12,7 @@ use OCA\Mail\Model\EventData; use PHPUnit\Framework\TestCase; -class EventDataTest extends TestCase { +final class EventDataTest extends TestCase { public function testAll(): void { $data = new EventData('sum', 'des'); diff --git a/tests/Unit/Model/IMAPMessageTest.php b/tests/Unit/Model/IMAPMessageTest.php index d5d707e741..95bf956601 100644 --- a/tests/Unit/Model/IMAPMessageTest.php +++ b/tests/Unit/Model/IMAPMessageTest.php @@ -24,7 +24,7 @@ use OCP\IURLGenerator; use RuntimeException; -class IMAPMessageTest extends TestCase { +final class IMAPMessageTest extends TestCase { /** @var Html|MockObject */ private $htmlService; @@ -32,7 +32,7 @@ protected function setUp(): void { $this->htmlService = $this->createMock(Html::class); } - public function testIconvHtmlMessage() { + public function testIconvHtmlMessage(): void { $urlGenerator = $this->getMockBuilder(IURLGenerator::class) ->disableOriginalConstructor() ->getMock(); @@ -166,7 +166,7 @@ public function testGetHtmlBodyIsNotMemoizedWhenSanitizingFails(): void { $this->assertSame('

456

', $retry); } - public function testSerialize() { + public function testSerialize(): void { $data = new Horde_Imap_Client_Data_Fetch(); $data->setUid(1234); $m = new IMAPMessage( diff --git a/tests/Unit/Model/MessageTest.php b/tests/Unit/Model/MessageTest.php index 5ffb5ee525..08b8ce5465 100644 --- a/tests/Unit/Model/MessageTest.php +++ b/tests/Unit/Model/MessageTest.php @@ -16,7 +16,7 @@ use OCA\Mail\AddressList; use OCA\Mail\Model\Message; -class MessageTest extends TestCase { +final class MessageTest extends TestCase { protected $message; protected function setUp(): void { @@ -25,7 +25,7 @@ protected function setUp(): void { $this->message = new Message(); } - public function testFlags() { + public function testFlags(): void { $flags = [ 'seen', 'flagged', @@ -36,7 +36,7 @@ public function testFlags() { $this->assertSame($flags, $this->message->getFlags()); } - public function testFrom() { + public function testFrom(): void { $from = new AddressList([ Address::fromRaw('Fritz', 'fritz@domain.tld'), ]); @@ -46,7 +46,7 @@ public function testFrom() { $this->assertSame($from, $this->message->getFrom()); } - public function testTo() { + public function testTo(): void { $expected = [ 'alice@example.com', 'Bob ', @@ -58,11 +58,11 @@ public function testTo() { $this->assertEquals($to, $this->message->getTo()); } - public function testEmptyTo() { + public function testEmptyTo(): void { $this->assertEquals(new AddressList(), $this->message->getTo()); } - public function testCC() { + public function testCC(): void { $raw = [ 'alice@example.com', 'Bob ', @@ -74,11 +74,11 @@ public function testCC() { $this->assertEquals($cc, $this->message->getCC()); } - public function testEmptyCC() { + public function testEmptyCC(): void { $this->assertEquals(new AddressList(), $this->message->getCC()); } - public function testBCC() { + public function testBCC(): void { $raw = [ 'alice@example.com', 'Bob ', @@ -90,11 +90,11 @@ public function testBCC() { $this->assertEquals($bcc, $this->message->getBCC()); } - public function testEmptyBCC() { + public function testEmptyBCC(): void { $this->assertEquals(new AddressList(), $this->message->getBCC()); } - public function testRepliedMessage() { + public function testRepliedMessage(): void { $reply = '9609171955.AA24342@cmstex2.maths.umanitoba.ca'; $this->message->setInReplyTo($reply); @@ -103,7 +103,7 @@ public function testRepliedMessage() { $this->assertSame($reply, $actual); } - public function testSubject() { + public function testSubject(): void { $subject = 'test message'; $this->message->setSubject($subject); @@ -111,11 +111,11 @@ public function testSubject() { $this->assertSame($subject, $this->message->getSubject()); } - public function testEmptySubject() { + public function testEmptySubject(): void { $this->assertSame('', $this->message->getSubject()); } - public function testContent() { + public function testContent(): void { $content = 'hello!'; $this->message->setContent($content); @@ -123,7 +123,7 @@ public function testContent() { $this->assertSame($content, $this->message->getContent()); } - public function testAttachments() { + public function testAttachments(): void { $name = 'coffee.jpg'; $mimeType = 'image/jpeg'; $contents = 'file content'; diff --git a/tests/Unit/Model/NewMessageDataTest.php b/tests/Unit/Model/NewMessageDataTest.php index b26756561b..a66c07fda7 100644 --- a/tests/Unit/Model/NewMessageDataTest.php +++ b/tests/Unit/Model/NewMessageDataTest.php @@ -1,5 +1,7 @@ createStub(Account::class); $to = '"Test" '; $cc = ''; @@ -34,7 +36,7 @@ public function testConstructionFromSimpleRequestData() { $this->assertTrue($messageData->isMdnRequested()); } - public function testConstructionFromComplexRequestData() { + public function testConstructionFromComplexRequestData(): void { $account = $this->createStub(Account::class); $to = '"Test" , test2@domain.de'; $cc = 'test2@domain.at'; diff --git a/tests/Unit/Model/RepliedMessageTest.php b/tests/Unit/Model/RepliedMessageTest.php index b148f53da1..74464607db 100644 --- a/tests/Unit/Model/RepliedMessageTest.php +++ b/tests/Unit/Model/RepliedMessageTest.php @@ -1,5 +1,7 @@ createStub(Account::class); $message = new Message(); @@ -23,7 +25,7 @@ public function testGetAccount() { $this->assertEquals($account, $data->getAccount()); } - public function testGetMessage() { + public function testGetMessage(): void { /** @var Account|MockObject $account */ $account = $this->createStub(Account::class); $message = new Message(); diff --git a/tests/Unit/Notification/NotifierTest.php b/tests/Unit/Notification/NotifierTest.php index 9ac2fb716d..c73229b793 100644 --- a/tests/Unit/Notification/NotifierTest.php +++ b/tests/Unit/Notification/NotifierTest.php @@ -18,7 +18,7 @@ use OCP\Notification\UnknownNotificationException; use PHPUnit\Framework\MockObject\MockObject; -class NotifierTest extends TestCase { +final class NotifierTest extends TestCase { private IFactory&MockObject $factory; private IURLGenerator&MockObject $url; private IL10N&MockObject $l10n; diff --git a/tests/Unit/Protocol/ConnectionPoolTest.php b/tests/Unit/Protocol/ConnectionPoolTest.php index c90b20f4c2..a003bad11e 100644 --- a/tests/Unit/Protocol/ConnectionPoolTest.php +++ b/tests/Unit/Protocol/ConnectionPoolTest.php @@ -22,7 +22,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class ConnectionPoolTest extends TestCase { +final class ConnectionPoolTest extends TestCase { private IMAPClientFactory&MockObject $imapClientFactory; private JmapClientFactory&MockObject $jmapClientFactory; private ConnectionPool $pool; diff --git a/tests/Unit/Protocol/ProtocolFactoryTest.php b/tests/Unit/Protocol/ProtocolFactoryTest.php index a85f40eb7d..48dcbf6439 100644 --- a/tests/Unit/Protocol/ProtocolFactoryTest.php +++ b/tests/Unit/Protocol/ProtocolFactoryTest.php @@ -24,7 +24,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Container\ContainerInterface; -class ProtocolFactoryTest extends TestCase { +final class ProtocolFactoryTest extends TestCase { private IMAPClientFactory&MockObject $imapClientFactory; private JmapClientFactory&MockObject $jmapClientFactory; private ConnectionPool&MockObject $connectionPool; diff --git a/tests/Unit/Provider/Command/MessageSendTest.php b/tests/Unit/Provider/Command/MessageSendTest.php index db2481f13a..048726504f 100644 --- a/tests/Unit/Provider/Command/MessageSendTest.php +++ b/tests/Unit/Provider/Command/MessageSendTest.php @@ -27,7 +27,7 @@ use OCP\Mail\Provider\Message; use PHPUnit\Framework\MockObject\MockObject; -class MessageSendTest extends TestCase { +final class MessageSendTest extends TestCase { private IConfig&MockObject $config; private ITimeFactory&MockObject $time; diff --git a/tests/Unit/Provider/MailProviderTest.php b/tests/Unit/Provider/MailProviderTest.php index 8872ed2c4c..d28c60d6b9 100644 --- a/tests/Unit/Provider/MailProviderTest.php +++ b/tests/Unit/Provider/MailProviderTest.php @@ -23,7 +23,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -class MailProviderTest extends TestCase { +final class MailProviderTest extends TestCase { private ContainerInterface&MockObject $containerInterface; private AccountService&MockObject $accountService; diff --git a/tests/Unit/Provider/MailServiceTest.php b/tests/Unit/Provider/MailServiceTest.php index 94ee98b73b..b59314107e 100644 --- a/tests/Unit/Provider/MailServiceTest.php +++ b/tests/Unit/Provider/MailServiceTest.php @@ -14,7 +14,7 @@ use OCP\Mail\Provider\Address; use Psr\Container\ContainerInterface; -class MailServiceTest extends TestCase { +final class MailServiceTest extends TestCase { private MailService $mailService; private Address $primaryAddress; diff --git a/tests/Unit/SMTP/SmtpClientFactoryTest.php b/tests/Unit/SMTP/SmtpClientFactoryTest.php index 1e9e918874..cc8936a211 100644 --- a/tests/Unit/SMTP/SmtpClientFactoryTest.php +++ b/tests/Unit/SMTP/SmtpClientFactoryTest.php @@ -19,7 +19,7 @@ use OCP\Security\ICrypto; use PHPUnit\Framework\MockObject\MockObject; -class SmtpClientFactoryTest extends TestCase { +final class SmtpClientFactoryTest extends TestCase { /** @var IConfig|MockObject */ private $config; @@ -42,7 +42,7 @@ protected function setUp(): void { $this->factory = new SmtpClientFactory($this->config, $this->crypto, $this->hostNameFactory); } - public function testSmtpTransport() { + public function testSmtpTransport(): void { $mailAccount = new MailAccount([ 'smtpHost' => 'smtp.domain.tld', 'smtpPort' => 25, diff --git a/tests/Unit/Search/FilteringProviderTest.php b/tests/Unit/Search/FilteringProviderTest.php index 2ac170afa4..b3af952503 100644 --- a/tests/Unit/Search/FilteringProviderTest.php +++ b/tests/Unit/Search/FilteringProviderTest.php @@ -33,7 +33,7 @@ /** * @covers \OCA\Mail\Search\FilteringProvider */ -class FilteringProviderTest extends TestCase { +final class FilteringProviderTest extends TestCase { private IMailSearch&MockObject $mailSearch; private IL10N&MockObject $l10n; private IDateTimeFormatter $dateTimeFormatter; diff --git a/tests/Unit/Send/AntiAbuseHandlerTest.php b/tests/Unit/Send/AntiAbuseHandlerTest.php index a590d40bb0..65cb6b9a58 100644 --- a/tests/Unit/Send/AntiAbuseHandlerTest.php +++ b/tests/Unit/Send/AntiAbuseHandlerTest.php @@ -21,7 +21,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class AntiAbuseHandlerTest extends TestCase { +final class AntiAbuseHandlerTest extends TestCase { private IUserManager|MockObject $userManager; private MockObject|AntiAbuseService $antiAbuseService; private LoggerInterface|MockObject $logger; diff --git a/tests/Unit/Send/ChainTest.php b/tests/Unit/Send/ChainTest.php index 89c1bbcfad..f2a5ceccb4 100644 --- a/tests/Unit/Send/ChainTest.php +++ b/tests/Unit/Send/ChainTest.php @@ -20,7 +20,7 @@ use OCA\Mail\Service\Attachment\AttachmentService; use PHPUnit\Framework\MockObject\MockObject; -class ChainTest extends TestCase { +final class ChainTest extends TestCase { private Chain $chain; private MockObject|AntiAbuseHandler $antiAbuseHandler; private SendHandler|MockObject $sendHandler; diff --git a/tests/Unit/Send/FlagRepliedMessageHandlerTest.php b/tests/Unit/Send/FlagRepliedMessageHandlerTest.php index 3e499f6da9..d562cc7e79 100644 --- a/tests/Unit/Send/FlagRepliedMessageHandlerTest.php +++ b/tests/Unit/Send/FlagRepliedMessageHandlerTest.php @@ -23,7 +23,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class FlagRepliedMessageHandlerTest extends TestCase { +final class FlagRepliedMessageHandlerTest extends TestCase { private MailboxMapper|MockObject $mailboxMapper; private LoggerInterface|MockObject $loggerInterface; private MockObject|MailManager $mailManager; diff --git a/tests/Unit/Send/SendHandlerTest.php b/tests/Unit/Send/SendHandlerTest.php index f3d04f41ee..420333b2dd 100644 --- a/tests/Unit/Send/SendHandlerTest.php +++ b/tests/Unit/Send/SendHandlerTest.php @@ -24,7 +24,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class SendHandlerTest extends TestCase { +final class SendHandlerTest extends TestCase { private MockObject|ProtocolFactory $protocolFactory; private MockObject|IEventDispatcher $eventDispatcher; private MockObject|MailboxMapper $mailboxMapper; diff --git a/tests/Unit/Service/AccountServiceTest.php b/tests/Unit/Service/AccountServiceTest.php index fa840fc4bd..a2b680dfcc 100644 --- a/tests/Unit/Service/AccountServiceTest.php +++ b/tests/Unit/Service/AccountServiceTest.php @@ -1,5 +1,7 @@ client = $this->createMock(Horde_Imap_Client_Socket::class); } - public function testFindByUserId() { + public function testFindByUserId(): void { $this->mapper->expects(self::exactly(2)) ->method('findByUserId') ->willReturnMap([ @@ -111,7 +113,7 @@ public function testFindByUserId() { $this->assertEquals($expected, $actual); } - public function testFind() { + public function testFind(): void { $accountId = 123; $this->mapper->expects($this->once()) @@ -125,7 +127,7 @@ public function testFind() { $this->assertEquals($expected, $actual); } - public function testFindById() { + public function testFindById(): void { $accountId = 123; $this->mapper->expects($this->once()) @@ -139,7 +141,7 @@ public function testFindById() { $this->assertEquals($expected, $actual); } - public function testDelete() { + public function testDelete(): void { $accountId = 33; $this->mapper->expects($this->once()) @@ -153,7 +155,7 @@ public function testDelete() { $this->accountService->delete($this->user, $accountId); } - public function testDeleteByAccountId() { + public function testDeleteByAccountId(): void { $accountId = 33; $this->mapper->expects($this->once()) @@ -167,7 +169,7 @@ public function testDeleteByAccountId() { $this->accountService->deleteByAccountId($accountId); } - public function testSave() { + public function testSave(): void { $mailAccount = new MailAccount(); $mailAccount->setId(1000); $mailAccount->setUserId('user1'); @@ -191,7 +193,7 @@ public function testSave() { $this->assertEquals($mailAccount, $actual); } - public function testUpdateSignature() { + public function testUpdateSignature(): void { $id = 3; $uid = 'ian'; $signature = 'sig'; @@ -209,7 +211,7 @@ public function testUpdateSignature() { $this->accountService->updateSignature($id, $uid, $signature); } - public function testAccountsFailedConnection() { + public function testAccountsFailedConnection(): void { $accountId = 1; $this->protocolFactory->expects($this->once()) ->method('testConnection') @@ -221,7 +223,7 @@ public function testAccountsFailedConnection() { $connected = $this->accountService->testAccountConnection($this->user, $accountId); $this->assertFalse($connected); } - public function testAccountsSuccesfulConnection() { + public function testAccountsSuccesfulConnection(): void { $accountId = 1; $this->protocolFactory->expects($this->once()) ->method('testConnection'); diff --git a/tests/Unit/Service/AiIntegrations/CacheTest.php b/tests/Unit/Service/AiIntegrations/CacheTest.php index e6f6aa0bd6..4e5e7aa118 100644 --- a/tests/Unit/Service/AiIntegrations/CacheTest.php +++ b/tests/Unit/Service/AiIntegrations/CacheTest.php @@ -15,7 +15,7 @@ use OCP\ICacheFactory; use PHPUnit\Framework\MockObject\MockObject; -class CacheTest extends TestCase { +final class CacheTest extends TestCase { private ICacheFactory&MockObject $cacheFactory; private ICache&MockObject $cacheImpl; @@ -93,14 +93,12 @@ public function testResetFailures(): void { $this->cache->resetFailures('key'); } - public static function backoffTtlDataProvider(): array { - return [ - [0, Cache::FAILURE_INITIAL_TTL], - [1, Cache::FAILURE_INITIAL_TTL], - [2, Cache::FAILURE_INITIAL_TTL * 2], - [3, Cache::FAILURE_INITIAL_TTL * 4], - [1000, Cache::FAILURE_MAX_TTL], - ]; + public static function backoffTtlDataProvider(): \Iterator { + yield [0, Cache::FAILURE_INITIAL_TTL]; + yield [1, Cache::FAILURE_INITIAL_TTL]; + yield [2, Cache::FAILURE_INITIAL_TTL * 2]; + yield [3, Cache::FAILURE_INITIAL_TTL * 4]; + yield [1000, Cache::FAILURE_MAX_TTL]; } /** diff --git a/tests/Unit/Service/AiIntegrationsServiceTest.php b/tests/Unit/Service/AiIntegrationsServiceTest.php index 2f8a8712e5..9ae26aef4e 100644 --- a/tests/Unit/Service/AiIntegrationsServiceTest.php +++ b/tests/Unit/Service/AiIntegrationsServiceTest.php @@ -37,7 +37,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\NullLogger; -class AiIntegrationsServiceTest extends TestCase { +final class AiIntegrationsServiceTest extends TestCase { private IAppConfig|MockObject $appConfig; private NullLogger|MockObject $logger; @@ -199,12 +199,10 @@ public function testSmartReplyMarkdownFormat(): void { $this->assertSame($expected, $cachedResult); } - public static function provideInvalidSmartReplyOutput(): array { - return [ - 'missing reply2' => ['{"reply1":"ok"}'], - 'numeric reply' => ['{"reply1":"ok","reply2":123}'], - 'list' => ['[]'], - ]; + public static function provideInvalidSmartReplyOutput(): \Iterator { + yield 'missing reply2' => ['{"reply1":"ok"}']; + yield 'numeric reply' => ['{"reply1":"ok","reply2":123}']; + yield 'list' => ['[]']; } /** @@ -284,17 +282,15 @@ public function testLlmUnavailable(): void { } - public function isLlmProcessingEnabledDataProvider(): array { - return [ - [false, false], - [true, true], - ]; + public function isLlmProcessingEnabledDataProvider(): \Iterator { + yield [false, false]; + yield [true, true]; } /** * @dataProvider isLlmProcessingEnabledDataProvider */ - public function testIsLlmProcessingEnabled(bool $appConfigValue, bool $expected) { + public function testIsLlmProcessingEnabled(bool $appConfigValue, bool $expected): void { $this->appConfig->expects(self::once()) ->method('getValueBool') ->with(Application::APP_ID, ConfigLexicon::LLM_PROCESSING, false) @@ -410,16 +406,14 @@ public function testGenerateEventDataFreePromptUnavailable(): void { self::assertNull($result); } - public static function provideInvalidEventDataOutput(): array { - return [ - 'invalid JSON' => ['Jason'], - 'missing title' => ['{"agenda":"* Q&A"}'], - 'missing agenda' => ['{"title":"Meeting"}'], - 'null title' => ['{"title":null,"agenda":"* Q&A"}'], - 'numeric agenda' => ['{"title":"Meeting","agenda":123}'], - 'list' => ['[]'], - 'scalar' => ['"Meeting"'], - ]; + public static function provideInvalidEventDataOutput(): \Iterator { + yield 'invalid JSON' => ['Jason']; + yield 'missing title' => ['{"agenda":"* Q&A"}']; + yield 'missing agenda' => ['{"title":"Meeting"}']; + yield 'null title' => ['{"title":null,"agenda":"* Q&A"}']; + yield 'numeric agenda' => ['{"title":"Meeting","agenda":123}']; + yield 'list' => ['[]']; + yield 'scalar' => ['"Meeting"']; } /** @@ -751,13 +745,11 @@ public function testRequiresFollowUp(): void { $this->assertTrue($result); } - public static function provideUnusableFollowUpOutput(): array { - return [ - 'failed task' => ['{"expectsReply": false}', TaskProcessingTask::STATUS_FAILED], - 'missing output' => [null, TaskProcessingTask::STATUS_SUCCESSFUL], - 'empty output' => ['', TaskProcessingTask::STATUS_SUCCESSFUL], - 'whitespace-only output' => [' ', TaskProcessingTask::STATUS_SUCCESSFUL], - ]; + public static function provideUnusableFollowUpOutput(): \Iterator { + yield 'failed task' => ['{"expectsReply": false}', TaskProcessingTask::STATUS_FAILED]; + yield 'missing output' => [null, TaskProcessingTask::STATUS_SUCCESSFUL]; + yield 'empty output' => ['', TaskProcessingTask::STATUS_SUCCESSFUL]; + yield 'whitespace-only output' => [' ', TaskProcessingTask::STATUS_SUCCESSFUL]; } /** diff --git a/tests/Unit/Service/AliasesServiceTest.php b/tests/Unit/Service/AliasesServiceTest.php index c6a1d4bbf4..240f6578d1 100644 --- a/tests/Unit/Service/AliasesServiceTest.php +++ b/tests/Unit/Service/AliasesServiceTest.php @@ -1,5 +1,7 @@ service->create( - 300, + $this->user, $entity->getAccountId(), $entity->getAlias(), $entity->getName() @@ -162,7 +164,7 @@ public function testCreateForbiddenAccountId(): void { ->willThrowException(new DoesNotExistException('Account does not exist')); $this->service->create( - 300, + $this->user, $entity->getAccountId(), $entity->getAlias(), $entity->getName() @@ -235,6 +237,6 @@ public function testUpateSignatureInvalidAliasId(): void { $this->aliasMapper->expects(self::never()) ->method('update'); - $this->service->updateSignature($this->user, '999999', 'Kind regards
Herbert'); + $this->service->updateSignature($this->user, 999999, 'Kind regards
Herbert'); } } diff --git a/tests/Unit/Service/AllowedRecipientsServiceTest.php b/tests/Unit/Service/AllowedRecipientsServiceTest.php index ad064d52de..486b1b5eeb 100644 --- a/tests/Unit/Service/AllowedRecipientsServiceTest.php +++ b/tests/Unit/Service/AllowedRecipientsServiceTest.php @@ -16,7 +16,7 @@ use OCA\Mail\Service\AllowedRecipientsService; use PHPUnit\Framework\MockObject\MockObject; -class AllowedRecipientsServiceTest extends TestCase { +final class AllowedRecipientsServiceTest extends TestCase { private AliasesService&MockObject $aliasesService; private AllowedRecipientsService $allowedRecipientsService; diff --git a/tests/Unit/Service/AntiAbuseServiceTest.php b/tests/Unit/Service/AntiAbuseServiceTest.php index 34884038cd..e6631877e4 100644 --- a/tests/Unit/Service/AntiAbuseServiceTest.php +++ b/tests/Unit/Service/AntiAbuseServiceTest.php @@ -19,7 +19,7 @@ use function array_map; use function range; -class AntiAbuseServiceTest extends TestCase { +final class AntiAbuseServiceTest extends TestCase { /** @var AntiAbuseService */ private $service; diff --git a/tests/Unit/Service/AntiSpamServiceTest.php b/tests/Unit/Service/AntiSpamServiceTest.php index a813be08c6..509f7c16b7 100644 --- a/tests/Unit/Service/AntiSpamServiceTest.php +++ b/tests/Unit/Service/AntiSpamServiceTest.php @@ -1,5 +1,7 @@ createMock(UploadedFile::class); $uploadedFile->expects($this->once()) @@ -115,7 +115,7 @@ public function testAddFileWithUploadException() { $this->service->addFile($userId, $uploadedFile); } - public function testAddFile() { + public function testAddFile(): void { $userId = 'jan'; $uploadedFile = $this->createMock(UploadedFile::class); $uploadedFile->expects($this->once()) @@ -145,7 +145,7 @@ public function testAddFile() { $this->service->addFile($userId, $uploadedFile); } - public function testAddFileFromStringWithUploadException() { + public function testAddFileFromStringWithUploadException(): void { $userId = 'jan'; $attachment = LocalAttachment::fromParams([ 'userId' => $userId, @@ -178,7 +178,7 @@ public function testAddFileFromStringWithUploadException() { $this->service->addFileFromString($userId, 'cat.jpg', 'image/jpg', 'Lorem ipsum dolor sit amet', null, null); } - public function testAddFileFromString() { + public function testAddFileFromString(): void { $userId = 'jan'; $attachment = LocalAttachment::fromParams([ 'userId' => $userId, diff --git a/tests/Unit/Service/Attachment/AttachmentStorageTest.php b/tests/Unit/Service/Attachment/AttachmentStorageTest.php index 9f5e81e431..4a81338172 100644 --- a/tests/Unit/Service/Attachment/AttachmentStorageTest.php +++ b/tests/Unit/Service/Attachment/AttachmentStorageTest.php @@ -1,5 +1,7 @@ storage = new AttachmentStorage($this->appData); } - public function testSaveWithFolderNotExisting() { + public function testSaveWithFolderNotExisting(): void { $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); $uploadedFile = $this->createMock(UploadedFile::class); @@ -63,7 +65,7 @@ public function testSaveWithFolderNotExisting() { $this->storage->save('fritz', 123, $uploadedFile); } - public function testSaveWithPermissionProblems() { + public function testSaveWithPermissionProblems(): void { $folder = $this->createStub(ISimpleFolder::class); $file = $this->createStub(ISimpleFile::class); $uploadedFile = $this->createStub(UploadedFile::class); @@ -81,7 +83,7 @@ public function testSaveWithPermissionProblems() { $this->storage->save('fritz', 123, $uploadedFile); } - public function testSaveWithoutTempPath() { + public function testSaveWithoutTempPath(): void { $folder = $this->createMock(ISimpleFolder::class); $file = $this->createStub(ISimpleFile::class); $uploadedFile = $this->createMock(UploadedFile::class); @@ -106,7 +108,7 @@ public function testSaveWithoutTempPath() { $this->storage->save('fritz', 123, $uploadedFile); } - public function testSaveWithFileReadError() { + public function testSaveWithFileReadError(): void { $folder = $this->createMock(ISimpleFolder::class); $file = $this->createStub(ISimpleFile::class); $uploadedFile = $this->createMock(UploadedFile::class); @@ -131,7 +133,7 @@ public function testSaveWithFileReadError() { $this->storage->save('fritz', 123, $uploadedFile); } - public function testSave() { + public function testSave(): void { $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); $uploadedFile = $this->createMock(UploadedFile::class); diff --git a/tests/Unit/Service/Attachment/UploadedFileTest.php b/tests/Unit/Service/Attachment/UploadedFileTest.php index 3229a2abb6..6d480022c0 100644 --- a/tests/Unit/Service/Attachment/UploadedFileTest.php +++ b/tests/Unit/Service/Attachment/UploadedFileTest.php @@ -1,5 +1,7 @@ assertEquals(null, $file->getFileName()); } - public function testGetFileName() { + public function testGetFileName(): void { $file = new UploadedFile([ 'name' => 'cat.jpg', ]); @@ -25,13 +27,13 @@ public function testGetFileName() { $this->assertEquals('cat.jpg', $file->getFileName()); } - public function testGetTempPathNotExisting() { + public function testGetTempPathNotExisting(): void { $file = new UploadedFile([]); $this->assertEquals(null, $file->getTempPath()); } - public function testGetTempPath() { + public function testGetTempPath(): void { $file = new UploadedFile([ 'tmp_name' => '/tmp/path', ]); diff --git a/tests/Unit/Service/Autocompletion/AddressCollectorTest.php b/tests/Unit/Service/Autocompletion/AddressCollectorTest.php index 29bc13851b..1b0e5cc2bc 100644 --- a/tests/Unit/Service/Autocompletion/AddressCollectorTest.php +++ b/tests/Unit/Service/Autocompletion/AddressCollectorTest.php @@ -17,7 +17,7 @@ use OCA\Mail\Service\AutoCompletion\AddressCollector; use Psr\Log\LoggerInterface; -class AddressCollectorTest extends TestCase { +final class AddressCollectorTest extends TestCase { private $mapper; private $userId = 'testuser'; private $logger; @@ -78,7 +78,7 @@ public function testAddDuplicateAddresses(): void { $this->collector->addAddresses($this->userId, $addressList); } - public function testSearchAddress() { + public function testSearchAddress(): void { $term = 'john'; $mapperResult = ['some', 'data']; diff --git a/tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php b/tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php index c08d748a2f..033a446569 100644 --- a/tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php +++ b/tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php @@ -1,5 +1,7 @@ addressCollector); } - public function testFindMatches() { + public function testFindMatches(): void { $term = 'jo'; $contactsResult = [ diff --git a/tests/Unit/Service/Autoconfig/ConfigurationTest.php b/tests/Unit/Service/Autoconfig/ConfigurationTest.php index 988da36909..d79a7ab139 100644 --- a/tests/Unit/Service/Autoconfig/ConfigurationTest.php +++ b/tests/Unit/Service/Autoconfig/ConfigurationTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Service\AutoConfig\Configuration; -class ConfigurationTest extends TestCase { +final class ConfigurationTest extends TestCase { public function testEmptyConfig(): void { $cfg = new Configuration(null, null); diff --git a/tests/Unit/Service/Autoconfig/IspDbTest.php b/tests/Unit/Service/Autoconfig/IspDbTest.php index 924c059e6f..4e3bded2d4 100644 --- a/tests/Unit/Service/Autoconfig/IspDbTest.php +++ b/tests/Unit/Service/Autoconfig/IspDbTest.php @@ -24,7 +24,7 @@ use function file_get_contents; use function str_starts_with; -class IspDbTest extends TestCase { +final class IspDbTest extends TestCase { /** @var IClientService|MockObject */ private $clientService; diff --git a/tests/Unit/Service/Autoconfig/ServerConfiguration.php b/tests/Unit/Service/Autoconfig/ServerConfiguration.php index 328c51516f..8ecdcad150 100644 --- a/tests/Unit/Service/Autoconfig/ServerConfiguration.php +++ b/tests/Unit/Service/Autoconfig/ServerConfiguration.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Service\AutoConfig\ServerConfiguration; -class ServerConfigurationTest extends TestCase { +final class ServerConfigurationTest extends TestCase { public function testCreateObject(): void { $cfg = new ServerConfiguration( 'username', diff --git a/tests/Unit/Service/Avatar/AddressbookSourceTest.php b/tests/Unit/Service/Avatar/AddressbookSourceTest.php index 85a1c15679..27b239a429 100644 --- a/tests/Unit/Service/Avatar/AddressbookSourceTest.php +++ b/tests/Unit/Service/Avatar/AddressbookSourceTest.php @@ -1,5 +1,7 @@ source = new AddressbookSource($this->ci); } - public function testFetch() { + public function testFetch(): void { $email = 'john@doe.com'; $avatarFactory = $this->createMock(AvatarFactory::class); $this->ci->expects($this->once()) @@ -47,7 +49,7 @@ public function testFetch() { $this->assertSame($avatar, $actualAvatar); } - public function testFetchNoneFound() { + public function testFetchNoneFound(): void { $email = 'john@doe.com'; $avatarFactory = $this->createStub(AvatarFactory::class); $this->ci->expects($this->once()) diff --git a/tests/Unit/Service/Avatar/AvatarFactoryTest.php b/tests/Unit/Service/Avatar/AvatarFactoryTest.php index b2a2723dbd..1182cf206e 100644 --- a/tests/Unit/Service/Avatar/AvatarFactoryTest.php +++ b/tests/Unit/Service/Avatar/AvatarFactoryTest.php @@ -13,7 +13,7 @@ use OCA\Mail\Service\Avatar\Avatar; use OCA\Mail\Service\Avatar\AvatarFactory; -class AvatarFactoryTest extends TestCase { +final class AvatarFactoryTest extends TestCase { private AvatarFactory $factory; protected function setUp(): void { diff --git a/tests/Unit/Service/Avatar/CacheTest.php b/tests/Unit/Service/Avatar/CacheTest.php index c06de9e89c..73ac4cf4f1 100644 --- a/tests/Unit/Service/Avatar/CacheTest.php +++ b/tests/Unit/Service/Avatar/CacheTest.php @@ -1,5 +1,7 @@ cache = new Cache($this->cacheFactory, $this->avatarFactory); } - public function testGetNonCachedAvatar() { + public function testGetNonCachedAvatar(): void { $email = 'john@doe.com'; $uid = 'jane'; $this->cacheImpl->expects($this->once()) @@ -56,7 +58,7 @@ public function testGetNonCachedAvatar() { $this->assertNull($cachedAvatar); } - public function testGetCachedAvatar() { + public function testGetCachedAvatar(): void { $email = 'john@doe.com'; $uid = 'jane'; $this->cacheImpl->expects($this->once()) @@ -74,7 +76,7 @@ public function testGetCachedAvatar() { $this->assertEquals($expected, $cachedAvatar); } - public function testSetAvatar() { + public function testSetAvatar(): void { $email = 'john@doe.com'; $uid = 'jane'; $avatar = new Avatar('https://…', 'image/jpeg'); @@ -85,7 +87,7 @@ public function testSetAvatar() { $this->cache->add($email, $uid, $avatar); } - public function testGetImage() { + public function testGetImage(): void { $uid = 'jane'; $this->cacheImpl->expects($this->once()) ->method('get') @@ -97,7 +99,7 @@ public function testGetImage() { $this->assertEquals(self::BLACK_DOT_BASE64, $image); } - public function testGetNonCachedImage() { + public function testGetNonCachedImage(): void { $uid = 'jane'; $this->cacheImpl->expects($this->once()) ->method('get') @@ -109,7 +111,7 @@ public function testGetNonCachedImage() { $this->assertNull($image); } - public function testAddImage() { + public function testAddImage(): void { $uid = 'jane'; $this->cacheImpl->expects($this->once()) ->method('set') diff --git a/tests/Unit/Service/Avatar/CompositeAvatarSourceTest.php b/tests/Unit/Service/Avatar/CompositeAvatarSourceTest.php index ad75fc62e7..7bc86b5b71 100644 --- a/tests/Unit/Service/Avatar/CompositeAvatarSourceTest.php +++ b/tests/Unit/Service/Avatar/CompositeAvatarSourceTest.php @@ -1,5 +1,7 @@ source = new CompositeAvatarSource($this->addressbookSource, $this->faviconSource, $this->gravatarSource); } - public function testFetchNoneFound() { + public function testFetchNoneFound(): void { $email = 'jane@doe.com'; $avatarFactory = $this->createStub(AvatarFactory::class); $this->addressbookSource->expects($this->any()) @@ -69,7 +71,7 @@ public function testFetchNoneFound() { $this->assertNull($actualAvatar); } - public function testFetchNoneFoundQueryOnlyInternal() { + public function testFetchNoneFoundQueryOnlyInternal(): void { $email = 'jane@doe.com'; $avatarFactory = $this->createStub(AvatarFactory::class); $this->addressbookSource->expects($this->once()) @@ -99,7 +101,7 @@ public function testFetchNoneFoundQueryOnlyInternal() { $this->assertNull($actualAvatar); } - public function testFetchFromGravatar() { + public function testFetchFromGravatar(): void { $email = 'jane@doe.com'; $avatar = new Avatar('https://gravatar.com', 'image/jpeg'); $avatarFactory = $this->createStub(AvatarFactory::class); diff --git a/tests/Unit/Service/Avatar/DownloaderTest.php b/tests/Unit/Service/Avatar/DownloaderTest.php index 45f668a955..4153a3f699 100644 --- a/tests/Unit/Service/Avatar/DownloaderTest.php +++ b/tests/Unit/Service/Avatar/DownloaderTest.php @@ -1,5 +1,7 @@ downloader = new Downloader($this->clientService); } - public function testDownload() { + public function testDownload(): void { $client = $this->createMock(IClient::class); $this->clientService->expects($this->once()) ->method('newClient') @@ -49,7 +51,7 @@ public function testDownload() { $this->assertEquals('data', $data); } - public function testDownloadError() { + public function testDownloadError(): void { $client = $this->createMock(IClient::class); $this->clientService->expects($this->once()) ->method('newClient') diff --git a/tests/Unit/Service/Avatar/FaviconDataAccessTest.php b/tests/Unit/Service/Avatar/FaviconDataAccessTest.php index c9b3568d45..79e6402a98 100644 --- a/tests/Unit/Service/Avatar/FaviconDataAccessTest.php +++ b/tests/Unit/Service/Avatar/FaviconDataAccessTest.php @@ -15,7 +15,7 @@ use OCP\Http\Client\IResponse; use PHPUnit\Framework\MockObject\MockObject; -class FaviconDataAccessTest extends TestCase { +final class FaviconDataAccessTest extends TestCase { private IClientService|MockObject $clientService; private FaviconDataAccess $dataAccess; @@ -30,7 +30,7 @@ protected function setUp(): void { ); } - public function testRetrieveUrl() { + public function testRetrieveUrl(): void { $client = $this->createMock(IClient::class); $this->clientService->expects(self::once()) ->method('newClient') @@ -49,7 +49,7 @@ public function testRetrieveUrl() { self::assertSame('html', $body); } - public function testRetrieveHeader() { + public function testRetrieveHeader(): void { $client = $this->createMock(IClient::class); $this->clientService->expects(self::once()) ->method('newClient') diff --git a/tests/Unit/Service/Avatar/FaviconSourceTest.php b/tests/Unit/Service/Avatar/FaviconSourceTest.php index b13e8bd59f..523db436b0 100644 --- a/tests/Unit/Service/Avatar/FaviconSourceTest.php +++ b/tests/Unit/Service/Avatar/FaviconSourceTest.php @@ -21,7 +21,7 @@ use OCP\Security\IRemoteHostValidator; use PHPUnit\Framework\MockObject\MockObject; -class FaviconSourceTest extends TestCase { +final class FaviconSourceTest extends TestCase { /** @var IClientService|MockObject */ private $clientService; diff --git a/tests/Unit/Service/Avatar/GravatarSourceTest.php b/tests/Unit/Service/Avatar/GravatarSourceTest.php index 53ff9d5f1e..f0c0982b83 100644 --- a/tests/Unit/Service/Avatar/GravatarSourceTest.php +++ b/tests/Unit/Service/Avatar/GravatarSourceTest.php @@ -1,5 +1,7 @@ source = new GravatarSource($this->clientService); } - public function testFetchExisting() { + public function testFetchExisting(): void { $email = 'hey@jancborchardt.net'; $client = $this->createMock(IClient::class); $avatarFactory = $this->createMock(AvatarFactory::class); @@ -58,7 +60,7 @@ public function testFetchExisting() { $this->assertEquals($avatar, $actualAvatar); } - public function testFetchHttpError() { + public function testFetchHttpError(): void { $email = 'hey@jancborchardt.net'; $client = $this->createMock(IClient::class); $avatarFactory = $this->createStub(AvatarFactory::class); diff --git a/tests/Unit/Service/AvatarServiceTest.php b/tests/Unit/Service/AvatarServiceTest.php index 61542fb28e..4b60a078af 100644 --- a/tests/Unit/Service/AvatarServiceTest.php +++ b/tests/Unit/Service/AvatarServiceTest.php @@ -21,7 +21,7 @@ use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; -class AvatarServiceTest extends TestCase { +final class AvatarServiceTest extends TestCase { public const BLACK_DOT_BASE64 = 'R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='; /** @var IAvatarSource|MockObject */ @@ -63,7 +63,7 @@ protected function setUp(): void { ); } - public function testGetCachedAvatarUrl() { + public function testGetCachedAvatarUrl(): void { $email = 'jane@doe.com'; $uid = 'john'; $avatar = new Avatar('https://doe.com/favicon.ico'); @@ -77,7 +77,7 @@ public function testGetCachedAvatarUrl() { $this->assertSame($avatar, $result); } - public function testGetAvatarNoAvatarFound() { + public function testGetAvatarNoAvatarFound(): void { $email = 'jane@doe.com'; $uid = 'john'; $this->preferences->expects($this->once()) @@ -101,7 +101,7 @@ public function testGetAvatarNoAvatarFound() { $this->assertNull($url); } - public function testGetAvatarMimeNotAllowed() { + public function testGetAvatarMimeNotAllowed(): void { $email = 'jane@doe.com'; $uid = 'john'; $this->preferences->expects($this->once()) @@ -126,7 +126,7 @@ public function testGetAvatarMimeNotAllowed() { $this->assertNull($url); } - public function testGetAvatarOnlyInternalAllowed() { + public function testGetAvatarOnlyInternalAllowed(): void { $email = 'jane@doe.com'; $uid = 'john'; $avatar = new Avatar('https://doe.com/favicon.ico', 'image/png'); @@ -151,7 +151,7 @@ public function testGetAvatarOnlyInternalAllowed() { $this->assertEquals($avatar, $actualAvatar); } - public function testGetAvatar() { + public function testGetAvatar(): void { $email = 'jane@doe.com'; $uid = 'john'; $avatar = new Avatar('https://doe.com/favicon.ico', 'image/png'); @@ -176,7 +176,7 @@ public function testGetAvatar() { $this->assertEquals($avatar, $actualAvatar); } - public function testGetCachedAvatarImage() { + public function testGetCachedAvatarImage(): void { $email = 'jane@doe.com'; $uid = 'john'; $avatar = new Avatar('https://doe.com/favicon.ico', 'image/png'); @@ -194,7 +194,7 @@ public function testGetCachedAvatarImage() { $this->assertEquals([$avatar, base64_decode(self::BLACK_DOT_BASE64)], $data); } - public function testGetAvatarImageNoUrlCached() { + public function testGetAvatarImageNoUrlCached(): void { $email = 'jane@doe.com'; $uid = 'john'; $this->cache->expects($this->once()) @@ -207,7 +207,7 @@ public function testGetAvatarImageNoUrlCached() { $this->assertNull($image); } - public function testGetAvatarImageDownloadImage() { + public function testGetAvatarImageDownloadImage(): void { $email = 'jane@doe.com'; $uid = 'john'; $avatar = new Avatar('https://doe.com/favicon.ico', 'image/jpg'); @@ -232,7 +232,7 @@ public function testGetAvatarImageDownloadImage() { $this->assertEquals([$avatar, base64_decode(self::BLACK_DOT_BASE64)], $data); } - public function testGetAvatarImageDownloadImageFails() { + public function testGetAvatarImageDownloadImageFails(): void { $email = 'jane@doe.com'; $uid = 'john'; $avatar = new Avatar('https://doe.com/favicon.ico', 'image/jpg'); diff --git a/tests/Unit/Service/Classification/ClassificationSettingsServiceTest.php b/tests/Unit/Service/Classification/ClassificationSettingsServiceTest.php index 1776277ec7..c727ec5ac5 100644 --- a/tests/Unit/Service/Classification/ClassificationSettingsServiceTest.php +++ b/tests/Unit/Service/Classification/ClassificationSettingsServiceTest.php @@ -17,7 +17,7 @@ use OCP\IAppConfig; use PHPUnit\Framework\MockObject\MockObject; -class ClassificationSettingsServiceTest extends TestCase { +final class ClassificationSettingsServiceTest extends TestCase { private IUserPreferences&MockObject $preferences; private IAppConfig&MockObject $appConfig; diff --git a/tests/Unit/Service/ContactsIntegrationTest.php b/tests/Unit/Service/ContactsIntegrationTest.php index da1d89d6c4..600daa96d9 100644 --- a/tests/Unit/Service/ContactsIntegrationTest.php +++ b/tests/Unit/Service/ContactsIntegrationTest.php @@ -18,7 +18,7 @@ use OCP\IUser; use OCP\IUserManager; -class ContactsIntegrationTest extends TestCase { +final class ContactsIntegrationTest extends TestCase { /** @var IManager */ private $contactsManager; @@ -47,7 +47,7 @@ protected function setUp(): void { $this->config); } - public function testDisabledContactsManager() { + public function testDisabledContactsManager(): void { $this->contactsManager->expects($this->once()) ->method('isEnabled') ->will($this->returnValue(false)); @@ -60,7 +60,7 @@ public function testDisabledContactsManager() { $this->assertEquals($expected, $actual); } - public function testGetMatchingRecipient() { + public function testGetMatchingRecipient(): void { $term = 'jo'; // searching for: John Doe $searchResult = [ [ @@ -140,7 +140,7 @@ public function testGetMatchingRecipientContactWithoutUid(): void { $this->assertSame($expected, $actual); } - public function testGetMatchingRecipientRestrictedToGroup() { + public function testGetMatchingRecipientRestrictedToGroup(): void { $term = 'jo'; // searching for: John Doe $searchResult = [ [ @@ -210,7 +210,7 @@ public function testGetMatchingRecipientRestrictedToGroup() { $this->assertEquals($expected, $actual); } - public function testGetMatchingRecipientRestrictedToGroupFullMatchUserId() { + public function testGetMatchingRecipientRestrictedToGroupFullMatchUserId(): void { $term = 'jf'; // searching for: Jonathan Frakes $searchResult = [ [ @@ -251,7 +251,7 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchUserId() { $this->assertEquals($expected, $actual); } - public function testGetMatchingRecipientRestrictedToGroupFullMatchFullName() { + public function testGetMatchingRecipientRestrictedToGroupFullMatchFullName(): void { $term = 'Jonathan Frakes'; // searching for: Jonathan Frakes $searchResult = [ [ @@ -292,7 +292,7 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchFullName() { $this->assertEquals($expected, $actual); } - public function testGetMatchingRecipientRestrictedToGroupFullMatchEmail() { + public function testGetMatchingRecipientRestrictedToGroupFullMatchEmail(): void { $term = 'jonathan@frakes.com'; // searching for: Jonathan Frakes $searchResult = [ [ @@ -333,7 +333,7 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchEmail() { $this->assertEquals($expected, $actual); } - public function testGetMatchingRecipientRestrictedToGroupFullMatchFalse() { + public function testGetMatchingRecipientRestrictedToGroupFullMatchFalse(): void { $term = 'jf'; // searching for: Jonathan Frakes $searchResult = [ diff --git a/tests/Unit/Service/ContextChat/ContextChatSettingsServiceTest.php b/tests/Unit/Service/ContextChat/ContextChatSettingsServiceTest.php index 6447b372eb..4457986aec 100644 --- a/tests/Unit/Service/ContextChat/ContextChatSettingsServiceTest.php +++ b/tests/Unit/Service/ContextChat/ContextChatSettingsServiceTest.php @@ -17,7 +17,7 @@ use OCP\IAppConfig; use PHPUnit\Framework\MockObject\MockObject; -class ContextChatSettingsServiceTest extends TestCase { +final class ContextChatSettingsServiceTest extends TestCase { private IUserPreferences&MockObject $preferences; private IAppConfig&MockObject $appConfig; diff --git a/tests/Unit/Service/DataUri/DataUriParserTest.php b/tests/Unit/Service/DataUri/DataUriParserTest.php index 14e71e4662..1e9612d8c3 100644 --- a/tests/Unit/Service/DataUri/DataUriParserTest.php +++ b/tests/Unit/Service/DataUri/DataUriParserTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Service\DataUri\DataUri; use OCA\Mail\Service\DataUri\DataUriParser; -class DataUriParserTest extends TestCase { +final class DataUriParserTest extends TestCase { private DataUriParser $parser; public function setUp(): void { @@ -40,44 +40,42 @@ public function testParseException(): void { $this->parser->parse('hellohello;base64'); } - public function dataParse(): array { - return [ - [ - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', - new DataUri( - 'image/png', - ['charset' => 'US-ASCII'], - true, - 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' - ) - ], - [ - 'data:image/png;charset=TEST,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', - new DataUri( - 'image/png', - ['charset' => 'TEST'], - false, - 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' - ) - ], - [ - 'data:text/plain2;charset=UTF-8;page=21,the%20data:1234,5678', - new DataUri( - 'text/plain2', - ['charset' => 'UTF-8', 'page' => '21'], - false, - 'the%20data:1234,5678' - ) - ], - [ - 'data:,', - new DataUri( - 'text/plain', - ['charset' => 'US-ASCII'], - false, - '' - ) - ] + public function dataParse(): \Iterator { + yield [ + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', + new DataUri( + 'image/png', + ['charset' => 'US-ASCII'], + true, + 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' + ) + ]; + yield [ + 'data:image/png;charset=TEST,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', + new DataUri( + 'image/png', + ['charset' => 'TEST'], + false, + 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' + ) + ]; + yield [ + 'data:text/plain2;charset=UTF-8;page=21,the%20data:1234,5678', + new DataUri( + 'text/plain2', + ['charset' => 'UTF-8', 'page' => '21'], + false, + 'the%20data:1234,5678' + ) + ]; + yield [ + 'data:,', + new DataUri( + 'text/plain', + ['charset' => 'US-ASCII'], + false, + '' + ) ]; } } diff --git a/tests/Unit/Service/DataUri/DataUriTest.php b/tests/Unit/Service/DataUri/DataUriTest.php index f41d091c1f..83ed582c9a 100644 --- a/tests/Unit/Service/DataUri/DataUriTest.php +++ b/tests/Unit/Service/DataUri/DataUriTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Service\DataUri\DataUri; -class DataUriTest extends TestCase { +final class DataUriTest extends TestCase { public function testEntity(): void { $mediaType = 'image/png'; $parameters = ['charset' => 'US-ASCII']; diff --git a/tests/Unit/Service/DelegationServiceTest.php b/tests/Unit/Service/DelegationServiceTest.php index c7fcde625d..e9af23c867 100644 --- a/tests/Unit/Service/DelegationServiceTest.php +++ b/tests/Unit/Service/DelegationServiceTest.php @@ -35,7 +35,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class DelegationServiceTest extends TestCase { +final class DelegationServiceTest extends TestCase { private DelegationMapper&MockObject $delegationMapper; private AccountService&MockObject $accountService; private MailboxMapper&MockObject $mailboxMapper; diff --git a/tests/Unit/Service/DkimServiceTest.php b/tests/Unit/Service/DkimServiceTest.php index 44b0c4de23..c4cd842843 100644 --- a/tests/Unit/Service/DkimServiceTest.php +++ b/tests/Unit/Service/DkimServiceTest.php @@ -23,7 +23,7 @@ use OCP\ICache; use OCP\ICacheFactory; -class DkimServiceTest extends TestCase { +final class DkimServiceTest extends TestCase { private ProtocolFactory $protocolFactory; private IMessageConnector $messageConnector; private ICache $cache; diff --git a/tests/Unit/Service/DraftsServiceTest.php b/tests/Unit/Service/DraftsServiceTest.php index f1951cc46f..59631f4f4e 100644 --- a/tests/Unit/Service/DraftsServiceTest.php +++ b/tests/Unit/Service/DraftsServiceTest.php @@ -37,7 +37,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class DraftsServiceTest extends TestCase { +final class DraftsServiceTest extends TestCase { /** @var MailboxMapper|MockObject */ private $mailboxMapper; diff --git a/tests/Unit/Service/FilterServiceTest.php b/tests/Unit/Service/FilterServiceTest.php index a4f4724613..90ffeac626 100644 --- a/tests/Unit/Service/FilterServiceTest.php +++ b/tests/Unit/Service/FilterServiceTest.php @@ -25,7 +25,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\Test\TestLogger; -class FilterServiceTest extends TestCase { +final class FilterServiceTest extends TestCase { private string $testFolder; diff --git a/tests/Unit/Service/Group/ContactsGroupServiceTest.php b/tests/Unit/Service/Group/ContactsGroupServiceTest.php index 8efd42405e..18ebbad2f4 100644 --- a/tests/Unit/Service/Group/ContactsGroupServiceTest.php +++ b/tests/Unit/Service/Group/ContactsGroupServiceTest.php @@ -1,5 +1,7 @@ config); } - public function testDisabledContactsManager() { + public function testDisabledContactsManager(): void { $this->contactsManager->expects($this->once()) ->method('isEnabled') ->will($this->returnValue(false)); @@ -43,7 +45,7 @@ public function testDisabledContactsManager() { $this->assertEquals($expected, $actual); } - public function testSearchGroups() { + public function testSearchGroups(): void { $term = 'wor'; // searching for: group Work $searchResult = [ [ @@ -105,7 +107,7 @@ public function testSearchGroups() { $this->assertEquals($expected, $actual); } - public function testGetUsersForGroup() { + public function testGetUsersForGroup(): void { $groupId = 'work'; // searching for: group Work $searchResult = [ [ diff --git a/tests/Unit/Service/Group/NextcloudGroupServiceTest.php b/tests/Unit/Service/Group/NextcloudGroupServiceTest.php index 69b00c2401..a7655774d1 100644 --- a/tests/Unit/Service/Group/NextcloudGroupServiceTest.php +++ b/tests/Unit/Service/Group/NextcloudGroupServiceTest.php @@ -1,5 +1,7 @@ 'testgroup', - 'name' => 'first test group', - ], - [ - 'id' => 'testgroup2', - 'name' => 'second test group', - ] - ]], - ['no', 'yes', []], - ['no', 'no', []], - ['yes', 'yes', []], - ]; + public function dataForTestSearch(): \Iterator { + yield ['yes', 'no', [ + [ + 'id' => 'testgroup', + 'name' => 'first test group', + ], + [ + 'id' => 'testgroup2', + 'name' => 'second test group', + ] + ]]; + yield ['no', 'yes', []]; + yield ['no', 'no', []]; + yield ['yes', 'yes', []]; } /** @@ -117,7 +117,7 @@ public function testSearch(string $allowGroupSharing, string $restrictSharingToG self::assertEquals($expected, $actual); } - public function testGetUsers() { + public function testGetUsers(): void { $users = [ $this->createTestUser('bob', 'Bobby', 'bob@smith.net'), $this->createTestUser('alice', 'Alice', 'alice@smith.net') @@ -156,7 +156,7 @@ public function testGetUsers() { $this->assertEquals($expected, $actual); } - public function testGetUsersWrong() { + public function testGetUsersWrong(): void { $this->expectException(ServiceException::class); $this->groupsManager->expects($this->once()) diff --git a/tests/Unit/Service/GroupsIntegrationTest.php b/tests/Unit/Service/GroupsIntegrationTest.php index 7fa05a9145..5daf4de3d5 100644 --- a/tests/Unit/Service/GroupsIntegrationTest.php +++ b/tests/Unit/Service/GroupsIntegrationTest.php @@ -17,7 +17,7 @@ use OCA\Mail\Service\GroupsIntegration; use PHPUnit\Framework\MockObject\MockObject; -class GroupsIntegrationTest extends TestCase { +final class GroupsIntegrationTest extends TestCase { private NextcloudGroupService|MockObject $groupService1; private NextcloudGroupService|MockObject $groupService2; /** @var GroupsIntegration */ diff --git a/tests/Unit/Service/HtmlPurify/TransformCidDataAttrTest.php b/tests/Unit/Service/HtmlPurify/TransformCidDataAttrTest.php index 8151b644c5..c5432f4753 100644 --- a/tests/Unit/Service/HtmlPurify/TransformCidDataAttrTest.php +++ b/tests/Unit/Service/HtmlPurify/TransformCidDataAttrTest.php @@ -15,7 +15,7 @@ use HTMLPurifier_Token_Start; use OCA\Mail\Service\HtmlPurify\TransformCidDataAttr; -class TransformCidDataAttrTest extends TestCase { +final class TransformCidDataAttrTest extends TestCase { private HTMLPurifier_Config $config; private array $inlineAttachments = [ diff --git a/tests/Unit/Service/HtmlPurify/TransformHTMLLinksTest.php b/tests/Unit/Service/HtmlPurify/TransformHTMLLinksTest.php index 531b854b54..b13773c8a8 100644 --- a/tests/Unit/Service/HtmlPurify/TransformHTMLLinksTest.php +++ b/tests/Unit/Service/HtmlPurify/TransformHTMLLinksTest.php @@ -14,7 +14,7 @@ use HTMLPurifier_Context; use OCA\Mail\Service\HtmlPurify\TransformHTMLLinks; -class TransformHTMLLinksTest extends TestCase { +final class TransformHTMLLinksTest extends TestCase { private TransformHTMLLinks $transform; protected function setUp(): void { diff --git a/tests/Unit/Service/HtmlPurify/TransformImageSrcTest.php b/tests/Unit/Service/HtmlPurify/TransformImageSrcTest.php index ff53ce658c..abe1f7f987 100644 --- a/tests/Unit/Service/HtmlPurify/TransformImageSrcTest.php +++ b/tests/Unit/Service/HtmlPurify/TransformImageSrcTest.php @@ -18,7 +18,7 @@ use OCP\Util; use PHPUnit\Framework\MockObject\MockObject; -class TransformImageSrcTest extends TestCase { +final class TransformImageSrcTest extends TestCase { private TransformImageSrc $transform; private IURLGenerator|MockObject $urlGenerator; diff --git a/tests/Unit/Service/HtmlPurify/TransformNoReferrerTest.php b/tests/Unit/Service/HtmlPurify/TransformNoReferrerTest.php index 22239a6e3e..8d29ed44e9 100644 --- a/tests/Unit/Service/HtmlPurify/TransformNoReferrerTest.php +++ b/tests/Unit/Service/HtmlPurify/TransformNoReferrerTest.php @@ -14,7 +14,7 @@ use HTMLPurifier_Context; use OCA\Mail\Service\HtmlPurify\TransformNoReferrer; -class TransformNoReferrerTest extends TestCase { +final class TransformNoReferrerTest extends TestCase { private TransformNoReferrer $transform; protected function setUp(): void { diff --git a/tests/Unit/Service/HtmlPurify/TransformStyleURLsTest.php b/tests/Unit/Service/HtmlPurify/TransformStyleURLsTest.php index 591c051541..0c2751a1eb 100644 --- a/tests/Unit/Service/HtmlPurify/TransformStyleURLsTest.php +++ b/tests/Unit/Service/HtmlPurify/TransformStyleURLsTest.php @@ -16,7 +16,7 @@ use OCP\IURLGenerator; use PHPUnit\Framework\MockObject\MockObject; -class TransformStyleURLsTest extends TestCase { +final class TransformStyleURLsTest extends TestCase { private TransformStyleURLs $transform; private IURLGenerator|MockObject $urlGenerator; diff --git a/tests/Unit/Service/HtmlPurify/TransformURLSchemeTest.php b/tests/Unit/Service/HtmlPurify/TransformURLSchemeTest.php index ff11f73ff2..c7195e2d98 100644 --- a/tests/Unit/Service/HtmlPurify/TransformURLSchemeTest.php +++ b/tests/Unit/Service/HtmlPurify/TransformURLSchemeTest.php @@ -19,7 +19,7 @@ use OCP\IURLGenerator; use PHPUnit\Framework\MockObject\MockObject; -class TransformURLSchemeTest extends TestCase { +final class TransformURLSchemeTest extends TestCase { private TransformURLScheme $filter; private IURLGenerator|MockObject $urlGenerator; private IRequest|MockObject $request; diff --git a/tests/Unit/Service/HtmlTest.php b/tests/Unit/Service/HtmlTest.php index 7866f8c9e6..968227e497 100644 --- a/tests/Unit/Service/HtmlTest.php +++ b/tests/Unit/Service/HtmlTest.php @@ -17,13 +17,13 @@ use OCP\IURLGenerator; use OCP\Server; -class HtmlTest extends TestCase { +final class HtmlTest extends TestCase { /** * @dataProvider linkDetectionProvider * @param $expected * @param $text */ - public function testLinkDetection(string $expected, string $text) { + public function testLinkDetection(string $expected, string $text): void { $urlGenerator = Server::get(IURLGenerator::class); $request = Server::get(IRequest::class); $hmacGenerator = $this->createStub(ProxyHmacGenerator::class); @@ -34,27 +34,26 @@ public function testLinkDetection(string $expected, string $text) { self::assertSame($expected, $withLinks); } - public function linkDetectionProvider() { - return [ - ['abc', 'abc'], - ['<>', '<>'], - ['<>', '<>'], // no double encoding - ['foo&bar', 'foo&bar'], - ['http://google.com', 'http://google.com'], - ['https://google.com', 'https://google.com'], - ['ftp://google.com', 'ftp://google.com'], - ['http://www.themukt.com/2014/07/23/take-control-cloud-owncloud-7/', 'http://www.themukt.com/2014/07/23/take-control-cloud-owncloud-7/'], - ['https://travis-ci.org/owncloud/music/builds/22037091', 'https://travis-ci.org/owncloud/music/builds/22037091'], - ['(ftp://google.com)', '(ftp://google.com)'], - ['https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1', 'https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1'], - ['(https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1)', '(https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1)'], - ['http://apps.owncloud.com/content/show.php/Music?content=160485', 'http://apps.owncloud.com/content/show.php/Music?content=160485'], - ['https://groups.google.com/forum/#!forum/ctpug', 'https://groups.google.com/forum/#!forum/ctpug'], - ['http://www.amazon.de/s/ref=nb_sb_noss?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords=Fax%2C+Kopierer+scanner+Laser&rh=i%3Aaps%2Ck%3AFax%5Cc+Kopierer+scanner+Laser', 'http://www.amazon.de/s/ref=nb_sb_noss?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords=Fax%2C+Kopierer+scanner+Laser&rh=i%3Aaps%2Ck%3AFax%5Cc+Kopierer+scanner+Laser'], - ['https://ci.owncloud.org/job/ownCloud-Documentation(7.0)/504/changes', 'https://ci.owncloud.org/job/ownCloud-Documentation(7.0)/504/changes'], - ['https://communities.coverity.com/community/scan-(open-source)/content', 'https://communities.coverity.com/community/scan-(open-source)/content'], - ['https://ma.ellak.gr/events/5ος-εκπαιδευτικός-κύκλος-σεμιναρίων-ε-5/', 'https://ma.ellak.gr/events/5ος-εκπαιδευτικός-κύκλος-σεμιναρίων-ε-5/'], - ]; + public function linkDetectionProvider(): \Iterator { + yield ['abc', 'abc']; + yield ['<>', '<>']; + yield ['<>', '<>']; + // no double encoding + yield ['foo&bar', 'foo&bar']; + yield ['http://google.com', 'http://google.com']; + yield ['https://google.com', 'https://google.com']; + yield ['ftp://google.com', 'ftp://google.com']; + yield ['http://www.themukt.com/2014/07/23/take-control-cloud-owncloud-7/', 'http://www.themukt.com/2014/07/23/take-control-cloud-owncloud-7/']; + yield ['https://travis-ci.org/owncloud/music/builds/22037091', 'https://travis-ci.org/owncloud/music/builds/22037091']; + yield ['(ftp://google.com)', '(ftp://google.com)']; + yield ['https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1', 'https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1']; + yield ['(https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1)', '(https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1)']; + yield ['http://apps.owncloud.com/content/show.php/Music?content=160485', 'http://apps.owncloud.com/content/show.php/Music?content=160485']; + yield ['https://groups.google.com/forum/#!forum/ctpug', 'https://groups.google.com/forum/#!forum/ctpug']; + yield ['http://www.amazon.de/s/ref=nb_sb_noss?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords=Fax%2C+Kopierer+scanner+Laser&rh=i%3Aaps%2Ck%3AFax%5Cc+Kopierer+scanner+Laser', 'http://www.amazon.de/s/ref=nb_sb_noss?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords=Fax%2C+Kopierer+scanner+Laser&rh=i%3Aaps%2Ck%3AFax%5Cc+Kopierer+scanner+Laser']; + yield ['https://ci.owncloud.org/job/ownCloud-Documentation(7.0)/504/changes', 'https://ci.owncloud.org/job/ownCloud-Documentation(7.0)/504/changes']; + yield ['https://communities.coverity.com/community/scan-(open-source)/content', 'https://communities.coverity.com/community/scan-(open-source)/content']; + yield ['https://ma.ellak.gr/events/5ος-εκπαιδευτικός-κύκλος-σεμιναρίων-ε-5/', 'https://ma.ellak.gr/events/5ος-εκπαιδευτικός-κύκλος-σεμιναρίων-ε-5/']; } /** @@ -72,16 +71,14 @@ public function testLinkDetectionRepairsInvalidUtf8(string $text, string $expect self::assertStringContainsString($expectedSubstring, $withLinks); } - public function invalidUtf8Provider(): array { - return [ - 'stray latin-1 byte' => ["Hello team,\r\n\r\nSee you n\xFCxt week.\r\n", 'Hello team,'], - // The two 3-byte sequences below are a UTF-16 surrogate pair (high D83D, - // low DE09) that got UTF-8-encoded one half at a time instead of combined - // into one 4-byte sequence - a CESU-8 encoding bug seen from some senders. - 'cesu-8 surrogate pair' => ["Hello team,\r\n\r\nSee you soon \xED\xA0\xBD\xED\xB8\x89\r\n", 'Hello team,'], - 'invalid bytes at the very start' => ["\xFF\xFEHello team,\r\n", 'Hello team,'], - 'only invalid bytes' => ["\xFF\xFE\xFD", '?'], - ]; + public function invalidUtf8Provider(): \Iterator { + yield 'stray latin-1 byte' => ["Hello team,\r\n\r\nSee you n\xFCxt week.\r\n", 'Hello team,']; + // The two 3-byte sequences below are a UTF-16 surrogate pair (high D83D, + // low DE09) that got UTF-8-encoded one half at a time instead of combined + // into one 4-byte sequence - a CESU-8 encoding bug seen from some senders. + yield 'cesu-8 surrogate pair' => ["Hello team,\r\n\r\nSee you soon \xED\xA0\xBD\xED\xB8\x89\r\n", 'Hello team,']; + yield 'invalid bytes at the very start' => ["\xFF\xFEHello team,\r\n", 'Hello team,']; + yield 'only invalid bytes' => ["\xFF\xFE\xFD", '?']; } public function testLinkDetectionLeavesValidMultibyteTextUnchanged(): void { @@ -115,7 +112,7 @@ public function testDoNotLinkAmbiguousExtensions(): void { * @param $expected * @param $text */ - public function testParseMailBody($expectedBody, $expectedSignature, $text) { + public function testParseMailBody($expectedBody, $expectedSignature, $text): void { $urlGenerator = \OCP\Server::get(\OCP\IURLGenerator::class); $request = \OCP\Server::get(\OCP\IRequest::class); $hmacGenerator = $this->createStub(ProxyHmacGenerator::class); @@ -126,12 +123,10 @@ public function testParseMailBody($expectedBody, $expectedSignature, $text) { $this->assertSame($expectedSignature, $s); } - public function parseMailBodyProvider() { - return [ - ['abc', null, 'abc'], - ['abc', 'def', "abc-- \r\ndef"], - ["abc-- \r\ndef", 'ghi', "abc-- \r\ndef-- \r\nghi"], - ]; + public function parseMailBodyProvider(): \Iterator { + yield ['abc', null, 'abc']; + yield ['abc', 'def', "abc-- \r\ndef"]; + yield ["abc-- \r\ndef", 'ghi', "abc-- \r\ndef-- \r\nghi"]; } public function testSanitizeHtmlMailBodyRewritesCidToUrl(): void { @@ -225,17 +220,15 @@ public function testSanitizeHtmlMailBodyStripsConditionalVariants(string $condit self::assertStringContainsString('

Kept

', $result); } - public function downlevelRevealedConditionalProvider(): array { - return [ - 'revealed if' => [''], - 'revealed endif' => [''], - 'uppercase' => [''], - 'padded brackets' => [''], - 'version gate' => [''], - ]; + public function downlevelRevealedConditionalProvider(): \Iterator { + yield 'revealed if' => ['']; + yield 'revealed endif' => ['']; + yield 'uppercase' => ['']; + yield 'padded brackets' => ['']; + yield 'version gate' => ['']; } - public function testSanitizeStyleSheet() { + public function testSanitizeStyleSheet(): void { $blockedUrl = '/apps/mail/img/blocked-image.png'; $urlGenerator = self::createMock(IURLGenerator::class); $urlGenerator->expects(self::any()) diff --git a/tests/Unit/Service/IMipServiceTest.php b/tests/Unit/Service/IMipServiceTest.php index 050ea21e62..dc5e910136 100644 --- a/tests/Unit/Service/IMipServiceTest.php +++ b/tests/Unit/Service/IMipServiceTest.php @@ -30,7 +30,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class IMipServiceTest extends TestCase { +final class IMipServiceTest extends TestCase { private ProtocolFactory&MockObject $protocolFactory; /** @var MailboxMapper|MockObject */ private $mailboxMapper; diff --git a/tests/Unit/Service/ItineraryServiceTest.php b/tests/Unit/Service/ItineraryServiceTest.php index e2dc18278a..dab48b6a6e 100644 --- a/tests/Unit/Service/ItineraryServiceTest.php +++ b/tests/Unit/Service/ItineraryServiceTest.php @@ -26,7 +26,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\NullLogger; -class ItineraryServiceTest extends TestCase { +final class ItineraryServiceTest extends TestCase { /** @var MailManager|MockObject */ private $mailManager; @@ -57,7 +57,7 @@ protected function setUp(): void { ); } - public function testExtractNoBodyNoAttachments() { + public function testExtractNoBodyNoAttachments(): void { $mailAccount = new MailAccount(); $mailAccount->setId(100); $mailAccount->setUserId('1'); @@ -119,7 +119,7 @@ public function testExtractWithoutAdapterSkipsImapFetch(): void { $this->assertNotNull($this->service->getCached($account, $mailbox, 13)); } - public function testExtractFromBody() { + public function testExtractFromBody(): void { $mailAccount = new MailAccount(); $mailAccount->setId(100); $mailAccount->setUserId('1'); @@ -155,7 +155,7 @@ public function testExtractFromBody() { $this->assertEquals(['datafrombody'], $itinerary->jsonSerialize()); } - public function testExtractFromAttachments() { + public function testExtractFromAttachments(): void { $mailAccount = new MailAccount(); $mailAccount->setId(100); $mailAccount->setUserId('1'); diff --git a/tests/Unit/Service/JMAP/JmapOperationsServiceTest.php b/tests/Unit/Service/JMAP/JmapOperationsServiceTest.php index 36088182ee..be834060fc 100644 --- a/tests/Unit/Service/JMAP/JmapOperationsServiceTest.php +++ b/tests/Unit/Service/JMAP/JmapOperationsServiceTest.php @@ -34,7 +34,7 @@ use ReflectionProperty; use RuntimeException; -class JmapOperationsServiceTest extends TestCase { +final class JmapOperationsServiceTest extends TestCase { private ProtocolFactory|MockObject $protocolFactory; private JmapMailboxAdapter|MockObject $jmapMailboxAdapter; diff --git a/tests/Unit/Service/MailFilter/FilterBuilderTest.php b/tests/Unit/Service/MailFilter/FilterBuilderTest.php index 903ab2b5a2..e01dc0d10e 100644 --- a/tests/Unit/Service/MailFilter/FilterBuilderTest.php +++ b/tests/Unit/Service/MailFilter/FilterBuilderTest.php @@ -13,7 +13,7 @@ use OCA\Mail\IMAP\ImapFlag; use OCA\Mail\Service\MailFilter\FilterBuilder; -class FilterBuilderTest extends TestCase { +final class FilterBuilderTest extends TestCase { private FilterBuilder $builder; public function setUp(): void { diff --git a/tests/Unit/Service/MailFilter/FilterParserTest.php b/tests/Unit/Service/MailFilter/FilterParserTest.php index 83e775df64..27d49cd080 100644 --- a/tests/Unit/Service/MailFilter/FilterParserTest.php +++ b/tests/Unit/Service/MailFilter/FilterParserTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Service\MailFilter\FilterParser; -class FilterParserTest extends TestCase { +final class FilterParserTest extends TestCase { private FilterParser $filterParser; private string $testFolder; diff --git a/tests/Unit/Service/MailFilter/FilterStateTest.php b/tests/Unit/Service/MailFilter/FilterStateTest.php index 3c5dceca55..2147f838a2 100644 --- a/tests/Unit/Service/MailFilter/FilterStateTest.php +++ b/tests/Unit/Service/MailFilter/FilterStateTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Service\MailFilter\FilterState; -class FilterStateTest extends TestCase { +final class FilterStateTest extends TestCase { public function testConstructor(): void { $filters = ['filter1' => ['name' => 'Test']]; diff --git a/tests/Unit/Service/MailFilter/FilterValidatorTest.php b/tests/Unit/Service/MailFilter/FilterValidatorTest.php index fd433831a0..bd6ef9762d 100644 --- a/tests/Unit/Service/MailFilter/FilterValidatorTest.php +++ b/tests/Unit/Service/MailFilter/FilterValidatorTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Service\MailFilter\FilterValidator; use OCP\AppFramework\Http; -class FilterValidatorTest extends TestCase { +final class FilterValidatorTest extends TestCase { private FilterValidator $validator; protected function setUp(): void { @@ -50,25 +50,23 @@ public function testValid(array $filters): void { $this->validator->validate($filters); } - public static function dataValid(): array { - return [ - 'no filters' => [[]], - 'filter' => [[self::filter()]], - 'any of' => [[self::filter(['operator' => FilterBuilder::OPERATOR_ANY])]], - 'priority as numeric string' => [[self::filter(['priority' => '20'])]], - 'all incoming messages' => [[self::filter(['operator' => FilterBuilder::OPERATOR_TRUE, 'tests' => []])]], - 'stored without conditions' => [[self::filter(['tests' => []])]], - 'stored with empty values' => [[self::filter(['tests' => [['field' => 'subject', 'operator' => 'contains', 'values' => []]]])]], - 'stored with empty mailbox' => [[self::filter(['enable' => false, 'actions' => [['type' => 'fileinto', 'mailbox' => '']]])]], - 'all action types' => [[self::filter(['actions' => [ - ['type' => 'fileinto', 'mailbox' => 'Archive'], - ['type' => 'addflag', 'flag' => 'Important'], - ['type' => 'addsystemflag', 'flag' => '\\Seen'], - ['type' => 'redirect', 'recipient' => 'alice@example.org'], - ['type' => 'keep'], - ['type' => 'stop'], - ]])]], - ]; + public static function dataValid(): \Iterator { + yield 'no filters' => [[]]; + yield 'filter' => [[self::filter()]]; + yield 'any of' => [[self::filter(['operator' => FilterBuilder::OPERATOR_ANY])]]; + yield 'priority as numeric string' => [[self::filter(['priority' => '20'])]]; + yield 'all incoming messages' => [[self::filter(['operator' => FilterBuilder::OPERATOR_TRUE, 'tests' => []])]]; + yield 'stored without conditions' => [[self::filter(['tests' => []])]]; + yield 'stored with empty values' => [[self::filter(['tests' => [['field' => 'subject', 'operator' => 'contains', 'values' => []]]])]]; + yield 'stored with empty mailbox' => [[self::filter(['enable' => false, 'actions' => [['type' => 'fileinto', 'mailbox' => '']]])]]; + yield 'all action types' => [[self::filter(['actions' => [ + ['type' => 'fileinto', 'mailbox' => 'Archive'], + ['type' => 'addflag', 'flag' => 'Important'], + ['type' => 'addsystemflag', 'flag' => '\\Seen'], + ['type' => 'redirect', 'recipient' => 'alice@example.org'], + ['type' => 'keep'], + ['type' => 'stop'], + ]])]]; } /** @@ -81,27 +79,25 @@ public function testInvalid(array $filters, string $message): void { $this->validator->validate($filters); } - public static function dataInvalid(): array { - return [ - 'filters not a list' => [['a' => self::filter()], 'Filters must be a list'], - 'filter not an array' => [['filter'], 'Filter 0 has an invalid definition'], - 'reports the position' => [[self::filter(), self::filter(['name' => ''])], 'Filter 1 has an invalid name'], - 'missing name' => [[self::filter(['name' => null])], 'Filter 0 has an invalid name'], - 'name with line break' => [[self::filter(['name' => "Marketing\r\nkeep;"])], 'Filter 0 has an invalid name'], - 'enable not a bool' => [[self::filter(['enable' => 'true'])], 'Filter 0 has an invalid enable'], - 'negative priority' => [[self::filter(['priority' => '-1'])], 'Filter 0 has an invalid priority'], - 'priority not a number' => [[self::filter(['priority' => '10 or'])], 'Filter 0 has an invalid priority'], - 'unknown operator' => [[self::filter(['operator' => 'not'])], 'Filter 0 has an invalid operator'], - 'tests not a list' => [[self::filter(['tests' => 'from'])], 'Filter 0 has an invalid tests'], - 'all incoming messages with conditions' => [[self::filter(['operator' => FilterBuilder::OPERATOR_TRUE])], 'Filter 0 has an invalid tests'], - 'unknown test field' => [[self::filter(['tests' => [['field' => 'cc', 'operator' => 'is', 'values' => []]]])], 'Filter 0 has an invalid test'], - 'unknown test operator' => [[self::filter(['tests' => [['field' => 'to', 'operator' => 'is" "x', 'values' => []]]])], 'Filter 0 has an invalid test'], - 'values not a list' => [[self::filter(['tests' => [['field' => 'to', 'operator' => 'is', 'values' => 'bob']]])], 'Filter 0 has an invalid test'], - 'value not a string' => [[self::filter(['tests' => [['field' => 'to', 'operator' => 'is', 'values' => [['bob']]]]])], 'Filter 0 has an invalid test'], - 'actions not a list' => [[self::filter(['actions' => 'stop'])], 'Filter 0 has an invalid actions'], - 'unknown action' => [[self::filter(['actions' => [['type' => 'discard']]])], 'Filter 0 has an invalid action'], - 'action without parameter' => [[self::filter(['actions' => [['type' => 'redirect']]])], 'Filter 0 has an invalid action'], - ]; + public static function dataInvalid(): \Iterator { + yield 'filters not a list' => [['a' => self::filter()], 'Filters must be a list']; + yield 'filter not an array' => [['filter'], 'Filter 0 has an invalid definition']; + yield 'reports the position' => [[self::filter(), self::filter(['name' => ''])], 'Filter 1 has an invalid name']; + yield 'missing name' => [[self::filter(['name' => null])], 'Filter 0 has an invalid name']; + yield 'name with line break' => [[self::filter(['name' => "Marketing\r\nkeep;"])], 'Filter 0 has an invalid name']; + yield 'enable not a bool' => [[self::filter(['enable' => 'true'])], 'Filter 0 has an invalid enable']; + yield 'negative priority' => [[self::filter(['priority' => '-1'])], 'Filter 0 has an invalid priority']; + yield 'priority not a number' => [[self::filter(['priority' => '10 or'])], 'Filter 0 has an invalid priority']; + yield 'unknown operator' => [[self::filter(['operator' => 'not'])], 'Filter 0 has an invalid operator']; + yield 'tests not a list' => [[self::filter(['tests' => 'from'])], 'Filter 0 has an invalid tests']; + yield 'all incoming messages with conditions' => [[self::filter(['operator' => FilterBuilder::OPERATOR_TRUE])], 'Filter 0 has an invalid tests']; + yield 'unknown test field' => [[self::filter(['tests' => [['field' => 'cc', 'operator' => 'is', 'values' => []]]])], 'Filter 0 has an invalid test']; + yield 'unknown test operator' => [[self::filter(['tests' => [['field' => 'to', 'operator' => 'is" "x', 'values' => []]]])], 'Filter 0 has an invalid test']; + yield 'values not a list' => [[self::filter(['tests' => [['field' => 'to', 'operator' => 'is', 'values' => 'bob']]])], 'Filter 0 has an invalid test']; + yield 'value not a string' => [[self::filter(['tests' => [['field' => 'to', 'operator' => 'is', 'values' => [['bob']]]]])], 'Filter 0 has an invalid test']; + yield 'actions not a list' => [[self::filter(['actions' => 'stop'])], 'Filter 0 has an invalid actions']; + yield 'unknown action' => [[self::filter(['actions' => [['type' => 'discard']]])], 'Filter 0 has an invalid action']; + yield 'action without parameter' => [[self::filter(['actions' => [['type' => 'redirect']]])], 'Filter 0 has an invalid action']; } public function testHttpCode(): void { diff --git a/tests/Unit/Service/MailManagerTest.php b/tests/Unit/Service/MailManagerTest.php index 9d2e8079bc..1ba70cc805 100644 --- a/tests/Unit/Service/MailManagerTest.php +++ b/tests/Unit/Service/MailManagerTest.php @@ -36,7 +36,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class MailManagerTest extends TestCase { +final class MailManagerTest extends TestCase { /** @var ProtocolFactory|MockObject */ private $protocolFactory; @@ -89,7 +89,7 @@ protected function setUp(): void { ); } - public function testGetFolders() { + public function testGetFolders(): void { /** @var Account|MockObject $account */ $account = $this->createStub(Account::class); $mailboxes = [ @@ -114,7 +114,7 @@ public function testGetFolders() { $this->assertSame($mailboxes, $result); } - public function testCreateFolder() { + public function testCreateFolder(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailboxConnector = $this->createMock(IMailboxConnector::class); @@ -547,8 +547,9 @@ public function testUpdateTagUnknownTag(): void { $this->manager->updateTag(100, 'Hello Hello 👋', '#0082c9', 'admin'); } - public static function threadOperations(): array { - return [['move'], ['delete']]; + public static function threadOperations(): \Iterator { + yield ['move']; + yield ['delete']; } /** @dataProvider threadOperations */ diff --git a/tests/Unit/Service/MimeMessageTest.php b/tests/Unit/Service/MimeMessageTest.php index 146a3bf26c..40b199c92b 100644 --- a/tests/Unit/Service/MimeMessageTest.php +++ b/tests/Unit/Service/MimeMessageTest.php @@ -18,7 +18,7 @@ use OCA\Mail\Service\DataUri\DataUriParser; use OCA\Mail\Service\MimeMessage; -class MimeMessageTest extends TestCase { +final class MimeMessageTest extends TestCase { private DataUriParser $uriParser; private MimeMessage $mimeMessage; private Account $account; @@ -31,7 +31,7 @@ protected function setUp(): void { $this->account = new Account(new MailAccount()); } - public function testTextPlain() { + public function testTextPlain(): void { $messageData = new NewMessageData( $this->account, new AddressList(), @@ -54,7 +54,7 @@ public function testTextPlain() { $this->assertEquals('text/plain', $part->getType()); } - public function testMultipartAlternative() { + public function testMultipartAlternative(): void { $messageData = new NewMessageData( $this->account, new AddressList(), @@ -83,7 +83,7 @@ public function testMultipartAlternative() { $this->assertEquals('text/html', $subParts[1]->getType()); } - public function testMultipartAlternativeEmptyContent() { + public function testMultipartAlternativeEmptyContent(): void { $messageData = new NewMessageData( $this->account, new AddressList(), @@ -112,7 +112,7 @@ public function testMultipartAlternativeEmptyContent() { $this->assertEquals('text/html', $subParts[1]->getType()); } - public function testMultipartMixedAlternative() { + public function testMultipartMixedAlternative(): void { $messageData = new NewMessageData( $this->account, new AddressList(), @@ -159,7 +159,7 @@ public function testMultipartMixedAlternative() { $this->assertEquals('attachment', $attachmentPart->getDisposition()); } - public function testMultipartMixedRelated() { + public function testMultipartMixedRelated(): void { $messageData = new NewMessageData( $this->account, new AddressList(), @@ -332,7 +332,7 @@ public function testRewriteSrcToCidFromDataCidAttribute(): void { $this->assertStringNotContainsString('data-cid', $htmlBody); } - public function testMultipartAlternativeGreek() { + public function testMultipartAlternativeGreek(): void { $messageData = new NewMessageData( $this->account, new AddressList(), diff --git a/tests/Unit/Service/OauthStateServiceTest.php b/tests/Unit/Service/OauthStateServiceTest.php index 12e1ff1b17..14fc3da90f 100644 --- a/tests/Unit/Service/OauthStateServiceTest.php +++ b/tests/Unit/Service/OauthStateServiceTest.php @@ -16,7 +16,7 @@ use OCP\Security\ICrypto; use PHPUnit\Framework\MockObject\MockObject; -class OauthStateServiceTest extends TestCase { +final class OauthStateServiceTest extends TestCase { private ICrypto&MockObject $crypto; private ITimeFactory&MockObject $time; private OauthStateService $service; diff --git a/tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php b/tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php index f09630ed6e..a2c1eeb562 100644 --- a/tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php +++ b/tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Service\OutOfOffice\OutOfOfficeParser; use OCA\Mail\Service\OutOfOffice\OutOfOfficeState; -class OutOfOfficeParserTest extends TestCase { +final class OutOfOfficeParserTest extends TestCase { private OutOfOfficeParser $outOfOfficeParser; protected function setUp(): void { diff --git a/tests/Unit/Service/OutOfOfficeServiceTest.php b/tests/Unit/Service/OutOfOfficeServiceTest.php index 0792facf82..068a0567b7 100644 --- a/tests/Unit/Service/OutOfOfficeServiceTest.php +++ b/tests/Unit/Service/OutOfOfficeServiceTest.php @@ -21,7 +21,7 @@ use OCP\IUser; use OCP\User\IOutOfOfficeData; -class OutOfOfficeServiceTest extends TestCase { +final class OutOfOfficeServiceTest extends TestCase { private ServiceMockObject $serviceMock; private OutOfOfficeService $outOfOfficeService; @@ -62,12 +62,10 @@ public function testFollowSystemWithNotFollowingAccount(): void { $this->outOfOfficeService->updateFromSystem($mailAccount, $user); } - public function enabledOutOfOfficeDataProvider(): array { + public function enabledOutOfOfficeDataProvider(): \Iterator { $user = $this->createMock(IUser::class); - return [ - [$this->createOutOfOfficeData('2', $user, 1000, 2000, 'Subject', 'Message')], - [$this->createOutOfOfficeData('2', $user, 1500, 2000, 'Subject', 'Message')], - ]; + yield [$this->createOutOfOfficeData('2', $user, 1000, 2000, 'Subject', 'Message')]; + yield [$this->createOutOfOfficeData('2', $user, 1500, 2000, 'Subject', 'Message')]; } /** @@ -141,12 +139,10 @@ public function testUpdateFromSystemWithEnabledOutOfOffice(?IOutOfOfficeData $da self::assertEquals('Message', $state->getMessage()); } - public function disabledOutOfOfficeDataProvider(): array { + public function disabledOutOfOfficeDataProvider(): \Iterator { $user = $this->createMock(IUser::class); - return [ - [$this->createOutOfOfficeData('2', $user, 1000, 1250, 'Subject', 'Message')], - [$this->createOutOfOfficeData('2', $user, 1750, 2000, 'Subject', 'Message')], - ]; + yield [$this->createOutOfOfficeData('2', $user, 1000, 1250, 'Subject', 'Message')]; + yield [$this->createOutOfOfficeData('2', $user, 1750, 2000, 'Subject', 'Message')]; } /** diff --git a/tests/Unit/Service/OutboxServiceTest.php b/tests/Unit/Service/OutboxServiceTest.php index 680a4cd518..224ee2a832 100644 --- a/tests/Unit/Service/OutboxServiceTest.php +++ b/tests/Unit/Service/OutboxServiceTest.php @@ -31,7 +31,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class OutboxServiceTest extends TestCase { +final class OutboxServiceTest extends TestCase { /** @var LocalMessageMapper|MockObject */ private $mapper; diff --git a/tests/Unit/Service/Phishing/ContactCheckTest.php b/tests/Unit/Service/Phishing/ContactCheckTest.php index f21e147dab..36aa297acd 100644 --- a/tests/Unit/Service/Phishing/ContactCheckTest.php +++ b/tests/Unit/Service/Phishing/ContactCheckTest.php @@ -1,5 +1,7 @@ assertEquals(0, $count); } - public function testDisabledAppDoesUnprovision() { + public function testDisabledAppDoesUnprovision(): void { /** @var IUser|MockObject $user */ $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com', @@ -86,7 +88,7 @@ public function testDisabledAppDoesUnprovision() { $this->assertFalse($result); } - public function testUpdateProvisionSingleUser() { + public function testUpdateProvisionSingleUser(): void { /** @var IUser|MockObject $user */ $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com', @@ -116,7 +118,7 @@ public function testUpdateProvisionSingleUser() { $this->assertTrue($result); } - public function testProvisionSingleUser() { + public function testProvisionSingleUser(): void { /** @var IUser|MockObject $user */ $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com', @@ -153,7 +155,7 @@ public function testProvisionSingleUser() { $this->assertTrue($result); } - public function testUpdateProvisionSingleUserWithWildcard() { + public function testUpdateProvisionSingleUserWithWildcard(): void { /** @var IUser|MockObject $user */ $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com', @@ -183,7 +185,7 @@ public function testUpdateProvisionSingleUserWithWildcard() { $this->assertTrue($result); } - public function testProvisionSingleUserWithWildcard() { + public function testProvisionSingleUserWithWildcard(): void { /** @var IUser|MockObject $user */ $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com', @@ -217,7 +219,7 @@ public function testProvisionSingleUserWithWildcard() { $this->assertTrue($result); } - public function testProvisionSingleUserNoDomainMatch() { + public function testProvisionSingleUserNoDomainMatch(): void { /** @var IUser|MockObject $user */ $user = $this->createConfiguredMock(IUser::class, [ 'getEmailAddress' => 'bruce.wayne@batman.com' @@ -248,7 +250,7 @@ public function testProvisionSingleUserNoDomainMatch() { $this->assertFalse($result); } - public function testDeprovision() { + public function testDeprovision(): void { $config = new Provisioning(); $config->setProvisioningDomain('*'); $config->setId(1); @@ -441,19 +443,17 @@ private function expectNoAccountWrite(): void { ->method('insert'); } - public function provideUnresolvableLdapValues(): array { - return [ - 'empty' => [''], - 'control characters' => ["BWAYNE\r\nX"], - 'invalid UTF-8' => ["BWAYNE\xFF"], - 'space' => ['Bruce Wayne'], - 'unicode line separator' => ["BWAYNE\u{2028}X"], - 'trailing newline' => ["BWAYNE\n"], - 'trailing carriage return' => ["BWAYNE\r"], - 'comma escaping the domain' => ['ceo@evil.example,x'], - 'angle brackets escaping the domain' => ['a@b.com'], - 'longer than the account column' => [str_repeat('a', 65)], - ]; + public function provideUnresolvableLdapValues(): \Iterator { + yield 'empty' => ['']; + yield 'control characters' => ["BWAYNE\r\nX"]; + yield 'invalid UTF-8' => ["BWAYNE\xFF"]; + yield 'space' => ['Bruce Wayne']; + yield 'unicode line separator' => ["BWAYNE\u{2028}X"]; + yield 'trailing newline' => ["BWAYNE\n"]; + yield 'trailing carriage return' => ["BWAYNE\r"]; + yield 'comma escaping the domain' => ['ceo@evil.example,x']; + yield 'angle brackets escaping the domain' => ['a@b.com']; + yield 'longer than the account column' => [str_repeat('a', 65)]; } /** diff --git a/tests/Unit/Service/QuickActionsServiceTest.php b/tests/Unit/Service/QuickActionsServiceTest.php index 6816c1e885..21d8e044b1 100644 --- a/tests/Unit/Service/QuickActionsServiceTest.php +++ b/tests/Unit/Service/QuickActionsServiceTest.php @@ -19,7 +19,7 @@ use OCP\AppFramework\Db\DoesNotExistException; use PHPUnit\Framework\MockObject\MockObject; -class QuickActionsServiceTest extends TestCase { +final class QuickActionsServiceTest extends TestCase { /** @var ActionsMapper|MockObject */ private $actionsMapper; diff --git a/tests/Unit/Service/Search/MailSearchTest.php b/tests/Unit/Service/Search/MailSearchTest.php index 66f822a974..b04244b925 100644 --- a/tests/Unit/Service/Search/MailSearchTest.php +++ b/tests/Unit/Service/Search/MailSearchTest.php @@ -25,7 +25,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use PHPUnit\Framework\MockObject\MockObject; -class MailSearchTest extends TestCase { +final class MailSearchTest extends TestCase { /** @var FilterStringParser|MockObject */ private $filterStringParser; @@ -62,7 +62,7 @@ protected function setUp(): void { ); } - public function testFindMessagesNotCached() { + public function testFindMessagesNotCached(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setSyncNewToken('abc'); @@ -81,7 +81,7 @@ public function testFindMessagesNotCached() { ); } - public function testFindMessagesLocked() { + public function testFindMessagesLocked(): void { $account = $this->createStub(Account::class); $mailbox = new Mailbox(); $mailbox->setSyncNewLock(123); @@ -99,7 +99,7 @@ public function testFindMessagesLocked() { ); } - public function testNoFindMessages() { + public function testNoFindMessages(): void { $account = $this->createMock(Account::class); $account->expects($this->once()) ->method('getUserId') @@ -123,7 +123,7 @@ public function testNoFindMessages() { $this->assertEmpty($messages); } - public function testFindFlagsLocally() { + public function testFindFlagsLocally(): void { $account = $this->createMock(Account::class); $account->expects($this->once()) ->method('getUserId') @@ -164,7 +164,7 @@ public function testFindFlagsLocally() { $this->assertCount(2, $messages); } - public function testFindText() { + public function testFindText(): void { $account = $this->createMock(Account::class); $account->expects($this->once()) ->method('getUserId') diff --git a/tests/Unit/Service/SetupServiceTest.php b/tests/Unit/Service/SetupServiceTest.php index dc6581cae0..5889af04f4 100644 --- a/tests/Unit/Service/SetupServiceTest.php +++ b/tests/Unit/Service/SetupServiceTest.php @@ -27,7 +27,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class SetupServiceTest extends TestCase { +final class SetupServiceTest extends TestCase { private const ACCOUNT_NAME = 'Test Account'; private const EMAIL_ADDRESS = 'test@example.com'; private const IMAP_HOST = 'imap.example.com'; diff --git a/tests/Unit/Service/SharingRestrictionServiceTest.php b/tests/Unit/Service/SharingRestrictionServiceTest.php index 4a2f6e3302..c10dd05646 100644 --- a/tests/Unit/Service/SharingRestrictionServiceTest.php +++ b/tests/Unit/Service/SharingRestrictionServiceTest.php @@ -84,15 +84,13 @@ private function configureUsers(array $groupsByUid): array { return $users; } - public static function legacyUserShareProvider(): array { - return [ - 'no restrictions' => [[], ['bob' => ['group-a'], 'alice' => ['group-b']], true], - 'common group' => [['groupMembersOnly' => true, 'excludedGroups' => ['everyone']], ['bob' => ['everyone', 'team'], 'alice' => ['everyone', 'team']], true], - 'sharing api disabled' => [['apiEnabled' => false], ['bob' => ['team'], 'alice' => ['team']], false], - 'sharing disabled for sharer' => [['disabledForUser' => true], ['bob' => ['team'], 'alice' => ['team']], false], - 'no common group' => [['groupMembersOnly' => true], ['bob' => ['group-a'], 'alice' => ['group-b']], false], - 'only common group is excluded' => [['groupMembersOnly' => true, 'excludedGroups' => ['everyone']], ['bob' => ['everyone', 'group-a'], 'alice' => ['everyone', 'group-b']], false], - ]; + public static function legacyUserShareProvider(): \Iterator { + yield 'no restrictions' => [[], ['bob' => ['group-a'], 'alice' => ['group-b']], true]; + yield 'common group' => [['groupMembersOnly' => true, 'excludedGroups' => ['everyone']], ['bob' => ['everyone', 'team'], 'alice' => ['everyone', 'team']], true]; + yield 'sharing api disabled' => [['apiEnabled' => false], ['bob' => ['team'], 'alice' => ['team']], false]; + yield 'sharing disabled for sharer' => [['disabledForUser' => true], ['bob' => ['team'], 'alice' => ['team']], false]; + yield 'no common group' => [['groupMembersOnly' => true], ['bob' => ['group-a'], 'alice' => ['group-b']], false]; + yield 'only common group is excluded' => [['groupMembersOnly' => true, 'excludedGroups' => ['everyone']], ['bob' => ['everyone', 'group-a'], 'alice' => ['everyone', 'group-b']], false]; } /** @@ -105,16 +103,14 @@ public function testLegacyCanShareWithUser(array $policy, array $groupsByUid, bo $this->assertSame($expected, $this->createLegacyService()->canShareWithUser('bob', $users['alice'])); } - public static function legacyGroupShareProvider(): array { - return [ - 'no restrictions' => [[], ['group-b'], true], - 'own group' => [['groupMembersOnly' => true], ['group-a'], true], - 'sharing api disabled' => [['apiEnabled' => false], ['group-a'], false], - 'sharing disabled for sharer' => [['disabledForUser' => true], ['group-a'], false], - 'group sharing disabled' => [['groupSharing' => false], ['group-a'], false], - 'not a member' => [['groupMembersOnly' => true], ['group-b'], false], - 'member of excluded group' => [['groupMembersOnly' => true, 'excludedGroups' => ['group-a']], ['group-a'], false], - ]; + public static function legacyGroupShareProvider(): \Iterator { + yield 'no restrictions' => [[], ['group-b'], true]; + yield 'own group' => [['groupMembersOnly' => true], ['group-a'], true]; + yield 'sharing api disabled' => [['apiEnabled' => false], ['group-a'], false]; + yield 'sharing disabled for sharer' => [['disabledForUser' => true], ['group-a'], false]; + yield 'group sharing disabled' => [['groupSharing' => false], ['group-a'], false]; + yield 'not a member' => [['groupMembersOnly' => true], ['group-b'], false]; + yield 'member of excluded group' => [['groupMembersOnly' => true, 'excludedGroups' => ['group-a']], ['group-a'], false]; } /** diff --git a/tests/Unit/Service/SieveServiceTest.php b/tests/Unit/Service/SieveServiceTest.php index 579345455f..740ee4768e 100644 --- a/tests/Unit/Service/SieveServiceTest.php +++ b/tests/Unit/Service/SieveServiceTest.php @@ -18,7 +18,7 @@ use OCA\Mail\Sieve\SieveClientFactory; use PHPUnit\Framework\MockObject\MockObject; -class SieveServiceTest extends TestCase { +final class SieveServiceTest extends TestCase { private SieveService $sieveService; /** @var SieveClientFactory|MockObject */ @@ -103,14 +103,12 @@ public function testGetActiveScriptNoName(): void { $this->assertEquals('', $actual->getScript()); } - public function scriptTrimDataProvider(): array { - return [ - ['# foo bar', '# foo bar'], - ["# foo bar\r\n", '# foo bar'], - ["# foo bar\r\n\r\n", '# foo bar'], - ["\r\n# foo bar", "\r\n# foo bar"], - ['# foo bar ', '# foo bar '], - ]; + public function scriptTrimDataProvider(): \Iterator { + yield ['# foo bar', '# foo bar']; + yield ["# foo bar\r\n", '# foo bar']; + yield ["# foo bar\r\n\r\n", '# foo bar']; + yield ["\r\n# foo bar", "\r\n# foo bar"]; + yield ['# foo bar ', '# foo bar ']; } /** diff --git a/tests/Unit/Service/SmimeServiceTest.php b/tests/Unit/Service/SmimeServiceTest.php index 5bc2df0262..e699bdd212 100644 --- a/tests/Unit/Service/SmimeServiceTest.php +++ b/tests/Unit/Service/SmimeServiceTest.php @@ -27,7 +27,7 @@ use OCP\Security\ICrypto; use PHPUnit\Framework\MockObject\MockObject; -class SmimeServiceTest extends TestCase { +final class SmimeServiceTest extends TestCase { private $tempFiles = []; /** @var ITempManager|MockObject */ @@ -91,7 +91,7 @@ private function createTempFile(): string { return $tempFile; } - public function testDecryptMimePartText() { + public function testDecryptMimePartText(): void { $encryptedMessage = file_get_contents(__DIR__ . '/../../data/encrypted-message.txt'); $decryptedBody = file_get_contents(__DIR__ . '/../../data/decrypted-message-body.txt'); @@ -227,14 +227,13 @@ public function testDecryptDataFetchWithRegularMessage(): void { ); } - public function provideIsEncryptedData(): array { - return [ - ['application/pkcs7-mime', ['smime-type' => 'enveloped-data'], true], - ['application/pkcs7-mime', ['smime-type' => 'signed-data'], false], - ['application/pkcs7-mime', [], false], // Should not happen in real life but who knows - ['multipart/alternative', [], false], - ['', [], false], - ]; + public function provideIsEncryptedData(): \Iterator { + yield ['application/pkcs7-mime', ['smime-type' => 'enveloped-data'], true]; + yield ['application/pkcs7-mime', ['smime-type' => 'signed-data'], false]; + yield ['application/pkcs7-mime', [], false]; + // Should not happen in real life but who knows + yield ['multipart/alternative', [], false]; + yield ['', [], false]; } /** @@ -315,7 +314,7 @@ public function testFindCertificatesByAddressList(): void { $this->assertCount(2, $certificates); } - public function testEncryptMimePartText() { + public function testEncryptMimePartText(): void { $certificateDomainTld = $this->getTestCertificate('user@domain.tld'); $certificateImapLocalhost = $this->getTestCertificate('user@imap.localhost'); @@ -362,78 +361,76 @@ public function testEncryptMimePartText() { $this->assertFalse($decryptionResult->isSigned()); } - public function provideParseCertificateData(): array { - return [ - [ - $this->getTestCertificate('user@imap.localhost'), - new SmimeCertificateInfo( - 'user', - 'user@imap.localhost', - 4862017735, - new SmimeCertificatePurposes(true, true), - true, - ), - ], - [ - $this->getTestCertificate('cn-only@imap.localhost'), - new SmimeCertificateInfo( - 'cn-only', - 'cn-only@imap.localhost', - 4862017727, - new SmimeCertificatePurposes(true, true), - true, - ), - ], - [ - $this->getTestCertificate('user@domain.tld'), - new SmimeCertificateInfo( - 'user', - 'user@domain.tld', - 4862017705, - new SmimeCertificatePurposes(true, true), - false, - ), - ], - [ // Full chain: Leaf -> Intermediate CA -> CA - $this->getTestCertificate('chain@imap.localhost'), - new SmimeCertificateInfo( - 'chain', - 'chain@imap.localhost', - 4870519697, - new SmimeCertificatePurposes(true, true), - true, - ), - ], - [ // Partial chain: Leaf -> Intermediate CA - $this->getTestCertificate('chain-partial@imap.localhost'), - new SmimeCertificateInfo( - 'chain', - 'chain@imap.localhost', - 4870519697, - new SmimeCertificatePurposes(true, true), - true, - ), - ], - [ // Leaf only - $this->getTestCertificate('chain-leaf-only@imap.localhost'), - new SmimeCertificateInfo( - 'chain', - 'chain@imap.localhost', - 4870519697, - new SmimeCertificatePurposes(true, true), - false, - ), - ], - [ // Email address only in SAN, not in Subject (RFC 8550 / government PKI pattern) - $this->getTestCertificate('san-only@imap.localhost'), - new SmimeCertificateInfo( - 'SAN Only User', - 'san-only@imap.localhost', - 4927747705, - new SmimeCertificatePurposes(true, true), - false, - ), - ], + public function provideParseCertificateData(): \Iterator { + yield [ + $this->getTestCertificate('user@imap.localhost'), + new SmimeCertificateInfo( + 'user', + 'user@imap.localhost', + 4862017735, + new SmimeCertificatePurposes(true, true), + true, + ), + ]; + yield [ + $this->getTestCertificate('cn-only@imap.localhost'), + new SmimeCertificateInfo( + 'cn-only', + 'cn-only@imap.localhost', + 4862017727, + new SmimeCertificatePurposes(true, true), + true, + ), + ]; + yield [ + $this->getTestCertificate('user@domain.tld'), + new SmimeCertificateInfo( + 'user', + 'user@domain.tld', + 4862017705, + new SmimeCertificatePurposes(true, true), + false, + ), + ]; + yield [ // Full chain: Leaf -> Intermediate CA -> CA + $this->getTestCertificate('chain@imap.localhost'), + new SmimeCertificateInfo( + 'chain', + 'chain@imap.localhost', + 4870519697, + new SmimeCertificatePurposes(true, true), + true, + ), + ]; + yield [ // Partial chain: Leaf -> Intermediate CA + $this->getTestCertificate('chain-partial@imap.localhost'), + new SmimeCertificateInfo( + 'chain', + 'chain@imap.localhost', + 4870519697, + new SmimeCertificatePurposes(true, true), + true, + ), + ]; + yield [ // Leaf only + $this->getTestCertificate('chain-leaf-only@imap.localhost'), + new SmimeCertificateInfo( + 'chain', + 'chain@imap.localhost', + 4870519697, + new SmimeCertificatePurposes(true, true), + false, + ), + ]; + yield [ // Email address only in SAN, not in Subject (RFC 8550 / government PKI pattern) + $this->getTestCertificate('san-only@imap.localhost'), + new SmimeCertificateInfo( + 'SAN Only User', + 'san-only@imap.localhost', + 4927747705, + new SmimeCertificatePurposes(true, true), + false, + ), ]; } @@ -456,11 +453,9 @@ public function testParseCertificate(SmimeCertificate $certificate, ); } - public static function provideCertificatesWithRepeatedSubjectFields(): array { - return [ - 'repeated common name' => ['repeated-common-name@imap.localhost', 'Alice', 'alice@imap.localhost'], - 'repeated email address' => ['repeated-email-address@imap.localhost', 'Alice', 'alice@imap.localhost'], - ]; + public static function provideCertificatesWithRepeatedSubjectFields(): \Iterator { + yield 'repeated common name' => ['repeated-common-name@imap.localhost', 'Alice', 'alice@imap.localhost']; + yield 'repeated email address' => ['repeated-email-address@imap.localhost', 'Alice', 'alice@imap.localhost']; } /** @@ -509,7 +504,7 @@ public function testSignMimePart(): void { )); } - public function testSignAndEncryptMimePart() { + public function testSignAndEncryptMimePart(): void { $certificateDomainTld = $this->getTestCertificate('user@domain.tld'); $certificateImapLocalhost = $this->getTestCertificate('user@imap.localhost'); diff --git a/tests/Unit/Service/Sync/ImapToDbSynchronizerTest.php b/tests/Unit/Service/Sync/ImapToDbSynchronizerTest.php index ba800d6e2c..110b30b013 100644 --- a/tests/Unit/Service/Sync/ImapToDbSynchronizerTest.php +++ b/tests/Unit/Service/Sync/ImapToDbSynchronizerTest.php @@ -31,7 +31,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class ImapToDbSynchronizerTest extends TestCase { +final class ImapToDbSynchronizerTest extends TestCase { private DatabaseMessageMapper&MockObject $dbMapper; private ProtocolFactory&MockObject $protocolFactory; private ImapMessageMapper&MockObject $imapMapper; diff --git a/tests/Unit/Service/TransmissionServiceTest.php b/tests/Unit/Service/TransmissionServiceTest.php index 03d3e5cb3a..e0deb395e6 100644 --- a/tests/Unit/Service/TransmissionServiceTest.php +++ b/tests/Unit/Service/TransmissionServiceTest.php @@ -24,7 +24,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -class TransmissionServiceTest extends TestCase { +final class TransmissionServiceTest extends TestCase { private GroupsIntegration|MockObject $groupsIntegration; private AttachmentService|MockObject $attachmentService; @@ -44,7 +44,7 @@ protected function setUp(): void { ); } - public function testGetAddressList() { + public function testGetAddressList(): void { $expected = new AddressList([Address::fromRaw('Bob', 'bob@test.com')]); $recipient = new Recipient(); $recipient->setLabel('Bob'); @@ -62,7 +62,7 @@ public function testGetAddressList() { $this->assertEquals($expected, $actual); } - public function testGetAttachments() { + public function testGetAttachments(): void { $id = 1; $expected = [[ 'type' => 'local', diff --git a/tests/Unit/Service/TrustedSenderServiceTest.php b/tests/Unit/Service/TrustedSenderServiceTest.php index 1cfc440179..f2cde7bf89 100644 --- a/tests/Unit/Service/TrustedSenderServiceTest.php +++ b/tests/Unit/Service/TrustedSenderServiceTest.php @@ -14,7 +14,7 @@ use OCA\Mail\Service\TrustedSenderService; use PHPUnit\Framework\MockObject\MockObject; -class TrustedSenderServiceTest extends TestCase { +final class TrustedSenderServiceTest extends TestCase { /** @var TrustedSenderMapper|MockObject */ private $mapper; diff --git a/tests/Unit/Service/UserPreferenceServiceTest.php b/tests/Unit/Service/UserPreferenceServiceTest.php index cb69a19933..57784d5673 100644 --- a/tests/Unit/Service/UserPreferenceServiceTest.php +++ b/tests/Unit/Service/UserPreferenceServiceTest.php @@ -1,5 +1,7 @@ service = new UserPreferenceService($this->config, $this->userId); } - public function testGetPreference() { + public function testGetPreference(): void { $this->config->expects($this->once()) ->method('getUserValue') ->with($this->userId, 'mail', 'test', null) @@ -40,7 +42,7 @@ public function testGetPreference() { $this->assertEquals($expected, $actual); } - public function testSetPreference() { + public function testSetPreference(): void { $this->config->expects($this->once()) ->method('setUserValue') ->with($this->userId, 'mail', 'test', '123') diff --git a/tests/Unit/Settings/AdminSettingsTest.php b/tests/Unit/Settings/AdminSettingsTest.php index 0a07a96ac6..0d6e7a5b4a 100644 --- a/tests/Unit/Settings/AdminSettingsTest.php +++ b/tests/Unit/Settings/AdminSettingsTest.php @@ -15,7 +15,7 @@ use OCA\Mail\Settings\AdminSettings; use OCP\AppFramework\Http\TemplateResponse; -class AdminSettingsTest extends TestCase { +final class AdminSettingsTest extends TestCase { /** @var ServiceMockObject */ private $serviceMock; @@ -30,13 +30,13 @@ protected function setUp(): void { $this->settings = $this->serviceMock->getService(); } - public function testGetSection() { + public function testGetSection(): void { $section = $this->settings->getSection(); $this->assertSame('groupware', $section); } - public function testGetForm() { + public function testGetForm(): void { $this->serviceMock->getParameter('initialStateService')->expects($this->exactly(16)) ->method('provideInitialState') ->withConsecutive( @@ -112,7 +112,7 @@ public function testGetForm() { $this->assertEquals($expected, $form); } - public function testGetPriority() { + public function testGetPriority(): void { $priority = $this->settings->getPriority(); $this->assertIsInt($priority); diff --git a/tests/Unit/SetupChecks/MailConnectionPerformanceTest.php b/tests/Unit/SetupChecks/MailConnectionPerformanceTest.php index 47c023fb88..97b66ec08e 100644 --- a/tests/Unit/SetupChecks/MailConnectionPerformanceTest.php +++ b/tests/Unit/SetupChecks/MailConnectionPerformanceTest.php @@ -25,7 +25,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\Test\TestLogger; -class MailConnectionPerformanceTest extends TestCase { +final class MailConnectionPerformanceTest extends TestCase { private IL10N&MockObject $l10n; private TestLogger $logger; diff --git a/tests/Unit/SetupChecks/MailTransportTest.php b/tests/Unit/SetupChecks/MailTransportTest.php index f45708e8bb..33350c74eb 100644 --- a/tests/Unit/SetupChecks/MailTransportTest.php +++ b/tests/Unit/SetupChecks/MailTransportTest.php @@ -17,7 +17,7 @@ use OCP\SetupCheck\SetupResult; use PHPUnit\Framework\MockObject\MockObject; -class MailTransportTest extends TestCase { +final class MailTransportTest extends TestCase { private IConfig&MockObject $config; private IL10N&MockObject $l10n; private MailTransport $check; diff --git a/tests/Unit/Sieve/SieveUtilsTest.php b/tests/Unit/Sieve/SieveUtilsTest.php index eacce6466a..1e86c24710 100644 --- a/tests/Unit/Sieve/SieveUtilsTest.php +++ b/tests/Unit/Sieve/SieveUtilsTest.php @@ -12,7 +12,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Sieve\SieveUtils; -class SieveUtilsTest extends TestCase { +final class SieveUtilsTest extends TestCase { /** * @dataProvider providerEscapeString */ @@ -21,14 +21,12 @@ public function testEscapeString(string $subject, string $expected): void { $this->assertSame($expected, $actual); } - public static function providerEscapeString(): array { - return [ - ['foo"bar', 'foo\"bar'], - ['foo\\bar', 'foo\\\\bar'], - ['foo"\\bar', 'foo\"\\\\bar'], - ['foobar', 'foobar'], - ['', ''], - ]; + public static function providerEscapeString(): \Iterator { + yield ['foo"bar', 'foo\"bar']; + yield ['foo\\bar', 'foo\\\\bar']; + yield ['foo"\\bar', 'foo\"\\\\bar']; + yield ['foobar', 'foobar']; + yield ['', '']; } /** @@ -39,13 +37,11 @@ public function testStringList(array $values, string $expected): void { $this->assertSame($expected, $actual); } - public static function providerStringList(): array { - return [ - [['Hello', 'World'], '["Hello", "World"]'], - [['foo"bar', 'foo\\bar'], '["foo\"bar", "foo\\\\bar"]'], - [['foo"bar', 'foo\\bar', 'foo"\\bar'], '["foo\"bar", "foo\\\\bar", "foo\"\\\\bar"]'], - [['foobar'], '["foobar"]'], - [[], '[""]'], - ]; + public static function providerStringList(): \Iterator { + yield [['Hello', 'World'], '["Hello", "World"]']; + yield [['foo"bar', 'foo\\bar'], '["foo\"bar", "foo\\\\bar"]']; + yield [['foo"bar', 'foo\\bar', 'foo"\\bar'], '["foo\"bar", "foo\\\\bar", "foo\"\\\\bar"]']; + yield [['foobar'], '["foobar"]']; + yield [[], '[""]']; } } diff --git a/tests/Unit/Support/HostNameFactoryTest.php b/tests/Unit/Support/HostNameFactoryTest.php index 0179a09cbc..dcf1ab01bf 100644 --- a/tests/Unit/Support/HostNameFactoryTest.php +++ b/tests/Unit/Support/HostNameFactoryTest.php @@ -13,7 +13,7 @@ use OCA\Mail\Support\HostNameFactory; use OCP\Util; -class HostNameFactoryTest extends TestCase { +final class HostNameFactoryTest extends TestCase { /** @var HostNameFactory */ private $factory; @@ -23,7 +23,7 @@ protected function setUp(): void { $this->factory = new HostNameFactory(); } - public function testGetHostName() { + public function testGetHostName(): void { $expected = Util::getServerHostName(); $actual = $this->factory->getHostName(); diff --git a/tests/Unit/UserMigration/MailAccountMigratorTest.php b/tests/Unit/UserMigration/MailAccountMigratorTest.php index af6f7cf8b2..33cbddced6 100644 --- a/tests/Unit/UserMigration/MailAccountMigratorTest.php +++ b/tests/Unit/UserMigration/MailAccountMigratorTest.php @@ -22,7 +22,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Output\OutputInterface; -class MailAccountMigratorTest extends TestCase { +final class MailAccountMigratorTest extends TestCase { use RecordsConsoleOutput; private const EXPORT_DELEGATIONS = [ diff --git a/tests/Unit/UserMigration/Service/AccountMigrationServiceTest.php b/tests/Unit/UserMigration/Service/AccountMigrationServiceTest.php index 34c377a3ff..76b8c66982 100644 --- a/tests/Unit/UserMigration/Service/AccountMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/AccountMigrationServiceTest.php @@ -24,7 +24,7 @@ use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class AccountMigrationServiceTest extends TestCase { +final class AccountMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = 'test_user'; @@ -616,15 +616,13 @@ public function testImportAliasWithoutName(): void { self::assertSame([null], $names); } - public static function provideInvalidAccountData(): array { - return [ - 'missing account id' => ['accountId'], - 'missing email address' => ['emailAddress'], - 'missing sieve flag' => ['sieveEnabled'], - 'missing special mailbox id' => ['sentMailboxId'], - 'missing mailboxes' => ['mailboxes'], - 'missing aliases' => ['aliases'], - ]; + public static function provideInvalidAccountData(): \Iterator { + yield 'missing account id' => ['accountId']; + yield 'missing email address' => ['emailAddress']; + yield 'missing sieve flag' => ['sieveEnabled']; + yield 'missing special mailbox id' => ['sentMailboxId']; + yield 'missing mailboxes' => ['mailboxes']; + yield 'missing aliases' => ['aliases']; } /** @@ -644,21 +642,19 @@ public function testImportSkipsAccountsMissingARequiredKey(string $key): void { self::assertSame(['accounts' => [], 'mailboxes' => []], $mappings); } - public static function provideMalformedAccountData(): array { - return [ - 'not an object' => ['not-an-account'], - 'account id is not an int' => [['accountId' => 'nineteen']], - 'mailboxes are not a list' => [['mailboxes' => ['unexpected' => 'object']]], - 'aliases are not a list' => [['aliases' => ['unexpected' => 'object']]], - 'mailbox is not an object' => [['mailboxes' => ['not-a-mailbox']]], - 'alias is not an object' => [['aliases' => ['not-an-alias']]], - 'unknown auth method' => [['authMethod' => 'plain']], - 'imap host is not a string' => [['imapHost' => 42]], - 'smtp host is not a string' => [['smtpHost' => ['smtp.doe.com']]], - 'sieve host is not a string' => [['sieveHost' => true]], - 'empty smtp host' => [['smtpHost' => '']], - 'sieve host made of dots' => [['sieveHost' => '..']], - ]; + public static function provideMalformedAccountData(): \Iterator { + yield 'not an object' => ['not-an-account']; + yield 'account id is not an int' => [['accountId' => 'nineteen']]; + yield 'mailboxes are not a list' => [['mailboxes' => ['unexpected' => 'object']]]; + yield 'aliases are not a list' => [['aliases' => ['unexpected' => 'object']]]; + yield 'mailbox is not an object' => [['mailboxes' => ['not-a-mailbox']]]; + yield 'alias is not an object' => [['aliases' => ['not-an-alias']]]; + yield 'unknown auth method' => [['authMethod' => 'plain']]; + yield 'imap host is not a string' => [['imapHost' => 42]]; + yield 'smtp host is not a string' => [['smtpHost' => ['smtp.doe.com']]]; + yield 'sieve host is not a string' => [['sieveHost' => true]]; + yield 'empty smtp host' => [['smtpHost' => '']]; + yield 'sieve host made of dots' => [['sieveHost' => '..']]; } /** @@ -677,12 +673,10 @@ public function testImportSkipsMalformedAccounts(mixed $payload): void { self::assertSame(['accounts' => [], 'mailboxes' => []], $mappings); } - public static function provideHostKeys(): array { - return [ - 'imap host' => ['imapHost'], - 'smtp host' => ['smtpHost'], - 'sieve host' => ['sieveHost'], - ]; + public static function provideHostKeys(): \Iterator { + yield 'imap host' => ['imapHost']; + yield 'smtp host' => ['smtpHost']; + yield 'sieve host' => ['sieveHost']; } /** @@ -769,12 +763,10 @@ public function testImportAssignsEveryRoleWhenTwoShareAMailbox(): void { self::assertSame(self::IMPORTED_SENT_ID, $this->savedAccount->getSentMailboxId()); } - public static function provideWronglyTypedAccountValues(): array { - return [ - 'order is a string' => ['order', 'abc'], - 'password is an int' => ['inboundPassword', 12345], - 'certificate id is an array' => ['smimeCertificateId', ['nope']], - ]; + public static function provideWronglyTypedAccountValues(): \Iterator { + yield 'order is a string' => ['order', 'abc']; + yield 'password is an int' => ['inboundPassword', 12345]; + yield 'certificate id is an array' => ['smimeCertificateId', ['nope']]; } /** diff --git a/tests/Unit/UserMigration/Service/AppConfigMigrationServiceTest.php b/tests/Unit/UserMigration/Service/AppConfigMigrationServiceTest.php index bef53af711..fcc6ebebfc 100644 --- a/tests/Unit/UserMigration/Service/AppConfigMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/AppConfigMigrationServiceTest.php @@ -20,7 +20,7 @@ use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class AppConfigMigrationServiceTest extends TestCase { +final class AppConfigMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = '123'; @@ -170,32 +170,30 @@ public function testImportRemapsAccountSettingsAndStartMailboxId(): void { ); } - public static function provideUnmappableReferences(): array { - return [ - 'account was not imported' => [ - AppConfigMigrationService::ACCOUNT_SETTINGS_KEY, - '[{"accountId":999,"collapsed":false}]', - ], - 'account settings are not a list' => [ - AppConfigMigrationService::ACCOUNT_SETTINGS_KEY, - '{"accountId":19}', - ], - 'account settings are invalid JSON' => [ - AppConfigMigrationService::ACCOUNT_SETTINGS_KEY, - 'not json at all', - ], - 'account settings entry without account id' => [ - AppConfigMigrationService::ACCOUNT_SETTINGS_KEY, - '[{"collapsed":false}]', - ], - 'start mailbox was not imported' => [ - AppConfigMigrationService::START_MAILBOX_ID_KEY, - '999', - ], - 'start mailbox is not numeric' => [ - AppConfigMigrationService::START_MAILBOX_ID_KEY, - '', - ], + public static function provideUnmappableReferences(): \Iterator { + yield 'account was not imported' => [ + AppConfigMigrationService::ACCOUNT_SETTINGS_KEY, + '[{"accountId":999,"collapsed":false}]', + ]; + yield 'account settings are not a list' => [ + AppConfigMigrationService::ACCOUNT_SETTINGS_KEY, + '{"accountId":19}', + ]; + yield 'account settings are invalid JSON' => [ + AppConfigMigrationService::ACCOUNT_SETTINGS_KEY, + 'not json at all', + ]; + yield 'account settings entry without account id' => [ + AppConfigMigrationService::ACCOUNT_SETTINGS_KEY, + '[{"collapsed":false}]', + ]; + yield 'start mailbox was not imported' => [ + AppConfigMigrationService::START_MAILBOX_ID_KEY, + '999', + ]; + yield 'start mailbox is not numeric' => [ + AppConfigMigrationService::START_MAILBOX_ID_KEY, + '', ]; } @@ -236,12 +234,10 @@ public function testImportNoFileIsBeingIgnored(): void { $this->migrationService->importAppConfiguration($this->user, $this->importSource, $this->output, [], []); } - public static function provideFileContentsWithNoSettingsImported(): array { - return [ - 'empty list' => [json_encode([])], - 'invalid JSON' => ['this is not valid json {{{'], - 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])], - ]; + public static function provideFileContentsWithNoSettingsImported(): \Iterator { + yield 'empty list' => [json_encode([])]; + yield 'invalid JSON' => ['this is not valid json {{{']; + yield 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])]; } /** diff --git a/tests/Unit/UserMigration/Service/InternalAddressesMigrationServiceTest.php b/tests/Unit/UserMigration/Service/InternalAddressesMigrationServiceTest.php index fe9e9ce5ea..4a2360d839 100644 --- a/tests/Unit/UserMigration/Service/InternalAddressesMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/InternalAddressesMigrationServiceTest.php @@ -20,7 +20,7 @@ use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class InternalAddressesMigrationServiceTest extends TestCase { +final class InternalAddressesMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = '123'; @@ -111,12 +111,10 @@ public function testImportMultipleInternalAddresses(): void { $this->migrationService->importInternalAddresses($this->user, $this->importSource, $this->output); } - public static function provideFileContentsWithNoInternalAddressesImported(): array { - return [ - 'empty list' => [json_encode([])], - 'invalid JSON' => ['this is not valid json {{{'], - 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])], - ]; + public static function provideFileContentsWithNoInternalAddressesImported(): \Iterator { + yield 'empty list' => [json_encode([])]; + yield 'invalid JSON' => ['this is not valid json {{{']; + yield 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])]; } /** diff --git a/tests/Unit/UserMigration/Service/LegacyAccountMigrationServiceTest.php b/tests/Unit/UserMigration/Service/LegacyAccountMigrationServiceTest.php index c9858ac34d..4674bd4660 100644 --- a/tests/Unit/UserMigration/Service/LegacyAccountMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/LegacyAccountMigrationServiceTest.php @@ -21,7 +21,7 @@ use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class LegacyAccountMigrationServiceTest extends TestCase { +final class LegacyAccountMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = 'test_user'; @@ -137,20 +137,18 @@ public function testImportWithoutIndexImportsNothing(): void { self::assertSame([], $mapping); } - public static function provideUnusableAccountFiles(): array { - return [ - 'not valid JSON' => ['this is not json {{{'], - 'not an object' => ['"just a string"'], - 'missing email address' => ['{"imapHost":"imap.doe.com"}'], - 'missing imap host' => ['{"emailAddress":"jane@doe.com"}'], - 'incomplete imap settings' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com"}'], - 'imap host is not a string' => ['{"emailAddress":"jane@doe.com","imapHost":42,"imapPort":993,"imapSslMode":"ssl"}'], - 'unknown auth method' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com","imapPort":993,"imapSslMode":"ssl","authMethod":"plain"}'], - 'empty imap host' => ['{"emailAddress":"jane@doe.com","imapHost":"","imapPort":993,"imapSslMode":"ssl"}'], - 'smtp host is not a string' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com","imapPort":993,"imapSslMode":"ssl","smtpHost":42}'], - 'sieve host is not a string' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com","imapPort":993,"imapSslMode":"ssl","sieveHost":true}'], - 'smtp host made of dots' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com","imapPort":993,"imapSslMode":"ssl","smtpHost":"."}'], - ]; + public static function provideUnusableAccountFiles(): \Iterator { + yield 'not valid JSON' => ['this is not json {{{']; + yield 'not an object' => ['"just a string"']; + yield 'missing email address' => ['{"imapHost":"imap.doe.com"}']; + yield 'missing imap host' => ['{"emailAddress":"jane@doe.com"}']; + yield 'incomplete imap settings' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com"}']; + yield 'imap host is not a string' => ['{"emailAddress":"jane@doe.com","imapHost":42,"imapPort":993,"imapSslMode":"ssl"}']; + yield 'unknown auth method' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com","imapPort":993,"imapSslMode":"ssl","authMethod":"plain"}']; + yield 'empty imap host' => ['{"emailAddress":"jane@doe.com","imapHost":"","imapPort":993,"imapSslMode":"ssl"}']; + yield 'smtp host is not a string' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com","imapPort":993,"imapSslMode":"ssl","smtpHost":42}']; + yield 'sieve host is not a string' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com","imapPort":993,"imapSslMode":"ssl","sieveHost":true}']; + yield 'smtp host made of dots' => ['{"emailAddress":"jane@doe.com","imapHost":"imap.doe.com","imapPort":993,"imapSslMode":"ssl","smtpHost":"."}']; } /** @@ -170,12 +168,10 @@ public function testImportSkipsUnusableAccountFiles(string $contents): void { self::assertSame([], $mapping); } - public static function provideDisallowedHosts(): array { - return [ - 'imap host' => [['imapHost' => self::DISALLOWED_HOST]], - 'smtp host' => [['smtpHost' => self::DISALLOWED_HOST]], - 'sieve host' => [['sieveHost' => self::DISALLOWED_HOST]], - ]; + public static function provideDisallowedHosts(): \Iterator { + yield 'imap host' => [['imapHost' => self::DISALLOWED_HOST]]; + yield 'smtp host' => [['smtpHost' => self::DISALLOWED_HOST]]; + yield 'sieve host' => [['sieveHost' => self::DISALLOWED_HOST]]; } /** @@ -236,11 +232,9 @@ public function testImportTreatsAMissingAuthMethodAsPassword(): void { self::assertSame('imap_secret_encrypted', $this->savedAccount->getInboundPassword()); } - public static function provideWronglyTypedAccountValues(): array { - return [ - 'password is an int' => ['inboundPassword', 12345], - 'oauth token is an array' => ['oauthAccessToken', ['nope']], - ]; + public static function provideWronglyTypedAccountValues(): \Iterator { + yield 'password is an int' => ['inboundPassword', 12345]; + yield 'oauth token is an array' => ['oauthAccessToken', ['nope']]; } /** diff --git a/tests/Unit/UserMigration/Service/QuickActionsMigrationServiceTest.php b/tests/Unit/UserMigration/Service/QuickActionsMigrationServiceTest.php index d78c81dbd9..acbd007435 100644 --- a/tests/Unit/UserMigration/Service/QuickActionsMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/QuickActionsMigrationServiceTest.php @@ -22,7 +22,7 @@ use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class QuickActionsMigrationServiceTest extends TestCase { +final class QuickActionsMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = '123'; @@ -176,12 +176,10 @@ public function testImportNoQuickActions(): void { self::ACCOUNT_MAPPING, self::MAILBOX_MAPPING, []); } - public static function provideFileContentsWithNoQuickActionsImported(): array { - return [ - 'empty list' => [json_encode([])], - 'invalid JSON' => ['this is not valid json {{{'], - 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])], - ]; + public static function provideFileContentsWithNoQuickActionsImported(): \Iterator { + yield 'empty list' => [json_encode([])]; + yield 'invalid JSON' => ['this is not valid json {{{']; + yield 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])]; } /** @@ -210,11 +208,9 @@ public function testImportNoFileIsBeingIgnored(): void { self::ACCOUNT_MAPPING, self::MAILBOX_MAPPING, []); } - public static function provideIncompleteMappings(): array { - return [ - 'no accounts imported' => ['accountMapping' => [], 'mailboxMapping' => self::MAILBOX_MAPPING], - 'nothing imported' => ['accountMapping' => [], 'mailboxMapping' => []], - ]; + public static function provideIncompleteMappings(): \Iterator { + yield 'no accounts imported' => ['accountMapping' => [], 'mailboxMapping' => self::MAILBOX_MAPPING]; + yield 'nothing imported' => ['accountMapping' => [], 'mailboxMapping' => []]; } /** diff --git a/tests/Unit/UserMigration/Service/SmimeMigrationServiceTest.php b/tests/Unit/UserMigration/Service/SmimeMigrationServiceTest.php index 5ff9924c3c..9d2b4b8743 100644 --- a/tests/Unit/UserMigration/Service/SmimeMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/SmimeMigrationServiceTest.php @@ -23,7 +23,7 @@ use OCP\UserMigration\IImportSource; use Symfony\Component\Console\Output\OutputInterface; -class SmimeMigrationServiceTest extends TestCase { +final class SmimeMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = '123'; @@ -205,11 +205,9 @@ public function testImportNoCertificatesFolder(): void { $this->assertCount(0, $mappedTags); } - public static function provideCreateCertificateFailures(): array { - return [ - 'private key mismatch' => [new ServiceException('Private key does not match certificate')], - 'unparsable certificate' => [new SmimeCertificateParserException('Could not parse certificate')], - ]; + public static function provideCreateCertificateFailures(): \Iterator { + yield 'private key mismatch' => [new ServiceException('Private key does not match certificate')]; + yield 'unparsable certificate' => [new SmimeCertificateParserException('Could not parse certificate')]; } /** @@ -274,12 +272,10 @@ public function testImportReportsACertificateThatCannotBeCreatedAsANotice(): voi $this->assertWritten('broken.json', 0); } - public static function provideFileContentsWithNoCertificatesImported(): array { - return [ - 'empty list' => [json_encode([])], - 'invalid JSON' => ['this is not valid json {{{'], - 'missing required fields' => [json_encode(['unexpected' => 'field'])], - ]; + public static function provideFileContentsWithNoCertificatesImported(): \Iterator { + yield 'empty list' => [json_encode([])]; + yield 'invalid JSON' => ['this is not valid json {{{']; + yield 'missing required fields' => [json_encode(['unexpected' => 'field'])]; } /** diff --git a/tests/Unit/UserMigration/Service/TagsMigrationServiceTest.php b/tests/Unit/UserMigration/Service/TagsMigrationServiceTest.php index 92bc4a4773..ddc3c5b5ba 100644 --- a/tests/Unit/UserMigration/Service/TagsMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/TagsMigrationServiceTest.php @@ -21,7 +21,7 @@ use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class TagsMigrationServiceTest extends TestCase { +final class TagsMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = '123'; @@ -159,12 +159,10 @@ public function testImportNoFileIsBeingIgnored(): void { $this->assertCount(0, $mappedTags); } - public static function provideFileContentsWithNoTagsImported(): array { - return [ - 'empty list' => [json_encode([])], - 'invalid JSON' => ['this is not valid json {{{'], - 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])], - ]; + public static function provideFileContentsWithNoTagsImported(): \Iterator { + yield 'empty list' => [json_encode([])]; + yield 'invalid JSON' => ['this is not valid json {{{']; + yield 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])]; } /** @@ -216,17 +214,15 @@ public function testImportReusesTagsTheUserAlreadyHas(): void { ); } - public static function provideInvalidTagValues(): array { - return [ - 'empty imap label' => [['imapLabel' => '']], - 'imap label longer than the column' => [['imapLabel' => str_repeat('a', Tag::IMAP_LABEL_MAX_LENGTH + 1)]], - 'imap label with a trailing space' => [['imapLabel' => 'testing ']], - 'imap label with a trailing newline' => [['imapLabel' => "testing\n"]], - 'imap label with non-ASCII characters' => [['imapLabel' => 'tästing']], - 'imap system flag' => [['imapLabel' => '\\deleted']], - 'display name longer than the tag form allows' => [['displayName' => str_repeat('ä', Tag::DISPLAY_NAME_MAX_LENGTH + 1)]], - 'color longer than the tag form allows' => [['color' => str_repeat('f', Tag::COLOR_MAX_LENGTH + 1)]], - ]; + public static function provideInvalidTagValues(): \Iterator { + yield 'empty imap label' => [['imapLabel' => '']]; + yield 'imap label longer than the column' => [['imapLabel' => str_repeat('a', Tag::IMAP_LABEL_MAX_LENGTH + 1)]]; + yield 'imap label with a trailing space' => [['imapLabel' => 'testing ']]; + yield 'imap label with a trailing newline' => [['imapLabel' => "testing\n"]]; + yield 'imap label with non-ASCII characters' => [['imapLabel' => 'tästing']]; + yield 'imap system flag' => [['imapLabel' => '\\deleted']]; + yield 'display name longer than the tag form allows' => [['displayName' => str_repeat('ä', Tag::DISPLAY_NAME_MAX_LENGTH + 1)]]; + yield 'color longer than the tag form allows' => [['color' => str_repeat('f', Tag::COLOR_MAX_LENGTH + 1)]]; } /** diff --git a/tests/Unit/UserMigration/Service/TextBlocksMigrationServiceTest.php b/tests/Unit/UserMigration/Service/TextBlocksMigrationServiceTest.php index 409401e83e..a464017186 100644 --- a/tests/Unit/UserMigration/Service/TextBlocksMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/TextBlocksMigrationServiceTest.php @@ -20,7 +20,7 @@ use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class TextBlocksMigrationServiceTest extends TestCase { +final class TextBlocksMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = '123'; @@ -141,12 +141,10 @@ public function testImportNoFileIsBeingIgnored(): void { $this->migrationService->importTextBlocks($this->user, $this->importSource, $this->output); } - public static function provideFileContentsWithNoTextBlocksImported(): array { - return [ - 'empty list' => [json_encode([])], - 'invalid JSON' => ['this is not valid json {{{'], - 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])], - ]; + public static function provideFileContentsWithNoTextBlocksImported(): \Iterator { + yield 'empty list' => [json_encode([])]; + yield 'invalid JSON' => ['this is not valid json {{{']; + yield 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])]; } /** diff --git a/tests/Unit/UserMigration/Service/TrustedSendersMigrationServiceTest.php b/tests/Unit/UserMigration/Service/TrustedSendersMigrationServiceTest.php index b3e3c6d6ae..71fd604974 100644 --- a/tests/Unit/UserMigration/Service/TrustedSendersMigrationServiceTest.php +++ b/tests/Unit/UserMigration/Service/TrustedSendersMigrationServiceTest.php @@ -20,7 +20,7 @@ use OCP\UserMigration\UserMigrationException; use Symfony\Component\Console\Output\OutputInterface; -class TrustedSendersMigrationServiceTest extends TestCase { +final class TrustedSendersMigrationServiceTest extends TestCase { use RecordsConsoleOutput; private const USER_ID = '123'; @@ -119,12 +119,10 @@ public function testImportNoFileIsBeingIgnored(): void { $this->migrationService->importTrustedSenders($this->user, $this->importSource, $this->output); } - public static function provideFileContentsWithNoTrustedSendersImported(): array { - return [ - 'empty list' => [json_encode([])], - 'invalid JSON' => ['this is not valid json {{{'], - 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])], - ]; + public static function provideFileContentsWithNoTrustedSendersImported(): \Iterator { + yield 'empty list' => [json_encode([])]; + yield 'invalid JSON' => ['this is not valid json {{{']; + yield 'JSON object instead of list' => [json_encode(['unexpected' => 'object'])]; } /**