From 427c4c6a806a8f1275f424311a935835bb195b65 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski <krupinskis05@gmail.com> Date: Mon, 15 Jul 2024 16:35:47 -0400 Subject: [PATCH] feat: mail provider backend Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com> --- lib/public/Mail/Provider/IMessage.php | 16 ++++++------- lib/public/Mail/Provider/IService.php | 19 +++++++++++----- lib/public/Mail/Provider/Message.php | 24 ++++++++++---------- tests/lib/Mail/Provider/AddressTest.php | 4 ++-- tests/lib/Mail/Provider/AttachmentTest.php | 4 ++-- tests/lib/Mail/Provider/ManagerTest.php | 20 ++++++++--------- tests/lib/Mail/Provider/MessageTest.php | 26 +++++++++++----------- 7 files changed, 61 insertions(+), 52 deletions(-) diff --git a/lib/public/Mail/Provider/IMessage.php b/lib/public/Mail/Provider/IMessage.php index ff2b52e5053..71021981362 100644 --- a/lib/public/Mail/Provider/IMessage.php +++ b/lib/public/Mail/Provider/IMessage.php @@ -83,9 +83,9 @@ interface IMessage { * * @since 30.0.0 * - * @param array<int,IAddress>|null collection of all recipient mail address objects + * @param array<int,IAddress> collection of all recipient mail address objects */ - public function getTo(): array | null; + public function getTo(): array; /** * sets the copy to recipient(s) of this message @@ -103,9 +103,9 @@ interface IMessage { * * @since 30.0.0 * - * @param array<int,IAddress>|null collection of all copied recipient mail address objects + * @param array<int,IAddress> collection of all copied recipient mail address objects */ - public function getCc(): array | null; + public function getCc(): array; /** * sets the blind copy to recipient(s) of this message @@ -123,9 +123,9 @@ interface IMessage { * * @since 30.0.0 * - * @param array<int,IAddress>|null collection of all blind copied recipient mail address objects + * @param array<int,IAddress> collection of all blind copied recipient mail address objects */ - public function getBcc(): array | null; + public function getBcc(): array; /** * sets the subject of this message @@ -226,7 +226,7 @@ interface IMessage { * * @since 30.0.0 * - * @return array<int,IAttachment>|null collection of all mail attachment objects + * @return array<int,IAttachment> collection of all mail attachment objects */ - public function getAttachments(): array | null; + public function getAttachments(): array; } diff --git a/lib/public/Mail/Provider/IService.php b/lib/public/Mail/Provider/IService.php index 65056418c67..677ad8f9658 100644 --- a/lib/public/Mail/Provider/IService.php +++ b/lib/public/Mail/Provider/IService.php @@ -28,15 +28,24 @@ interface IService { public function id(): string; /** - * checks or retrieves what capabilites the service has + * checks if a service is able of performing an specific action * - * @since 30.0.0 + * @since 4.0.0 + * + * @param string $value required ability e.g. 'MessageSend' + * + * @return bool true/false if ability is supplied and found in collection + */ + public function capable(string $value): bool; + + /** + * retrieves a collection of what actions a service can perfrom * - * @param string $ability required ability e.g. 'MessageSend' + * @since 4.0.0 * - * @return bool|array true/false if ability is supplied, collection of abilities otherwise + * @return array collection of abilities otherwise empty collection */ - public function capable(?string $ability = null): bool | array; + public function capabilities(): array; /** * gets the localized human frendly name of this service diff --git a/lib/public/Mail/Provider/Message.php b/lib/public/Mail/Provider/Message.php index 8bf07b34f70..58638963640 100644 --- a/lib/public/Mail/Provider/Message.php +++ b/lib/public/Mail/Provider/Message.php @@ -119,11 +119,11 @@ class Message implements \OCP\Mail\Provider\IMessage { * * @since 30.0.0 * - * @param array<int,IAddress>|null collection of all recipient mail address objects + * @param array<int,IAddress> collection of all recipient mail address objects */ - public function getTo(): array | null { - // evaluate if data store field exists and return value(s) or null otherwise - return (isset($this->data['to'])) ? $this->data['to'] : null; + public function getTo(): array { + // evaluate if data store field exists and return value(s) or empty collection + return (isset($this->data['to'])) ? $this->data['to'] : []; } /** @@ -147,11 +147,11 @@ class Message implements \OCP\Mail\Provider\IMessage { * * @since 30.0.0 * - * @param array<int,IAddress>|null collection of all copied recipient mail address objects + * @param array<int,IAddress> collection of all copied recipient mail address objects */ - public function getCc(): array | null { - // evaluate if data store field exists and return value(s) or null otherwise - return (isset($this->data['cc'])) ? $this->data['cc'] : null; + public function getCc(): array { + // evaluate if data store field exists and return value(s) or empty collection + return (isset($this->data['cc'])) ? $this->data['cc'] : []; } /** @@ -175,11 +175,11 @@ class Message implements \OCP\Mail\Provider\IMessage { * * @since 30.0.0 * - * @param array<int,IAddress>|null collection of all blind copied recipient mail address objects + * @param array<int,IAddress> collection of all blind copied recipient mail address objects */ - public function getBcc(): array | null { - // evaluate if data store field exists and return value(s) or null otherwise - return (isset($this->data['bcc'])) ? $this->data['bcc'] : null; + public function getBcc(): array { + // evaluate if data store field exists and return value(s) or empty collection + return (isset($this->data['bcc'])) ? $this->data['bcc'] : []; } /** diff --git a/tests/lib/Mail/Provider/AddressTest.php b/tests/lib/Mail/Provider/AddressTest.php index 5df22977bff..ee03f6f1e83 100644 --- a/tests/lib/Mail/Provider/AddressTest.php +++ b/tests/lib/Mail/Provider/AddressTest.php @@ -13,8 +13,8 @@ use Test\TestCase; class AddressTest extends TestCase { - /** @var Address*/ - private $address; + /** @var Address&MockObject */ + private Address $address; protected function setUp(): void { parent::setUp(); diff --git a/tests/lib/Mail/Provider/AttachmentTest.php b/tests/lib/Mail/Provider/AttachmentTest.php index e5b254aacb9..283391650b5 100644 --- a/tests/lib/Mail/Provider/AttachmentTest.php +++ b/tests/lib/Mail/Provider/AttachmentTest.php @@ -13,8 +13,8 @@ use Test\TestCase; class AttachmentTest extends TestCase { - /** @var Attachment*/ - private $attachment; + /** @var Attachment&MockObject */ + private Attachment $attachment; protected function setUp(): void { parent::setUp(); diff --git a/tests/lib/Mail/Provider/ManagerTest.php b/tests/lib/Mail/Provider/ManagerTest.php index 76ed953cfda..2658c324521 100644 --- a/tests/lib/Mail/Provider/ManagerTest.php +++ b/tests/lib/Mail/Provider/ManagerTest.php @@ -21,16 +21,16 @@ use Test\TestCase; class ManagerTest extends TestCase { - /** @var CoordinatorMockObject*/ - private $coordinator; - /** @var ContainerInterfaceMockObject*/ - private $container; - /** @var LoggerInterfaceMockObject*/ - private $logger; - /** @var IProviderMockObject*/ - private $provider; - /** @var IServiceMockObject*/ - private $service; + /** @var Coordinator&MockObject */ + private Coordinator $coordinator; + /** @var ContainerInterface&MockObject */ + private ContainerInterface $container; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + /** @var IProvider&MockObject */ + private IProvider $provider; + /** @var IService&MockObject */ + private IService $service; protected function setUp(): void { parent::setUp(); diff --git a/tests/lib/Mail/Provider/MessageTest.php b/tests/lib/Mail/Provider/MessageTest.php index 546d1f87e32..1791a03421c 100644 --- a/tests/lib/Mail/Provider/MessageTest.php +++ b/tests/lib/Mail/Provider/MessageTest.php @@ -15,16 +15,16 @@ use Test\TestCase; class MessageTest extends TestCase { - /** @var Message*/ - private $message; - /** @var Address*/ - private $address1; - /** @var Address*/ - private $address2; - /** @var Attachment*/ - private $attachment1; - /** @var Attachment*/ - private $attachment2; + /** @var Message&MockObject */ + private Message $message; + /** @var Address&MockObject */ + private Address $address1; + /** @var Address&MockObject */ + private Address $address2; + /** @var Attachment&MockObject */ + private Attachment $attachment1; + /** @var Attachment&MockObject */ + private Attachment $attachment2; protected function setUp(): void { parent::setUp(); @@ -85,7 +85,7 @@ class MessageTest extends TestCase { public function testTo(): void { // test not set - $this->assertNull($this->message->getTo()); + $this->assertEquals([], $this->message->getTo()); // test set by setter single $this->message->setTo($this->address1); $this->assertEquals([$this->address1], $this->message->getTo()); @@ -98,7 +98,7 @@ class MessageTest extends TestCase { public function testCc(): void { // test not set - $this->assertNull($this->message->getCc()); + $this->assertEquals([], $this->message->getCc()); // test set by setter single $this->message->setCc($this->address1); $this->assertEquals([$this->address1], $this->message->getCc()); @@ -111,7 +111,7 @@ class MessageTest extends TestCase { public function testBcc(): void { // test not set - $this->assertNull($this->message->getBcc()); + $this->assertEquals([], $this->message->getBcc()); // test set by setter single $this->message->setBcc($this->address1); $this->assertEquals([$this->address1], $this->message->getBcc()); -- GitLab