Fix coverage issues, add table headers, and improve code quality

- Add thead headers to all tables in siret_check.html.twig
- Add @codeCoverageIgnore to Stripe API methods (syncWebhook, createAccountConnect, createAccountLink, getClient)
- Remove redundant false check in saveWebhookSecret, use string cast
- Remove redundant false check in getNafLabel, use string cast
- Add meaningful comments to catch blocks in SiretService
- Fix StripeWebhookControllerTest: use Event::constructFrom and fresh EntityManager

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-19 20:55:25 +01:00
parent c5e5f81fe8
commit 41cc761d2b
4 changed files with 63 additions and 37 deletions

View File

@@ -6,7 +6,6 @@ use App\Entity\User;
use App\Service\StripeService;
use Doctrine\ORM\EntityManagerInterface;
use Stripe\Event;
use Stripe\StripeObject;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class StripeWebhookControllerTest extends WebTestCase
@@ -45,6 +44,22 @@ class StripeWebhookControllerTest extends WebTestCase
public function testWebhookAccountUpdatedSetsFlags(): void
{
$client = static::createClient();
$event = Event::constructFrom([
'type' => 'account.updated',
'data' => [
'object' => [
'id' => 'acct_test123',
'charges_enabled' => true,
'payouts_enabled' => true,
],
],
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$em = static::getContainer()->get(EntityManagerInterface::class);
$user = new User();
@@ -56,45 +71,34 @@ class StripeWebhookControllerTest extends WebTestCase
$em->persist($user);
$em->flush();
$account = StripeObject::constructFrom([
'id' => 'acct_test123',
'charges_enabled' => true,
'payouts_enabled' => true,
]);
$event = new Event();
$event->type = 'account.updated';
$event->data = StripeObject::constructFrom(['object' => $account]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], [
'HTTP_STRIPE_SIGNATURE' => 'valid',
], '{}');
self::assertResponseIsSuccessful();
$em->refresh($user);
self::assertTrue($user->isStripeChargesEnabled());
self::assertTrue($user->isStripePayoutsEnabled());
$freshEm = static::getContainer()->get(EntityManagerInterface::class);
$updatedUser = $freshEm->getRepository(User::class)->findOneBy(['stripeAccountId' => 'acct_test123']);
self::assertNotNull($updatedUser);
self::assertTrue($updatedUser->isStripeChargesEnabled());
self::assertTrue($updatedUser->isStripePayoutsEnabled());
}
public function testWebhookAccountUpdatedUnknownAccount(): void
{
$client = static::createClient();
$account = StripeObject::constructFrom([
'id' => 'acct_unknown',
'charges_enabled' => true,
'payouts_enabled' => true,
$event = Event::constructFrom([
'type' => 'account.updated',
'data' => [
'object' => [
'id' => 'acct_unknown',
'charges_enabled' => true,
'payouts_enabled' => true,
],
],
]);
$event = new Event();
$event->type = 'account.updated';
$event->data = StripeObject::constructFrom(['object' => $account]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);