diff --git a/phpunit.dist.xml b/phpunit.dist.xml index 22bd879..eb794bd 100644 --- a/phpunit.dist.xml +++ b/phpunit.dist.xml @@ -15,6 +15,7 @@ + diff --git a/src/Entity/MailConfiguration.php b/src/Entity/MailConfiguration.php new file mode 100644 index 0000000..b1af5b1 --- /dev/null +++ b/src/Entity/MailConfiguration.php @@ -0,0 +1,193 @@ +id; + } + + public function getProtocol(): string + { + return $this->protocol; + } + + public function setProtocol(string $protocol): static + { + $this->protocol = $protocol; + + return $this; + } + + public function getImapHost(): ?string + { + return $this->imapHost; + } + + public function setImapHost(?string $imapHost): static + { + $this->imapHost = $imapHost; + + return $this; + } + + public function getImapPort(): int + { + return $this->imapPort; + } + + public function setImapPort(int $imapPort): static + { + $this->imapPort = $imapPort; + + return $this; + } + + public function getImapEncryption(): string + { + return $this->imapEncryption; + } + + public function setImapEncryption(string $imapEncryption): static + { + $this->imapEncryption = $imapEncryption; + + return $this; + } + + public function getSmtpHost(): ?string + { + return $this->smtpHost; + } + + public function setSmtpHost(?string $smtpHost): static + { + $this->smtpHost = $smtpHost; + + return $this; + } + + public function getSmtpPort(): int + { + return $this->smtpPort; + } + + public function setSmtpPort(int $smtpPort): static + { + $this->smtpPort = $smtpPort; + + return $this; + } + + public function getSmtpEncryption(): string + { + return $this->smtpEncryption; + } + + public function setSmtpEncryption(string $smtpEncryption): static + { + $this->smtpEncryption = $smtpEncryption; + + return $this; + } + + public function getUsername(): ?string + { + return $this->username; + } + + public function setUsername(?string $username): static + { + $this->username = $username; + + return $this; + } + + public function getEncryptedPassword(): ?string + { + return $this->encryptedPassword; + } + + public function setEncryptedPassword(?string $encryptedPassword): static + { + $this->encryptedPassword = $encryptedPassword; + + return $this; + } + + public function getSentFolderPath(): string + { + return $this->sentFolderPath; + } + + public function setSentFolderPath(string $sentFolderPath): static + { + $this->sentFolderPath = $sentFolderPath; + + return $this; + } + + public function isEnabled(): bool + { + return $this->enabled; + } + + public function setEnabled(bool $enabled): static + { + $this->enabled = $enabled; + + return $this; + } + + public function hasPassword(): bool + { + return null !== $this->encryptedPassword; + } +} diff --git a/src/Repository/MailConfigurationRepository.php b/src/Repository/MailConfigurationRepository.php new file mode 100644 index 0000000..9be3993 --- /dev/null +++ b/src/Repository/MailConfigurationRepository.php @@ -0,0 +1,26 @@ +createQueryBuilder('m') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult() + ; + } +} diff --git a/tests/Unit/Repository/MailConfigurationRepositoryTest.php b/tests/Unit/Repository/MailConfigurationRepositoryTest.php new file mode 100644 index 0000000..f903ee6 --- /dev/null +++ b/tests/Unit/Repository/MailConfigurationRepositoryTest.php @@ -0,0 +1,50 @@ +repository = $container->get(MailConfigurationRepository::class); + $this->em = $container->get('doctrine.orm.entity_manager'); + $this->em->getConnection()->executeStatement('TRUNCATE TABLE mail_configuration RESTART IDENTITY CASCADE'); + } + + public function testFindSingletonReturnsNullWhenEmpty(): void + { + $result = $this->repository->findSingleton(); + + self::assertNull($result); + } + + public function testFindSingletonReturnsFirstRecord(): void + { + $config = new MailConfiguration(); + $config->setImapHost('ssl0.ovh.net'); + $config->setEnabled(false); + $this->em->persist($config); + $this->em->flush(); + + $result = $this->repository->findSingleton(); + + self::assertInstanceOf(MailConfiguration::class, $result); + self::assertSame('ssl0.ovh.net', $result->getImapHost()); + self::assertFalse($result->isEnabled()); + } +}