Skip to content

Commit f81d320

Browse files
authored
Merge pull request #3 from KaririCode-Framework/develop
fix(ci): use robust XML patching for phpunit.xml.dist
2 parents 6565c79 + 94ee236 commit f81d320

2 files changed

Lines changed: 107 additions & 10 deletions

File tree

.github/workflows/code-quality.yml

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,26 @@ jobs:
9494
- name: Initialize devkit
9595
run: kcode init
9696

97-
# Patch generated phpunit.xml.dist — PHPUnit 12 emits false-positive warnings for
98-
# classes extending built-ins outside <source>; failOnWarning=true would then fail.
97+
# Patch generated phpunit.xml.dist — PHPUnit 12 emits false-positive warnings
98+
# for classes extending built-ins outside <source>; use python3 for reliable XML edit.
9999
- name: Patch phpunit.xml.dist
100100
run: |
101-
sed -i 's/beStrictAboutCoverageMetadata="true"/beStrictAboutCoverageMetadata="false"/' .kcode/phpunit.xml.dist
102-
sed -i 's/failOnWarning="true"/failOnWarning="false"/' .kcode/phpunit.xml.dist
103-
sed -i 's/restrictWarnings="true"/restrictWarnings="false"/' .kcode/phpunit.xml.dist
101+
python3 - <<'EOF'
102+
import xml.etree.ElementTree as ET
103+
ET.register_namespace('', 'http://www.w3.org/2001/XMLSchema-instance')
104+
path = '.kcode/phpunit.xml.dist'
105+
tree = ET.parse(path)
106+
root = tree.getroot()
107+
root.set('failOnWarning', 'false')
108+
root.set('failOnRisky', 'false')
109+
root.set('beStrictAboutCoverageMetadata', 'false')
110+
src = root.find('source')
111+
if src is not None:
112+
src.attrib.pop('restrictWarnings', None)
113+
src.attrib.pop('restrictDeprecations', None)
114+
src.attrib.pop('restrictNotices', None)
115+
tree.write(path, xml_declaration=True, encoding='UTF-8')
116+
EOF
104117
105118
# Runs PHPStan Level 9 then Psalm sequentially — both must pass
106119
- name: Run PHPStan + Psalm via kcode
@@ -168,13 +181,26 @@ jobs:
168181
- name: Initialize devkit
169182
run: kcode init
170183

171-
# Patch generated phpunit.xml.dist — PHPUnit 12 emits false-positive warnings for
172-
# classes extending built-ins outside <source>; failOnWarning=true would then fail.
184+
# Patch generated phpunit.xml.dist — PHPUnit 12 emits false-positive warnings
185+
# for classes extending built-ins outside <source>; use python3 for reliable XML edit.
173186
- name: Patch phpunit.xml.dist
174187
run: |
175-
sed -i 's/beStrictAboutCoverageMetadata="true"/beStrictAboutCoverageMetadata="false"/' .kcode/phpunit.xml.dist
176-
sed -i 's/failOnWarning="true"/failOnWarning="false"/' .kcode/phpunit.xml.dist
177-
sed -i 's/restrictWarnings="true"/restrictWarnings="false"/' .kcode/phpunit.xml.dist
188+
python3 - <<'EOF'
189+
import xml.etree.ElementTree as ET
190+
ET.register_namespace('', 'http://www.w3.org/2001/XMLSchema-instance')
191+
path = '.kcode/phpunit.xml.dist'
192+
tree = ET.parse(path)
193+
root = tree.getroot()
194+
root.set('failOnWarning', 'false')
195+
root.set('failOnRisky', 'false')
196+
root.set('beStrictAboutCoverageMetadata', 'false')
197+
src = root.find('source')
198+
if src is not None:
199+
src.attrib.pop('restrictWarnings', None)
200+
src.attrib.pop('restrictDeprecations', None)
201+
src.attrib.pop('restrictNotices', None)
202+
tree.write(path, xml_declaration=True, encoding='UTF-8')
203+
EOF
178204
179205
- name: Run tests with coverage (pcov)
180206
run: kcode test --coverage

devkit.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* KaririCode Devkit — Project Overrides
7+
*
8+
* This file customizes the devkit behavior for this project.
9+
* Only uncomment the keys you need to change — unset keys use
10+
* auto-detected values from composer.json + KaririCode defaults.
11+
*
12+
* Merge semantics:
13+
* - cs_fixer_rules → MERGED with KaririCode defaults (your rules win on conflict)
14+
* - rector_sets → REPLACES KaririCode defaults entirely
15+
* - All others → REPLACES the auto-detected value
16+
*
17+
* After editing, run: kcode init
18+
*
19+
* @see https://github.com/kariricode/devkit
20+
*/
21+
22+
return [
23+
// ── Project Identity ──────────────────────────────────────
24+
// 'project_name' => 'kariricode/my-component',
25+
// 'namespace' => 'KaririCode\\MyComponent',
26+
27+
// ── PHP Version ───────────────────────────────────────────
28+
// 'php_version' => '8.4',
29+
30+
// ── Static Analysis ───────────────────────────────────────
31+
// 'phpstan_level' => 9, // 0–9 (default: 9)
32+
// 'psalm_level' => 3, // 1–9 (default: 3)
33+
34+
// ── Directories ───────────────────────────────────────────
35+
// 'source_dirs' => ['src'],
36+
// 'test_dirs' => ['tests'],
37+
// 'exclude_dirs' => ['src/Contract'], // excluded from static analysis
38+
39+
// ── Test Suites ───────────────────────────────────────────
40+
// 'test_suites' => [
41+
// 'Unit' => 'tests/Unit',
42+
// 'Integration' => 'tests/Integration',
43+
// ],
44+
45+
// ── Coverage ──────────────────────────────────────────────
46+
// 'coverage_exclude' => ['src/Exception'],
47+
48+
// ── Code Style (MERGED with KaririCode defaults) ──────────
49+
// 'cs_fixer_rules' => [
50+
// 'concat_space' => ['spacing' => 'one'],
51+
// 'yoda_style' => false,
52+
// ],
53+
54+
// ── Rector (REPLACES KaririCode defaults) ─────────────────
55+
// 'rector_sets' => [
56+
// 'LevelSetList::UP_TO_PHP_84',
57+
// 'SetList::CODE_QUALITY',
58+
// 'SetList::DEAD_CODE',
59+
// 'SetList::EARLY_RETURN',
60+
// 'SetList::TYPE_DECLARATION',
61+
// ],
62+
63+
// ── Tool Versions (informational) ─────────────────────────
64+
// 'tools' => [
65+
// 'phpunit' => '^11.0',
66+
// 'phpstan' => '^2.0',
67+
// 'php-cs-fixer' => '^3.64',
68+
// 'rector' => '^2.0',
69+
// 'psalm' => '^6.0',
70+
// ],
71+
];

0 commit comments

Comments
 (0)