packages/requirements/tests/Unit/Config/Markdown/Render/RecordTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Config\Markdown\Render;
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\Config\Markdown\Render\Record;
13use Requirements\Input\Fields;
14use Requirements\Input\InvalidInputException;
15use stdClass;
16
17#[CoversClass(Record::class)]
18#[UsesClass(Fields::class)]
19#[Small]
20final class RecordTest extends TestCase
21{
22 public function testFieldsReturnsTheRecordFields(): void
23 {
24 self::assertSame(['runner' => 'unit', 'target' => 'A::b'], Record::fields((object) ['runner' => 'unit', 'target' => 'A::b']));
25 }
26
27 public function testFieldsReturnsNothingForAnEmptyRecord(): void
28 {
29 self::assertSame([], Record::fields(new stdClass()));
30 }
31
32 #[DataProvider('providerNotRecords')]
33 public function testFieldsRejectsAValueThatIsNotARecord(mixed $value): void
34 {
35 $this->expectException(InvalidInputException::class);
36 $this->expectExceptionMessage('Expected a Markdown record.');
37 Record::fields($value);
38 }
39
40 /**
41 * @return array<string, array{mixed}>
42 */
43 public static function providerNotRecords(): array
44 {
45 return [
46 'string' => ['REQ-001'],
47 'mapping array' => [['runner' => 'unit']],
48 'null' => [null],
49 ];
50 }
51
52 public function testFieldsRejectsNumericKeys(): void
53 {
54 $this->expectException(InvalidInputException::class);
55 $this->expectExceptionMessage('record must have string keys.');
56 Record::fields((object) ['first']);
57 }
58}
59