Skip to content

Commit a8b5c2c

Browse files
committed
build: added coverage report to GitHub pages
1 parent 35a98fa commit a8b5c2c

46 files changed

Lines changed: 2044 additions & 485 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Code Coverage → GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
# Optional: Manuelles Triggern über die GitHub UI
7+
workflow_dispatch:
8+
9+
# Sicherstellen, dass immer nur ein Deployment gleichzeitig läuft
10+
concurrency:
11+
group: pages
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
pages: write
17+
id-token: write
18+
19+
jobs:
20+
coverage:
21+
name: Generate Coverage & Deploy
22+
runs-on: ubuntu-latest
23+
24+
environment:
25+
name: github-pages
26+
url: ${{ steps.deployment.outputs.page_url }}
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Setup PHP
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: '8.5'
36+
extensions: mbstring, xml, dom
37+
coverage: pcov
38+
39+
- name: Validate composer.json
40+
run: composer validate --strict
41+
42+
- name: Cache Composer packages
43+
uses: actions/cache@v4
44+
with:
45+
path: vendor
46+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
47+
restore-keys: |
48+
${{ runner.os }}-composer-
49+
50+
- name: Install dependencies
51+
run: composer install --no-interaction --prefer-dist
52+
53+
- name: Run tests with coverage
54+
run: |
55+
php -dxdebug.mode=coverage vendor/bin/phpunit \
56+
--coverage-html build/coverage \
57+
--coverage-clover build/coverage/clover.xml
58+
59+
# Optional: Coverage-Zusammenfassung in der GitHub Actions Summary anzeigen
60+
- name: Coverage Summary
61+
if: always()
62+
run: |
63+
if [ -f build/coverage/clover.xml ]; then
64+
echo "## Code Coverage Report" >> $GITHUB_STEP_SUMMARY
65+
echo "" >> $GITHUB_STEP_SUMMARY
66+
67+
# Gesamtabdeckung aus clover.xml extrahieren
68+
COVERED=$(grep -oP 'coveredstatements="\K[0-9]+' build/coverage/clover.xml | tail -1)
69+
TOTAL=$(grep -oP 'statements="\K[0-9]+' build/coverage/clover.xml | tail -1)
70+
71+
if [ -n "$COVERED" ] && [ -n "$TOTAL" ] && [ "$TOTAL" -gt 0 ]; then
72+
PERCENT=$(awk "BEGIN { printf \"%.1f\", ($COVERED/$TOTAL)*100 }")
73+
echo "**Gesamtabdeckung: ${PERCENT}%** (${COVERED}/${TOTAL} Statements)" >> $GITHUB_STEP_SUMMARY
74+
fi
75+
76+
echo "" >> $GITHUB_STEP_SUMMARY
77+
echo "📊 [Vollständiger Report](${{ steps.deployment.outputs.page_url }})" >> $GITHUB_STEP_SUMMARY
78+
fi
79+
80+
- name: Setup Pages
81+
uses: actions/configure-pages@v4
82+
83+
- name: Upload artifact
84+
uses: actions/upload-pages-artifact@v3
85+
with:
86+
path: build/coverage
87+
88+
- name: Deploy to GitHub Pages
89+
id: deployment
90+
uses: actions/deploy-pages@v4

composer.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
"@babel/preset-env": "^7.29.0",
5353
"@commitlint/cli": "^20.4.4",
5454
"@commitlint/config-conventional": "^20.4.4",
55-
"@eslint/js": "^9.39.3",
55+
"@eslint/js": "^9.39.4",
5656
"@types/bootstrap": "^5.2.10",
5757
"@types/highlightjs": "^9.12.6",
5858
"@types/jsdom": "^28.0.0",
5959
"@types/masonry-layout": "^4.2.8",
6060
"@types/node": "^25.5.0",
6161
"@types/sortablejs": "^1.15.9",
62-
"@vitest/coverage-istanbul": "^4.0.18",
63-
"@vitest/coverage-v8": "^4.0.18",
62+
"@vitest/coverage-istanbul": "^4.1.0",
63+
"@vitest/coverage-v8": "^4.1.0",
6464
"autoprefixer": "^10.4.27",
65-
"eslint": "^10.0.2",
65+
"eslint": "^10.0.3",
6666
"husky": "^9.1.7",
6767
"jsdom": "^28.1.0",
6868
"postcss": "^8.5.8",
@@ -76,8 +76,8 @@
7676
"vite-plugin-compression": "^0.5.1",
7777
"vite-plugin-html": "^3.2.2",
7878
"vite-plugin-minify": "^2.1.0",
79-
"vite-plugin-static-copy": "^3.2.0",
80-
"vitest": "^4.0.18",
79+
"vite-plugin-static-copy": "^3.3.0",
80+
"vitest": "^4.1.0",
8181
"vitest-fetch-mock": "^0.4.5"
8282
},
8383
"husky": {

phpmyfaq/assets/templates/default/index.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
{% endif %}
8989
<li><a class="dropdown-item" href="./login">{{ msgLoginUser }}</a></li>
9090
{% else %}
91-
<li><a class="dropdown-item" href="./user/ucp">{{ msgUserControlDropDown }}</a></li>run
91+
<li><a class="dropdown-item" href="./user/ucp">{{ msgUserControlDropDown }}</a></li>
9292
<li><a class="dropdown-item" href="./user/bookmarks">{{ msgBookmarks }}</a></li>
9393
<li>
9494
<a class="dropdown-item d-flex align-items-center" href="./user/chat">

phpmyfaq/src/phpMyFAQ/Auth/AuthSso.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
namespace phpMyFAQ\Auth;
2121

22+
use Closure;
2223
use phpMyFAQ\Auth;
2324
use phpMyFAQ\Configuration;
2425
use phpMyFAQ\Core\Exception;
@@ -35,15 +36,23 @@
3536
class AuthSso extends Auth implements AuthDriverInterface
3637
{
3738
private readonly Request $request;
39+
private readonly ?Closure $ldapFactory;
40+
private readonly ?Closure $userFactory;
3841

3942
/**
4043
* @inheritDoc
4144
*/
42-
public function __construct(Configuration $configuration)
43-
{
45+
public function __construct(
46+
Configuration $configuration,
47+
?Request $request = null,
48+
?Closure $ldapFactory = null,
49+
?Closure $userFactory = null,
50+
) {
4451
parent::__construct($configuration);
4552

46-
$this->request = Request::createFromGlobals();
53+
$this->request = $request ?? Request::createFromGlobals();
54+
$this->ldapFactory = $ldapFactory;
55+
$this->userFactory = $userFactory;
4756
}
4857

4958
/**
@@ -54,12 +63,12 @@ public function create(string $login, #[SensitiveParameter] string $password, st
5463
{
5564
if ($this->configuration->isLdapActive()) {
5665
// LDAP/AD + SSO
57-
$authLdap = new AuthLdap($this->configuration);
66+
$authLdap = $this->createLdapAuth();
5867
return $authLdap->create($login, '', $domain);
5968
}
6069

6170
// SSO without LDAP/AD
62-
$user = new User($this->configuration);
71+
$user = $this->createUser();
6372
$result = $user->createUser($login, '', $domain);
6473
$user->setStatus('active');
6574
$user->setAuthSource(AuthenticationSourceType::AUTH_SSO->value);
@@ -121,4 +130,22 @@ public function isValidLogin(string $login, ?array $optionalData = null): int
121130
{
122131
return $this->request->server->get('PHP_AUTH_USER') !== null ? 1 : 0;
123132
}
133+
134+
private function createLdapAuth(): AuthLdap
135+
{
136+
if ($this->ldapFactory instanceof Closure) {
137+
return ($this->ldapFactory)();
138+
}
139+
140+
return new AuthLdap($this->configuration);
141+
}
142+
143+
private function createUser(): User
144+
{
145+
if ($this->userFactory instanceof Closure) {
146+
return ($this->userFactory)();
147+
}
148+
149+
return new User($this->configuration);
150+
}
124151
}

phpmyfaq/src/phpMyFAQ/Bootstrap/ConfigDirectoryResolver.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ public static function computeAttachmentsPath(string $confAttachmentsPath, strin
134134
}
135135
}
136136

137-
$tmp = $rootDir . DIRECTORY_SEPARATOR . $confAttachmentsPath;
138-
139-
if (str_starts_with($tmp, $rootDir)) {
140-
return $tmp;
141-
}
142-
143-
return false;
137+
return $rootDir . DIRECTORY_SEPARATOR . $confAttachmentsPath;
144138
}
145139
}

0 commit comments

Comments
 (0)