feat(mail) : MailConfiguration entity + repository + singleton test
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
<ini name="error_reporting" value="-1" />
|
<ini name="error_reporting" value="-1" />
|
||||||
<server name="APP_ENV" value="test" force="true" />
|
<server name="APP_ENV" value="test" force="true" />
|
||||||
<server name="SHELL_VERBOSITY" value="-1" />
|
<server name="SHELL_VERBOSITY" value="-1" />
|
||||||
|
<server name="KERNEL_CLASS" value="App\Kernel" />
|
||||||
</php>
|
</php>
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
|||||||
193
src/Entity/MailConfiguration.php
Normal file
193
src/Entity/MailConfiguration.php
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\MailConfigurationRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: MailConfigurationRepository::class)]
|
||||||
|
#[ORM\Table(name: 'mail_configuration')]
|
||||||
|
class MailConfiguration
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 10)]
|
||||||
|
private string $protocol = 'imap';
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $imapHost = null;
|
||||||
|
|
||||||
|
#[ORM\Column]
|
||||||
|
private int $imapPort = 993;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 10)]
|
||||||
|
private string $imapEncryption = 'ssl';
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $smtpHost = null;
|
||||||
|
|
||||||
|
#[ORM\Column]
|
||||||
|
private int $smtpPort = 465;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 10)]
|
||||||
|
private string $smtpEncryption = 'ssl';
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $username = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'text', nullable: true)]
|
||||||
|
private ?string $encryptedPassword = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private string $sentFolderPath = 'Sent';
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'boolean')]
|
||||||
|
private bool $enabled = false;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/Repository/MailConfigurationRepository.php
Normal file
26
src/Repository/MailConfigurationRepository.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\MailConfiguration;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
class MailConfigurationRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, MailConfiguration::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findSingleton(): ?MailConfiguration
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('m')
|
||||||
|
->setMaxResults(1)
|
||||||
|
->getQuery()
|
||||||
|
->getOneOrNullResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
50
tests/Unit/Repository/MailConfigurationRepositoryTest.php
Normal file
50
tests/Unit/Repository/MailConfigurationRepositoryTest.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Unit\Repository;
|
||||||
|
|
||||||
|
use App\Entity\MailConfiguration;
|
||||||
|
use App\Repository\MailConfigurationRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class MailConfigurationRepositoryTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
private MailConfigurationRepository $repository;
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$container = static::getContainer();
|
||||||
|
$this->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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user