From 213617c3c14dca84777f3d00db6a9e5b56c297a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sun, 19 Oct 2025 13:27:33 +0200 Subject: [PATCH] test: add test for Namecheap --- .env.test | 8 ++++++++ config/services.yaml | 2 ++ src/Service/Provider/NamecheapProvider.php | 4 +++- .../Service/Provider/AbstractProviderTest.php | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.env.test b/.env.test index 738de73..23b2d15 100644 --- a/.env.test +++ b/.env.test @@ -15,3 +15,11 @@ GANDI_PAT_TOKEN= NAMECOM_USERNAME= NAMECOM_PASSWORD= + +NAMECHEAP_USERNAME= +NAMECHEAP_TOKEN= + +# Typically your IP address, this envvar is required for +# some connectors that need to be provided with your host's +# outgoing IP address. +OUTGOING_IP= diff --git a/config/services.yaml b/config/services.yaml index e635b6e..7c2ffea 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -52,3 +52,5 @@ when@test: gandi_pat_token: '%env(string:GANDI_PAT_TOKEN)%' namecom_username: '%env(string:NAMECOM_USERNAME)%' namecom_password: '%env(string:NAMECOM_PASSWORD)%' + namecheap_username: '%env(string:NAMECHEAP_USERNAME)%' + namecheap_token: '%env(string:NAMECHEAP_TOKEN)%' diff --git a/src/Service/Provider/NamecheapProvider.php b/src/Service/Provider/NamecheapProvider.php index f2ee9b1..1095b65 100644 --- a/src/Service/Provider/NamecheapProvider.php +++ b/src/Service/Provider/NamecheapProvider.php @@ -11,6 +11,7 @@ use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\InvalidArgumentException; use Symfony\Component\DependencyInjection\Attribute\Autoconfigure; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; @@ -37,6 +38,7 @@ class NamecheapProvider extends AbstractProvider private readonly string $outgoingIp, DenormalizerInterface&NormalizerInterface $serializer, ValidatorInterface $validator, + private readonly KernelInterface $kernel, ) { parent::__construct($cacheItemPool, $serializer, $validator); } @@ -99,7 +101,7 @@ class NamecheapProvider extends AbstractProvider 'ClientIp' => $this->outgoingIp, ], $parameters); - $response = $this->client->request('POST', $dryRun ? self::SANDBOX_BASE_URL : self::BASE_URL, [ + $response = $this->client->request('POST', ($this->kernel->isDebug() || $dryRun) ? self::SANDBOX_BASE_URL : self::BASE_URL, [ 'query' => $actualParams, ]); diff --git a/tests/Service/Provider/AbstractProviderTest.php b/tests/Service/Provider/AbstractProviderTest.php index 93e3327..cf9cefb 100644 --- a/tests/Service/Provider/AbstractProviderTest.php +++ b/tests/Service/Provider/AbstractProviderTest.php @@ -54,6 +54,25 @@ class AbstractProviderTest extends ApiTestCase ]); } + #[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')] + public function testNamecheap() + { + $namecheapUsername = static::getContainer()->getParameter('namecheap_username'); + $namecheapToken = static::getContainer()->getParameter('namecheap_token'); + + if (!$namecheapUsername || !$namecheapToken) { + $this->markTestSkipped('Missing Namecheap username or token'); + } + + $this->testGenericProvider(ConnectorProvider::NAMECHEAP, [ + 'waiveRetractationPeriod' => true, + 'acceptConditions' => true, + 'ownerLegalAge' => true, + 'ApiUser' => $namecheapUsername, + 'ApiKey' => $namecheapToken, + ]); + } + private function testGenericProvider(ConnectorProvider $connectorProvider, array $authData): void { // Create a Connector