2025-10-14 17:40:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
2025-10-14 23:34:17 +02:00
|
|
|
namespace App\Tests\State;
|
2025-10-14 17:40:48 +02:00
|
|
|
|
2025-10-14 18:48:40 +02:00
|
|
|
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
2025-10-14 17:40:48 +02:00
|
|
|
use App\Entity\Domain;
|
|
|
|
|
use App\Factory\UserFactory;
|
2025-10-16 14:16:58 +02:00
|
|
|
use App\Repository\DomainRepository;
|
|
|
|
|
use App\Service\RDAPService;
|
2025-10-14 18:48:40 +02:00
|
|
|
use App\Tests\AuthenticatedUserTrait;
|
2025-10-14 17:40:48 +02:00
|
|
|
use App\Tests\Service\RDAPServiceTest;
|
|
|
|
|
use PHPUnit\Framework\Attributes\DependsExternal;
|
|
|
|
|
use Zenstruck\Foundry\Test\Factories;
|
|
|
|
|
|
2025-10-14 23:34:17 +02:00
|
|
|
final class AutoRegisterDomainProviderTest extends ApiTestCase
|
2025-10-14 17:40:48 +02:00
|
|
|
{
|
|
|
|
|
use Factories;
|
2025-10-14 18:48:40 +02:00
|
|
|
use AuthenticatedUserTrait;
|
2025-10-14 17:40:48 +02:00
|
|
|
|
|
|
|
|
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
|
|
|
|
public function testRegisterDomain(): void
|
|
|
|
|
{
|
2025-10-16 14:16:58 +02:00
|
|
|
$client = AutoRegisterDomainProviderTest::createClientWithCredentials(AutoRegisterDomainProviderTest::getToken(UserFactory::createOne()));
|
2025-10-14 17:40:48 +02:00
|
|
|
$client->request('GET', '/api/domains/example.com');
|
|
|
|
|
|
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
|
$this->assertMatchesResourceItemJsonSchema(Domain::class);
|
|
|
|
|
}
|
2025-10-16 14:16:58 +02:00
|
|
|
|
|
|
|
|
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
|
|
|
|
public function testRegisterDomainAlreadyUpdated(): void
|
|
|
|
|
{
|
|
|
|
|
$client = AutoRegisterDomainProviderTest::createClientWithCredentials(AutoRegisterDomainProviderTest::getToken(UserFactory::createOne()));
|
|
|
|
|
|
|
|
|
|
$mockedDomain = $this->getMockBuilder(Domain::class)->getMock();
|
|
|
|
|
$mockedDomain->method('isToBeUpdated')->willReturn(false);
|
|
|
|
|
|
|
|
|
|
$mockedDomainRepository = $this->createMock(DomainRepository::class);
|
|
|
|
|
$mockedDomainRepository->method('findOneBy')->willReturn($mockedDomain);
|
|
|
|
|
|
|
|
|
|
$rdapServiceMocked = $this->createMock(RDAPService::class);
|
|
|
|
|
$rdapServiceMocked->expects(self::never())->method('registerDomain');
|
|
|
|
|
|
|
|
|
|
$container = static::getContainer();
|
|
|
|
|
$container->set(DomainRepository::class, $mockedDomainRepository);
|
|
|
|
|
$container->set(RDAPService::class, $rdapServiceMocked);
|
|
|
|
|
|
|
|
|
|
$client->request('GET', '/api/domains/example.com');
|
|
|
|
|
}
|
2025-10-14 17:40:48 +02:00
|
|
|
}
|