packages/sql-catalog/tests/Unit/Cli/CommandLineTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Cli;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\UsesClass;
9use PHPUnit\Framework\TestCase;
10use SqlCatalog\Cli\CommandLine;
11use SqlCatalog\Core\Catalog\Severity;
12use SqlCatalog\Core\Filter\CatalogFilter;
13
14#[CoversClass(CommandLine::class)]
15#[UsesClass(CatalogFilter::class)]
16#[UsesClass(\SqlCatalog\Facade\Configuration::class)]
17final class CommandLineTest extends TestCase
18{
19    public function testIsQueryWhenTheCommandWasAskedForInformation(): void
20    {
21        self::assertTrue((new CommandLine(help: true))->isQuery());
22        self::assertTrue((new CommandLine(listExtensions: true))->isQuery());
23        self::assertTrue((new CommandLine(listReporters: true))->isQuery());
24        self::assertFalse((new CommandLine(['src']))->isQuery());
25    }
26
27    public function testTheDefaultsAreTheOnesTheHelpDocuments(): void
28    {
29        $command = new CommandLine();
30        self::assertSame('text', $command->reporter);
31        self::assertSame(['pdo', 'mysqli'], $command->extensions);
32        self::assertSame('.', $command->root);
33        self::assertNull($command->output);
34        self::assertNull($command->failOn);
35        self::assertTrue($command->filter->isEmpty());
36    }
37
38    public function testWhatWasAskedForIsKept(): void
39    {
40        $command = new CommandLine(
41            ['src'],
42            'catalog',
43            'json',
44            ['laravel'],
45            new CatalogFilter(['App']),
46            ['vendor'],
47            'root',
48            Severity::High,
49        );
50        self::assertSame(['src'], $command->paths);
51        self::assertSame('catalog', $command->output);
52        self::assertSame(['vendor'], $command->excluded);
53        self::assertSame(Severity::High, $command->failOn);
54    }
55}
56