packages/requirements/tests/Unit/Console/ItemRecordTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Console;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\Attributes\UsesClass;
10use PHPUnit\Framework\TestCase;
11use Requirements\Console\ItemRecord;
12use Requirements\Model\Item;
13use Requirements\Model\Source;
14
15#[CoversClass(ItemRecord::class)]
16#[UsesClass(Item::class)]
17#[UsesClass(Source::class)]
18#[Small]
19final class ItemRecordTest extends TestCase
20{
21    public function testDescribeReturnsTheCompleteTraceabilityRecord(): void
22    {
23        $item = new Item(
24            'SPEC-001',
25            'specification',
26            'The reader shall preserve positions.',
27            'unsupported',
28            new Source('manual', 'source.html', 'html', 'main p'),
29            [],
30            [],
31            ['REQ-001'],
32            ['SPEC-002'],
33            ['diagnostics', 'reader'],
34            'reader',
35            'sourced',
36            'The editor owns this behavior.',
37            'definition.yaml',
38            ['design' => [['text' => 'Preserve offsets.']], 'metadata' => ['owner' => 'parser'], 'tests' => [['runner' => 'unit', 'target' => 'ReaderTest::testA']]],
39        );
40        self::assertSame([
41            'id' => 'SPEC-001',
42            'kind' => 'specification',
43            'statement' => 'The reader shall preserve positions.',
44            'support' => 'unsupported',
45            'source' => 'manual',
46            'origin' => 'sourced',
47            'reason' => 'The editor owns this behavior.',
48            'labels' => ['diagnostics', 'reader'],
49            'category' => 'reader',
50            'requirements' => ['REQ-001'],
51            'related' => ['SPEC-002'],
52            'design' => [['text' => 'Preserve offsets.']],
53            'metadata' => ['owner' => 'parser'],
54            'test_references' => [['runner' => 'unit', 'target' => 'ReaderTest::testA']],
55        ], ItemRecord::describe($item));
56    }
57
58    public function testDescribeDefaultsMissingSourceDesignMetadataAndTests(): void
59    {
60        $item = new Item('ORIGINAL-001', 'requirement', 'Names may contain digits.', 'supported', null, [], [], [], [], [], '', 'original', 'Avoid data loss.', 'definition.yaml', ['id' => 'ORIGINAL-001']);
61        self::assertSame([
62            'id' => 'ORIGINAL-001',
63            'kind' => 'requirement',
64            'statement' => 'Names may contain digits.',
65            'support' => 'supported',
66            'source' => null,
67            'origin' => 'original',
68            'reason' => 'Avoid data loss.',
69            'labels' => [],
70            'category' => '',
71            'requirements' => [],
72            'related' => [],
73            'design' => [],
74            'metadata' => [],
75            'test_references' => [],
76        ], ItemRecord::describe($item));
77    }
78}
79