packages/requirements/tests/Unit/Verification/TestExecutionTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Verification;
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\Model\Item;
13use Requirements\Model\Project;
14use Requirements\Model\TestReference;
15use Requirements\Test\BehatRunner;
16use Requirements\Test\PhpUnitRunner;
17use Requirements\Test\Registry;
18use Requirements\Test\RunnerConfig;
19use Requirements\Test\TestResult;
20use Requirements\Verification\TestExecution;
21use Tests\Fake\CountingRunner;
22use Tests\Fake\ProjectDirectory;
23
24#[CoversClass(TestExecution::class)]
25#[UsesClass(Item::class)]
26#[UsesClass(Project::class)]
27#[UsesClass(TestReference::class)]
28#[UsesClass(Registry::class)]
29#[UsesClass(RunnerConfig::class)]
30#[UsesClass(TestResult::class)]
31#[UsesClass(PhpUnitRunner::class)]
32#[UsesClass(BehatRunner::class)]
33#[Small]
34final class TestExecutionTest extends TestCase
35{
36 /**
37 * @param list<string> $keys
38 */
39 #[DataProvider('providerModes')]
40 public function testRunDeduplicatesEligibleTargetsAndNeverRunsUnsupportedItems(bool $all, array $keys, string $executed): void
41 {
42 $directory = new ProjectDirectory();
43 $project = new Project($directory->directory, [], [], ['unit' => new RunnerConfig('custom', ['unused'], $directory->directory)], [], ['custom' => CountingRunner::class], 0.0, 0.0, [], []);
44 $manual = new Item('MANUAL', 'specification', 'The reader shall read.', 'supported', null, [], [new TestReference('unit', 'shared', 'manual'), new TestReference('unit', 'slow', 'manual')], [], [], [], '', 'original', 'Support editors.', 'definition.yaml', []);
45 $auto = new Item('AUTO', 'specification', 'The reader shall read.', 'supported', null, [], [new TestReference('unit', 'shared'), new TestReference('unit', 'shared')], [], [], [], '', 'original', 'Support editors.', 'definition.yaml', []);
46 $unsupported = new Item('UNSUPPORTED', 'specification', 'The reader shall read.', 'unsupported', null, [], [new TestReference('unit', 'never', 'manual')], [], [], [], '', 'original', 'Not implemented.', 'definition.yaml', []);
47 $requirement = new Item('REQ', 'requirement', 'The reader reads.', 'supported', null, [], [new TestReference('unit', 'never')], [], [], [], '', 'original', 'Upstream statement.', 'definition.yaml', []);
48 $results = (new TestExecution())->run($project, ['MANUAL' => $manual, 'AUTO' => $auto, 'UNSUPPORTED' => $unsupported, 'REQ' => $requirement], $all);
49 self::assertSame($keys, array_keys($results));
50 self::assertSame($executed, $directory->read('executions.txt'));
51 }
52
53 /**
54 * @return list<array{bool, list<string>, string}>
55 */
56 public static function providerModes(): array
57 {
58 return [
59 [false, ["unit\0shared"], "shared\n"],
60 [true, ["unit\0shared", "unit\0slow"], "shared\nslow\n"],
61 ];
62 }
63}
64