test: update DomainTest after refactor

This commit is contained in:
Maël Gangloff 2025-10-22 18:22:36 +02:00
parent 597c744161
commit 51345f15b7
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
2 changed files with 102 additions and 100 deletions

View File

@ -127,7 +127,7 @@ class Domain
#[ORM\Column(nullable: false, options: ['default' => false])]
#[Groups(['domain:item', 'domain:list'])]
private ?bool $delegationSigned = null;
private bool $delegationSigned = false;
/**
* @var Collection<int, DnsKey>

View File

@ -7,12 +7,18 @@ namespace App\Tests\Entity;
use App\Entity\Domain;
use App\Entity\DomainEvent;
use App\Entity\DomainStatus;
use App\Entity\Tld;
use App\Exception\MalformedDomainException;
use App\Service\RDAPService;
use App\Tests\Service\RDAPServiceTest;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\ORMException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\DependsExternal;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Uid\UuidV4;
final class DomainTest extends KernelTestCase
class DomainTest extends KernelTestCase
{
public function testIsRedemptionPeriod(): void
{
@ -50,112 +56,108 @@ final class DomainTest extends KernelTestCase
);
}
public function testGetExpiresInDays(): void
#[DataProvider('domainProvider')]
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
public function testGetExpiresInDays(?int $expected, Domain $domain, string $message): void
{
$this->assertNull(
(new Domain())
->setDeleted(true)
->getExpiresInDays(),
'No guess if the domain is flagged as deleted'
);
/** @var RDAPService $RDAPService */
$RDAPService = self::getContainer()->get(RDAPService::class);
$this->assertEquals(
90, // Expiration date (10 days) + Auto Renew Period (45 days) + Redemption Period (30 days) + Pending Delete (5 days)
(new Domain())
$this->assertEquals($expected, $RDAPService->getExpiresInDays($domain), $message);
}
/**
* @throws MalformedDomainException
* @throws ORMException
*/
public static function domainProvider(): array
{
/** @var EntityManagerInterface $entityManager */
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$arpaTld = $entityManager->getReference(Tld::class, 'arpa');
$now = new \DateTimeImmutable();
// Domain deleted
$domainDeleted = (new Domain())
->setLdhName((new UuidV4())->toString())
->setTld($arpaTld)
->setDeleted(true);
$entityManager->persist($domainDeleted);
// Domain with future expiration event
$domainExpirationEvent = (new Domain())
->setLdhName((new UuidV4())->toString())
->setTld($arpaTld)
->addEvent(
(new DomainEvent())
->setDate((new \DateTimeImmutable())->add(new \DateInterval('P10D')))
->setDate($now->add(new \DateInterval('P10D')))
->setAction('expiration')
->setDeleted(false)
)->getExpiresInDays(),
'Guess based on domain events date'
);
$this->assertEquals(
5, // Pending Delete (5 days)
(new Domain())
->setStatus(['pending delete'])
->addDomainStatus(
(new DomainStatus())
$entityManager->persist($domainExpirationEvent);
// Domain with pending delete status
$domainPendingDelete = (new Domain())
->setLdhName((new UuidV4())->toString())
->setTld($arpaTld)
->setStatus(['pending delete']);
$entityManager->persist($domainPendingDelete);
$entityManager->persist((new DomainStatus())
->setDomain($domainPendingDelete)
->setAddStatus(['pending delete'])
->setDeleteStatus(['active'])
->setCreatedAt(new \DateTimeImmutable())
->setDate(new \DateTimeImmutable())
)->getExpiresInDays(),
'Guess based on domain EPP status'
);
->setCreatedAt($now)
->setDate($now));
$this->assertEquals(
35, // Redemption Period (15 days) + Pending Delete (5 days)
(new Domain())
->setStatus(['redemption period'])
->addDomainStatus(
(new DomainStatus())
// Domain in redemption period
$domainRedemption = (new Domain())
->setLdhName((new UuidV4())->toString())
->setTld($arpaTld)
->setStatus(['redemption period']);
$entityManager->persist($domainRedemption);
$entityManager->persist((new DomainStatus())
->setDomain($domainRedemption)
->setAddStatus(['redemption period'])
->setDeleteStatus(['active'])
->setCreatedAt(new \DateTimeImmutable())
->setDate(new \DateTimeImmutable())
)->getExpiresInDays(),
'Domain name entered in the redemption period'
);
->setCreatedAt($now)
->setDate($now));
$this->assertEquals(
5, // Pending Delete (5 days)
(new Domain())
// Domain with deletion event today
$domainDeletionToday = (new Domain())
->setLdhName((new UuidV4())->toString())
->setTld($arpaTld)
->setStatus(['pending delete'])
->addEvent(
(new DomainEvent())
->setDate((new \DateTimeImmutable())->sub(new \DateInterval('P10D')))
->setAction('expiration')
->setDeleted(false)
)
->addDomainStatus(
(new DomainStatus())
->setAddStatus(['pending delete'])
->setDeleteStatus(['active'])
->setCreatedAt(new \DateTimeImmutable())
->setDate(new \DateTimeImmutable())
)->getExpiresInDays(),
'Domain name entered in the pending delete period'
);
$this->assertEquals(
1,
(new Domain())
->setStatus(['pending delete'])
->addEvent(
(new DomainEvent())
->setDate((new \DateTimeImmutable())->sub(new \DateInterval('P'.(45 + 30 + 4).'D')))
->setAction('expiration')
->setDeleted(false)
)
->addDomainStatus(
(new DomainStatus())
->setAddStatus(['pending delete'])
->setDeleteStatus(['active'])
->setCreatedAt(new \DateTimeImmutable())
->setDate(new \DateTimeImmutable())
)->getExpiresInDays(),
'Guess based on domain status in priority'
);
$this->assertNull(
(new Domain())->setStatus(['pending delete'])->getExpiresInDays(),
'Not enough data to guess'
);
$this->assertEquals(
0,
(new Domain())
->setStatus(['pending delete'])
->addEvent(
(new DomainEvent())
->setDate(new \DateTimeImmutable())
->setDate($now)
->setAction('deletion')
->setDeleted(false)
)->getExpiresInDays(),
'deletion event on last day (AFNIC)'
);
$entityManager->persist($domainDeletionToday);
// Domain with status but not enough data
$domainNotEnoughData = (new Domain())
->setLdhName((new UuidV4())->toString())
->setTld($arpaTld)
->setStatus(['pending delete']);
$entityManager->persist($domainNotEnoughData);
$entityManager->flush();
return [
[null, $domainDeleted, 'No guess if the domain is flagged as deleted'],
[90, $domainExpirationEvent, 'Guess based on domain events date'],
[5, $domainPendingDelete, 'Guess based on domain EPP status'],
[35, $domainRedemption, 'Domain name entered in the redemption period'],
[0, $domainDeletionToday, 'deletion event on last day (AFNIC)'],
[null, $domainNotEnoughData, 'Not enough data to guess'],
];
}
public function testIdnDomainName(): void