<?php

namespace App\Tests\Controller;

use App\Controller\SonarBadgeController;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

class SonarBadgeControllerTest extends TestCase
{
    public function testBadgeSuccess(): void
    {
        $httpResponse = $this->createStub(ResponseInterface::class);
        $httpResponse->method('getContent')->willReturn('<svg>badge</svg>');

        $httpClient = $this->createStub(HttpClientInterface::class);
        $httpClient->method('request')->willReturn($httpResponse);

        $controller = new SonarBadgeController();
        $response = $controller->badge('coverage', $httpClient, 'https://sonar.test', 'project', 'token');

        $this->assertSame(200, $response->getStatusCode());
        $this->assertSame('image/svg+xml', $response->headers->get('Content-Type'));
        $this->assertSame('<svg>badge</svg>', $response->getContent());
    }

    public function testBadgeInvalidMetric(): void
    {
        $httpClient = $this->createStub(HttpClientInterface::class);

        $controller = new SonarBadgeController();
        $response = $controller->badge('invalid_metric', $httpClient, 'https://sonar.test', 'project', 'token');

        $this->assertSame(404, $response->getStatusCode());
    }
}
