test: add phpunit

This commit is contained in:
Maël Gangloff 2025-09-06 10:35:07 +02:00
parent ada68af9b4
commit 08bd2a4541
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
3 changed files with 85 additions and 1 deletions

View File

@ -44,7 +44,7 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
readonly class RDAPService
class RDAPService
{
/* @see https://www.iana.org/domains/root/db */
public const ISO_TLD_EXCEPTION = ['ac', 'eu', 'uk', 'su', 'tp'];

View File

@ -13,6 +13,15 @@
"src/ApiResource/.gitignore"
]
},
"doctrine/deprecations": {
"version": "1.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "87424683adc81d7dc305eefec1fced883084aab9"
}
},
"doctrine/doctrine-bundle": {
"version": "2.12",
"recipe": {

View File

@ -0,0 +1,75 @@
<?php declare(strict_types=1);
namespace App\Tests\Service;
use App\Entity\Domain;
use App\Entity\DomainEvent;
use DateInterval;
use DateTimeImmutable;
use Exception;
use PHPUnit\Framework\TestCase;
final class DomainTest extends TestCase
{
public function testIsRedemptionPeriod(): void
{
$this->assertTrue(
(new Domain())
->setStatus(['redemption period'])
->isRedemptionPeriod()
);
$this->assertFalse(
(new Domain())
->setStatus(['active'])
->isRedemptionPeriod()
);
}
public function testIsPendingDelete(): void
{
$this->assertTrue(
(new Domain())
->setStatus(['pending delete'])
->isPendingDelete()
);
$this->assertFalse(
(new Domain())
->setStatus(['active'])
->isPendingDelete()
);
$this->assertFalse(
(new Domain())
->setStatus(['redemption period', 'pending delete'])
->isPendingDelete()
);
}
/**
* @throws Exception
*/
public function testGetExpiresInDays(): void
{
$this->assertNull(
(new Domain())
->setDeleted(true)
->getExpiresInDays()
);
$this->assertEquals(
90, // Expiration date (10 days) + Auto Renew Period (45 days) + Redemption Period (30 days) + Pending Delete Period (10 days)
(new Domain())
->addEvent(
(new DomainEvent())
->setDate((new DateTimeImmutable())->add(new DateInterval('P10D')))
->setAction('expiration')
->setDeleted(false)
)->getExpiresInDays()
);
}
}