domain-watchdog/tests/State/RegisterUserProcessorTest.php

78 lines
2.4 KiB
PHP
Raw Normal View History

2025-10-14 23:46:46 +02:00
<?php
2025-12-11 10:32:29 +01:00
namespace App\Tests\State;
2025-10-14 23:46:46 +02:00
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use App\Factory\UserFactory;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
2025-10-14 23:46:46 +02:00
use Zenstruck\Foundry\Test\Factories;
2025-12-11 10:32:29 +01:00
final class RegisterUserProcessorTest extends ApiTestCase
2025-10-14 23:46:46 +02:00
{
use Factories;
protected static ContainerInterface $container;
protected static EntityManagerInterface $entityManager;
protected function setUp(): void
{
2025-12-11 10:32:29 +01:00
RegisterUserProcessorTest::$container = RegisterUserProcessorTest::getContainer();
RegisterUserProcessorTest::$entityManager = RegisterUserProcessorTest::$container->get(EntityManagerInterface::class);
2025-10-14 23:46:46 +02:00
}
public function testRegister(): void
{
$testUser = UserFactory::createOne();
2025-12-11 10:32:29 +01:00
RegisterUserProcessorTest::$entityManager->remove($testUser);
RegisterUserProcessorTest::$entityManager->flush();
2025-10-14 23:46:46 +02:00
$client = $this->createClient();
$client->request('POST', '/api/register', [
'json' => [
'email' => $testUser->getEmail(),
'password' => $testUser->getPlainPassword(),
],
]);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_CREATED);
2025-10-14 23:46:46 +02:00
}
public function testRegisterEmptyEmail(): void
{
$client = $this->createClient();
$client->request('POST', '/api/register', [
'json' => [
'email' => '',
'password' => 'MySuperPassword123',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
2025-10-14 23:46:46 +02:00
}
public function testRegisterEmptyPassword(): void
{
$client = $this->createClient();
$client->request('POST', '/api/register', [
'json' => [
'email' => 'test@domainwatchdog.eu',
'password' => '',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
2025-10-14 23:46:46 +02:00
}
public function testRegisterWeakPassword(): void
{
$client = $this->createClient();
$client->request('POST', '/api/register', [
'json' => [
'email' => 'test@domainwatchdog.eu',
'password' => '123',
],
]);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
2025-10-14 23:46:46 +02:00
}
}