Files
crm_ecosplay/tests/Controller/WebhookStripeControllerTest.php
Serreau Jovann 8bda02888c test: couverture 83% methodes (1046 tests, 2135 assertions)
Entites completes a 100% :
- AdvertTest : 12 nouveaux (state, customer, totals, hmac, lines, payments)
- CustomerTest : 3 nouveaux (isPendingDelete, revendeurCode, updatedAt)
- DevisTest : 6 nouveaux (customer, submissionId, lines, state constants)
- FactureTest : 10 nouveaux (state, totals, isPaid, lines, hmac, splitIndex)
- OrderNumberTest : 1 nouveau (markAsUnused)
- WebsiteTest : 1 nouveau (revendeurCode)

Services completes/ameliores :
- DocuSealServiceTest : 30 nouveaux (sendDevis, resendDevis, download, compta)
- AdvertServiceTest : 6 nouveaux (isTvaEnabled, getTvaRate, computeTotals)
- DevisServiceTest : 6 nouveaux (idem)
- FactureServiceTest : 8 nouveaux (idem + createPaidFactureFromAdvert)
- MailerServiceTest : 7 nouveaux (unsubscribe headers, VCF, formatFileSize)
- MeilisearchServiceTest : 42 nouveaux (index/remove/search tous types)
- RgpdServiceTest : 6 nouveaux (sendVerificationCode, verifyCode)
- OrderNumberServiceTest : 2 nouveaux (preview/generate unused)
- TarificationServiceTest : 1 nouveau (stripe error logger)
- ComptaPdfTest : 4 nouveaux (totaux, colonnes numeriques, signature)
- FacturePdfTest : 6 nouveaux (QR code, RIB, CGV Twig, footer skip)

Controllers ameliores :
- ComptabiliteControllerTest : 13 nouveaux (JSON, PDF, sign, callback)
- StatsControllerTest : 2 nouveaux (rich data, 6-month evolution)
- SyncControllerTest : 13 nouveaux (sync 6 types + purge)
- ClientsControllerTest : 7 nouveaux (show, delete, resendWelcome)
- FactureControllerTest : 2 nouveaux (generatePdf 404, send success)
- LegalControllerTest : 6 nouveaux (rgpdVerify GET/POST)
- TarificationControllerTest : 3 nouveaux (purge paths)
- AdminControllersTest : 9 nouveaux (dashboard search, services)
- WebhookStripeControllerTest : 3 nouveaux (invalid signatures)
- KeycloakAuthenticatorTest : 4 nouveaux (groups, domain check)

Commands :
- PaymentReminderCommandTest : 1 nouveau (formalNotice step)
- TestMailCommandTest : 2 nouveaux (force-dsn success/failure)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 00:13:00 +02:00

118 lines
4.0 KiB
PHP

<?php
namespace App\Tests\Controller;
use App\Controller\WebhookStripeController;
use App\Entity\StripeWebhookSecret;
use App\Repository\StripeWebhookSecretRepository;
use App\Service\FactureService;
use App\Service\MailerService;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
class WebhookStripeControllerTest extends TestCase
{
private function createController(?string $secret = null): WebhookStripeController
{
$repo = $this->createStub(StripeWebhookSecretRepository::class);
$repo->method('getSecret')->willReturn($secret);
return new WebhookStripeController(
$this->createStub(LoggerInterface::class),
$repo,
$this->createStub(EntityManagerInterface::class),
$this->createStub(MailerService::class),
$this->createStub(Environment::class),
$this->createStub(FactureService::class),
$this->createStub(KernelInterface::class),
$this->createStub(UrlGeneratorInterface::class),
);
}
private function createPostRequest(string $body = '{}', string $signature = ''): Request
{
$request = new Request([], [], [], [], [], ['HTTP_STRIPE_SIGNATURE' => $signature], $body);
$request->setMethod('POST');
return $request;
}
public function testMainLightNoSecret(): void
{
$controller = $this->createController(null);
$response = $controller->mainLight($this->createPostRequest());
$this->assertSame(503, $response->getStatusCode());
$this->assertStringContainsString('not configured', $response->getContent());
}
public function testMainInstantNoSecret(): void
{
$controller = $this->createController(null);
$response = $controller->mainInstant($this->createPostRequest());
$this->assertSame(503, $response->getStatusCode());
}
public function testConnectLightNoSecret(): void
{
$controller = $this->createController(null);
$response = $controller->connectLight($this->createPostRequest());
$this->assertSame(503, $response->getStatusCode());
}
public function testConnectInstantNoSecret(): void
{
$controller = $this->createController(null);
$response = $controller->connectInstant($this->createPostRequest());
$this->assertSame(503, $response->getStatusCode());
}
public function testMainLightInvalidSignature(): void
{
$controller = $this->createController('whsec_test123');
$response = $controller->mainLight($this->createPostRequest('{"id":"evt_1"}', 't=123,v1=bad'));
$this->assertSame(400, $response->getStatusCode());
}
public function testMainLightInvalidPayload(): void
{
$controller = $this->createController('whsec_test123');
$response = $controller->mainLight($this->createPostRequest('not-json', ''));
$this->assertSame(400, $response->getStatusCode());
}
public function testMainInstantInvalidSignature(): void
{
$controller = $this->createController('whsec_test123');
$response = $controller->mainInstant($this->createPostRequest('{"id":"evt_1"}', 't=123,v1=bad'));
$this->assertSame(400, $response->getStatusCode());
}
public function testConnectLightInvalidSignature(): void
{
$controller = $this->createController('whsec_test123');
$response = $controller->connectLight($this->createPostRequest('{"id":"evt_1"}', 't=123,v1=bad'));
$this->assertSame(400, $response->getStatusCode());
}
public function testConnectInstantInvalidSignature(): void
{
$controller = $this->createController('whsec_test123');
$response = $controller->connectInstant($this->createPostRequest('{"id":"evt_1"}', 't=123,v1=bad'));
$this->assertSame(400, $response->getStatusCode());
}
}