From 8a3ba9eb5285ec57967bb49fff9af229c24bae4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Thu, 11 Dec 2025 10:53:08 +0100 Subject: [PATCH] test: use Response:: enum for HTTP status code --- tests/Controller/ConnectorControllerTest.php | 13 +++++++------ tests/Controller/HomeControllerTest.php | 3 ++- tests/Service/Provider/AbstractProviderTest.php | 5 +++-- tests/State/AutoRegisterDomainProviderTest.php | 3 ++- tests/State/RegisterUserProcessorTest.php | 9 +++++---- tests/State/WatchlistUpdateProcessorTest.php | 5 +++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tests/Controller/ConnectorControllerTest.php b/tests/Controller/ConnectorControllerTest.php index 1480e5d..e0e6822 100644 --- a/tests/Controller/ConnectorControllerTest.php +++ b/tests/Controller/ConnectorControllerTest.php @@ -9,6 +9,7 @@ use App\Message\ValidateConnectorCredentials; use App\MessageHandler\ValidateConnectorCredentialsHandler; use App\Tests\AuthenticatedUserTrait; use PHPUnit\Framework\Attributes\Depends; +use Symfony\Component\HttpFoundation\Response; use Zenstruck\Foundry\Test\Factories; final class ConnectorControllerTest extends ApiTestCase @@ -39,7 +40,7 @@ final class ConnectorControllerTest extends ApiTestCase ], 'provider' => 'gandi', ]]); - $this->assertResponseStatusCodeSame(400); + $this->assertResponseStatusCodeSame(Response::HTTP_BAD_REQUEST); } public function testCreateConnectorInvalidConsent(): void @@ -54,7 +55,7 @@ final class ConnectorControllerTest extends ApiTestCase ], 'provider' => 'gandi', ]]); - $this->assertResponseStatusCodeSame(451); + $this->assertResponseStatusCodeSame(Response::HTTP_UNAVAILABLE_FOR_LEGAL_REASONS); } public function testCreateConnectorInvalidAuthDataAdditionalKey(): void @@ -70,7 +71,7 @@ final class ConnectorControllerTest extends ApiTestCase ], 'provider' => 'gandi', ]]); - $this->assertResponseStatusCodeSame(400); + $this->assertResponseStatusCodeSame(Response::HTTP_BAD_REQUEST); } public function testCreateConnectorValidAuthData(): void @@ -89,7 +90,7 @@ final class ConnectorControllerTest extends ApiTestCase ], 'provider' => 'gandi', ]]); - $this->assertResponseStatusCodeSame(201); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); } #[Depends('testCreateConnectorValidAuthData')] @@ -118,10 +119,10 @@ final class ConnectorControllerTest extends ApiTestCase ], 'provider' => 'gandi', ]]); - $this->assertResponseStatusCodeSame(201); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); $client->request('DELETE', '/api/connectors/'.$response->toArray()['id']); - $this->assertResponseStatusCodeSame(204); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); } } diff --git a/tests/Controller/HomeControllerTest.php b/tests/Controller/HomeControllerTest.php index 5aa12ce..ea0c95b 100644 --- a/tests/Controller/HomeControllerTest.php +++ b/tests/Controller/HomeControllerTest.php @@ -3,6 +3,7 @@ namespace App\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpFoundation\Response; class HomeControllerTest extends WebTestCase { @@ -11,6 +12,6 @@ class HomeControllerTest extends WebTestCase $client = static::createClient(); $client->request('GET', '/login/oauth'); - $this->assertResponseStatusCodeSame(404); + $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND); } } diff --git a/tests/Service/Provider/AbstractProviderTest.php b/tests/Service/Provider/AbstractProviderTest.php index 05c2aef..b53117c 100644 --- a/tests/Service/Provider/AbstractProviderTest.php +++ b/tests/Service/Provider/AbstractProviderTest.php @@ -16,6 +16,7 @@ use App\Tests\State\WatchlistUpdateProcessorTest; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\Attributes\DependsExternal; use Symfony\Component\HttpClient\Exception\ServerException; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Uid\UuidV4; class AbstractProviderTest extends ApiTestCase @@ -83,7 +84,7 @@ class AbstractProviderTest extends ApiTestCase 'authData' => $authData, 'provider' => $connectorProvider->value, ]]); - $this->assertResponseStatusCodeSame(201); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); /** @var EntityManagerInterface $entityManager */ $entityManager = self::getContainer()->get(EntityManagerInterface::class); @@ -112,7 +113,7 @@ class AbstractProviderTest extends ApiTestCase $message = new OrderDomain($watchlist->getToken(), $domain->getLdhName(), $domain->getUpdatedAt()); $orderDomainHandler($message); - $this->assertResponseStatusCodeSame(200); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); } catch (ServerException $e) { $this->markTestSkipped('Provider '.$connectorProvider->value.' is not ready. Response HTTP '.$e->getResponse()->getStatusCode()); } diff --git a/tests/State/AutoRegisterDomainProviderTest.php b/tests/State/AutoRegisterDomainProviderTest.php index 4cd4b88..5a19174 100644 --- a/tests/State/AutoRegisterDomainProviderTest.php +++ b/tests/State/AutoRegisterDomainProviderTest.php @@ -10,6 +10,7 @@ use App\Service\RDAPService; use App\Tests\AuthenticatedUserTrait; use App\Tests\Service\RDAPServiceTest; use PHPUnit\Framework\Attributes\DependsExternal; +use Symfony\Component\HttpFoundation\Response; use Zenstruck\Foundry\Test\Factories; final class AutoRegisterDomainProviderTest extends ApiTestCase @@ -33,7 +34,7 @@ final class AutoRegisterDomainProviderTest extends ApiTestCase $client = $this->createClient(); $client->request('GET', '/api/domains/example.com'); - $this->assertResponseStatusCodeSame(401); + $this->assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED); } #[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')] diff --git a/tests/State/RegisterUserProcessorTest.php b/tests/State/RegisterUserProcessorTest.php index 3b99ff3..92573a2 100644 --- a/tests/State/RegisterUserProcessorTest.php +++ b/tests/State/RegisterUserProcessorTest.php @@ -6,6 +6,7 @@ use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use App\Factory\UserFactory; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Response; use Zenstruck\Foundry\Test\Factories; final class RegisterUserProcessorTest extends ApiTestCase @@ -35,7 +36,7 @@ final class RegisterUserProcessorTest extends ApiTestCase ], ]); $this->assertResponseIsSuccessful(); - $this->assertResponseStatusCodeSame(201); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); } public function testRegisterEmptyEmail(): void @@ -47,7 +48,7 @@ final class RegisterUserProcessorTest extends ApiTestCase 'password' => 'MySuperPassword123', ], ]); - $this->assertResponseStatusCodeSame(422); + $this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY); } public function testRegisterEmptyPassword(): void @@ -59,7 +60,7 @@ final class RegisterUserProcessorTest extends ApiTestCase 'password' => '', ], ]); - $this->assertResponseStatusCodeSame(422); + $this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY); } public function testRegisterWeakPassword(): void @@ -71,6 +72,6 @@ final class RegisterUserProcessorTest extends ApiTestCase 'password' => '123', ], ]); - $this->assertResponseStatusCodeSame(422); + $this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY); } } diff --git a/tests/State/WatchlistUpdateProcessorTest.php b/tests/State/WatchlistUpdateProcessorTest.php index d612aa4..deeacf4 100644 --- a/tests/State/WatchlistUpdateProcessorTest.php +++ b/tests/State/WatchlistUpdateProcessorTest.php @@ -9,6 +9,7 @@ use App\Factory\UserFactory; use App\Tests\AuthenticatedUserTrait; use App\Tests\Service\RDAPServiceTest; use PHPUnit\Framework\Attributes\DependsExternal; +use Symfony\Component\HttpFoundation\Response; use Zenstruck\Foundry\Test\Factories; final class WatchlistUpdateProcessorTest extends ApiTestCase @@ -21,7 +22,7 @@ final class WatchlistUpdateProcessorTest extends ApiTestCase { self::createUserAndWatchlist(); $this->assertResponseIsSuccessful(); - $this->assertResponseStatusCodeSame(201); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); $this->assertMatchesResourceItemJsonSchema(Watchlist::class); } @@ -31,7 +32,7 @@ final class WatchlistUpdateProcessorTest extends ApiTestCase $client = self::createClientWithCredentials(self::getToken(UserFactory::createOne())); self::createUserAndWatchlist($client); self::createUserAndWatchlist($client); - $this->assertResponseStatusCodeSame(403); + $this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN); } #[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]