packages/requirements/tests/Unit/Console/SpecificationReportTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Console;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\DataProvider;
9use PHPUnit\Framework\Attributes\Small;
10use PHPUnit\Framework\Attributes\UsesClass;
11use PHPUnit\Framework\TestCase;
12use Requirements\Console\ItemRecord;
13use Requirements\Console\Options;
14use Requirements\Console\SpecificationReport;
15use Requirements\Model\Item;
16use Requirements\Model\Project;
17use Requirements\Verification\VerificationResult;
18use Requirements\Verification\Verifier;
19
20#[CoversClass(SpecificationReport::class)]
21#[UsesClass(ItemRecord::class)]
22#[UsesClass(Options::class)]
23#[UsesClass(Item::class)]
24#[UsesClass(Project::class)]
25#[UsesClass(Verifier::class)]
26#[UsesClass(VerificationResult::class)]
27#[Small]
28final class SpecificationReportTest extends TestCase
29{
30 /**
31 * @param array<string, string|bool> $options
32 * @param list<string> $errors
33 */
34 #[DataProvider('providerGates')]
35 public function testGenerateChecksLinkageIndependentlyOfExecution(array $options, bool $passed, array $errors): void
36 {
37 $item = new Item('SPEC-1', 'specification', 'The reader shall read.', 'supported', null, [], [], [], [], [], '', 'original', 'Support editors.', 'definition.yaml', []);
38 $project = new Project('.', ['SPEC-1' => $item], [], [], [], [], 0.0, 0.0, [], []);
39 $report = (new SpecificationReport())->generate($project, new Options('spec', ['no-test' => true, ...$options]));
40 self::assertSame($passed, $report['passed']);
41 self::assertSame($errors, $report['errors']);
42 self::assertTrue($report['no_test']);
43 }
44
45 /**
46 * @return list<array{array<string, string|bool>, bool, list<string>}>
47 */
48 public static function providerGates(): array
49 {
50 return [
51 [[], true, []],
52 [['strict' => true], false, ['SPEC-1: No tests linked.']],
53 [['id' => 'MISSING'], true, []],
54 [['id' => 'MISSING', 'strict' => true], false, ['No specifications or requirements selected.']],
55 ];
56 }
57}
58