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()); } }