-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpUnitConfigGenerator.php
More file actions
116 lines (97 loc) · 3.71 KB
/
PhpUnitConfigGenerator.php
File metadata and controls
116 lines (97 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
declare(strict_types=1);
namespace KaririCode\Devkit\Configuration;
use KaririCode\Devkit\Contract\ConfigGenerator;
use KaririCode\Devkit\Core\ProjectContext;
/**
* Generates `.kcode/phpunit.xml.dist`.
*
* All caches and reports are routed to `.kcode/build/` to keep
* the project root clean. Bootstrap points to `../vendor/autoload.php`
* relative to the generated config location.
*
* @since 1.0.0
*/
final class PhpUnitConfigGenerator implements ConfigGenerator
{
#[\Override]
public function toolName(): string
{
return 'phpunit';
}
#[\Override]
public function outputPath(): string
{
return 'phpunit.xml.dist';
}
#[\Override]
public function generate(ProjectContext $context): string
{
$suites = $this->renderSuites($context);
$sourceIncludes = $this->renderDirList($context->relativeSourceDirs(), 12);
$coverageExcludes = $this->renderDirList($context->coverageExclude, 12);
return <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by KaririCode Devkit — override via devkit.php (project root) -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.5/phpunit.xsd"
bootstrap="../vendor/autoload.php"
cacheDirectory="build/.phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="false"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
colors="true">
<php>
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
<env name="APP_ENV" value="testing"/>
</php>
<testsuites>
{$suites} </testsuites>
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
{$sourceIncludes} </include>
<exclude>
{$coverageExcludes} </exclude>
</source>
<coverage includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="false">
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="php://stdout" showUncoveredFiles="false"/>
<clover outputFile="build/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/junit.xml"/>
</logging>
</phpunit>
XML;
}
private function renderSuites(ProjectContext $context): string
{
$xml = '';
foreach ($context->testSuites as $name => $relativeDir) {
$xml .= " <testsuite name=\"{$name}\">\n";
$xml .= " <directory>../{$relativeDir}</directory>\n";
$xml .= " </testsuite>\n";
}
return $xml;
}
/** @param list<string> $dirs */
private function renderDirList(array $dirs, int $indent): string
{
$pad = str_repeat(' ', $indent);
$xml = '';
foreach ($dirs as $dir) {
$xml .= "{$pad}<directory>../{$dir}</directory>\n";
}
return $xml;
}
}