packages/deriver/tests/Unit/Deriver/Parser/ParserConfigTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Deriver\Parser;
6
7use Deriver\Deriver\Parser\ParserConfig;
8use Deriver\Exception\InvalidInputException;
9use PHPUnit\Framework\Attributes\CoversClass;
10use PHPUnit\Framework\Attributes\DataProvider;
11use PHPUnit\Framework\Attributes\Small;
12use PHPUnit\Framework\TestCase;
13
14#[CoversClass(ParserConfig::class)]
15#[Small]
16final class ParserConfigTest extends TestCase
17{
18    public function testRetainsOnlyThePhpVersion(): void
19    {
20        self::assertSame(['phpVersion' => '8.4'], get_object_vars(new ParserConfig('8.4')));
21    }
22
23    #[DataProvider('providerInvalidVersions')]
24    public function testRejectsMalformedVersionStrings(string $version): void
25    {
26        $this->expectException(InvalidInputException::class);
27        new ParserConfig($version);
28    }
29
30    /**
31     * @return iterable<string, array{string}>
32     */
33    public static function providerInvalidVersions(): iterable
34    {
35        yield 'empty' => [''];
36        yield 'major only' => ['8'];
37        yield 'trailing text' => ['8.3-invalid'];
38        yield 'patch version' => ['8.3.1'];
39    }
40}
41