mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
fix: use state provider
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||||
use App\Factory\UserFactory;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Zenstruck\Foundry\Test\Factories;
|
||||
use Zenstruck\Foundry\Test\ResetDatabase;
|
||||
|
||||
final class RegistrationControllerTest extends ApiTestCase
|
||||
{
|
||||
use ResetDatabase;
|
||||
use Factories;
|
||||
|
||||
protected static ContainerInterface $container;
|
||||
protected static EntityManagerInterface $entityManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
RegistrationControllerTest::$container = RegistrationControllerTest::getContainer();
|
||||
RegistrationControllerTest::$entityManager = RegistrationControllerTest::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
public function testRegister(): void
|
||||
{
|
||||
$testUser = UserFactory::createOne();
|
||||
RegistrationControllerTest::$entityManager->remove($testUser);
|
||||
RegistrationControllerTest::$entityManager->flush();
|
||||
|
||||
$client = $this->createClient();
|
||||
$client->request('POST', '/api/register', [
|
||||
'json' => [
|
||||
'email' => $testUser->getEmail(),
|
||||
'password' => $testUser->getPlainPassword(),
|
||||
],
|
||||
]);
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertResponseStatusCodeSame(201);
|
||||
}
|
||||
|
||||
public function testRegisterEmptyEmail(): void
|
||||
{
|
||||
$client = $this->createClient();
|
||||
$client->request('POST', '/api/register', [
|
||||
'json' => [
|
||||
'email' => '',
|
||||
'password' => 'MySuperPassword123',
|
||||
],
|
||||
]);
|
||||
$this->assertResponseStatusCodeSame(400);
|
||||
}
|
||||
|
||||
public function testRegisterEmptyPassword(): void
|
||||
{
|
||||
$client = $this->createClient();
|
||||
$client->request('POST', '/api/register', [
|
||||
'json' => [
|
||||
'email' => 'test@domainwatchdog.eu',
|
||||
'password' => '',
|
||||
],
|
||||
]);
|
||||
$this->assertResponseStatusCodeSame(400);
|
||||
}
|
||||
|
||||
public function testRegisterWeakPassword(): void
|
||||
{
|
||||
$client = $this->createClient();
|
||||
$client->request('POST', '/api/register', [
|
||||
'json' => [
|
||||
'email' => 'test@domainwatchdog.eu',
|
||||
'password' => '123',
|
||||
],
|
||||
]);
|
||||
$this->assertResponseStatusCodeSame(400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ final class WatchlistControllerTest extends ApiTestCase
|
||||
use Factories;
|
||||
use AuthenticatedUserTrait;
|
||||
|
||||
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
||||
public function testGetWatchlistCollection(): void
|
||||
{
|
||||
$client = $this->createUserAndWatchlist();
|
||||
@@ -77,7 +78,7 @@ final class WatchlistControllerTest extends ApiTestCase
|
||||
{
|
||||
$client = self::createClientWithCredentials(self::getToken(UserFactory::createOne()));
|
||||
$client->request('POST', '/api/watchlists', ['json' => [
|
||||
'domains' => ['/api/domains/example.com'],
|
||||
'domains' => ['/api/domains/iana.org'],
|
||||
'name' => 'My Watchlist',
|
||||
'triggers' => [
|
||||
['action' => 'email', 'event' => 'last changed'],
|
||||
|
||||
@@ -16,6 +16,9 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpClient\Exception\ClientException;
|
||||
use Symfony\Component\HttpClient\Exception\TransportException;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
use Symfony\Component\HttpClient\Response\MockResponse;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class RDAPServiceTest extends KernelTestCase
|
||||
{
|
||||
@@ -76,9 +79,46 @@ class RDAPServiceTest extends KernelTestCase
|
||||
}
|
||||
|
||||
#[Depends('testUpdateRdapServers')]
|
||||
public function testDomainNotFound()
|
||||
public function testDomainDeleted()
|
||||
{
|
||||
self::$RDAPService->registerDomain('example.com');
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
self::bootKernel();
|
||||
|
||||
static::getContainer()->set(HttpClientInterface::class, new MockHttpClient(
|
||||
new MockResponse('', ['http_code' => 404])
|
||||
));
|
||||
|
||||
$rdapService = static::getContainer()->get(RDAPService::class);
|
||||
|
||||
$this->expectException(DomainNotFoundException::class);
|
||||
self::$RDAPService->registerDomain('dd5c3e77-c824-4792-95fc-ddde03a08881.com');
|
||||
$rdapService->registerDomain('example.com');
|
||||
}
|
||||
|
||||
#[Depends('testDomainDeleted')]
|
||||
public function testDomainUpdateStatus(): void
|
||||
{
|
||||
$domain = self::$RDAPService->registerDomain('example.com');
|
||||
$domain->setStatus(['pending delete']);
|
||||
self::$entityManager->flush();
|
||||
self::$RDAPService->registerDomain('example.com');
|
||||
|
||||
$this->expectNotToPerformAssertions();
|
||||
}
|
||||
|
||||
#[Depends('testUpdateRdapServers')]
|
||||
public function testHttpClientException()
|
||||
{
|
||||
self::ensureKernelShutdown();
|
||||
self::bootKernel();
|
||||
static::getContainer()->set(HttpClientInterface::class, new MockHttpClient(
|
||||
fn () => throw new TransportException()
|
||||
));
|
||||
|
||||
$rdapService = static::getContainer()->get(RDAPService::class);
|
||||
|
||||
$this->expectException(TransportException::class);
|
||||
$rdapService->registerDomain('example.com');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
namespace App\Tests\State;
|
||||
|
||||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||||
use App\Entity\Domain;
|
||||
@@ -10,7 +10,7 @@ use App\Tests\Service\RDAPServiceTest;
|
||||
use PHPUnit\Framework\Attributes\DependsExternal;
|
||||
use Zenstruck\Foundry\Test\Factories;
|
||||
|
||||
final class DomainRefreshControllerTest extends ApiTestCase
|
||||
final class AutoRegisterDomainProviderTest extends ApiTestCase
|
||||
{
|
||||
use Factories;
|
||||
use AuthenticatedUserTrait;
|
||||
@@ -19,7 +19,7 @@ final class DomainRefreshControllerTest extends ApiTestCase
|
||||
public function testRegisterDomain(): void
|
||||
{
|
||||
$testUser = UserFactory::createOne();
|
||||
$client = DomainRefreshControllerTest::createClientWithCredentials(DomainRefreshControllerTest::getToken($testUser));
|
||||
$client = AutoRegisterDomainProviderTest::createClientWithCredentials(AutoRegisterDomainProviderTest::getToken($testUser));
|
||||
$client->request('GET', '/api/domains/example.com');
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
Reference in New Issue
Block a user