<?php

declare(strict_types=1);

namespace CpCreation\AltchaBundle\Tests\PublicApi;

use PHPUnit\Framework\TestCase;

final class PackageMetadataTest extends TestCase
{
    public function testConcreteHttpClientIsARuntimeDependency(): void
    {
        $metadata = json_decode(
            (string) file_get_contents(dirname(__DIR__, 2).'/composer.json'),
            true,
            flags: JSON_THROW_ON_ERROR,
        );

        self::assertArrayHasKey('symfony/http-client', $metadata['require']);
        self::assertArrayNotHasKey('symfony/http-client', $metadata['require-dev'] ?? []);
    }

    public function testPackageIsDiscoveredBySymfonyFlexAsAUXPackage(): void
    {
        $metadata = json_decode(
            (string) file_get_contents(dirname(__DIR__, 2).'/composer.json'),
            true,
            flags: JSON_THROW_ON_ERROR,
        );
        $readme = (string) file_get_contents(dirname(__DIR__, 2).'/README.md');
        $assetMetadata = json_decode(
            (string) file_get_contents(dirname(__DIR__, 2).'/assets/package.json'),
            true,
            flags: JSON_THROW_ON_ERROR,
        );

        self::assertContains('symfony-ux', $metadata['keywords'] ?? []);
        self::assertStringContainsString('assets/controllers.json', $readme);
        self::assertStringContainsString('@cpcreation/altcha-bundle@file:vendor/cpcreation/altcha-bundle/assets', $readme);
        self::assertSame('3.2.2', $assetMetadata['peerDependencies']['altcha'] ?? null);
    }
}
