Skip to content

Commit f162a4a

Browse files
rubenvdlindeclaude
andcommitted
feat: Add PHPUnit unit test bootstrap and CI integration
- Add tests/bootstrap-unit.php with OCP class autoloader (no Nextcloud bootstrap) - Update .github/workflows/code-quality.yml to run PHPUnit unit tests on every PR (uses --bootstrap tests/bootstrap-unit.php to skip Integration test setup) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c3944ce commit f162a4a

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/code-quality.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ jobs:
5454
echo "Critical violations: $CRITICAL" >> $GITHUB_STEP_SUMMARY
5555
fi
5656
57+
- name: PHPUnit (Unit Tests)
58+
run: ./vendor/bin/phpunit --bootstrap tests/bootstrap-unit.php --testsuite "Unit Tests" --configuration phpunit.xml
59+
5760
frontend-quality:
5861
name: Frontend Quality
5962
runs-on: ubuntu-latest

tests/bootstrap-unit.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* Bootstrap file for PHPUnit unit tests (minimal — no Nextcloud bootstrap required).
5+
*
6+
* @category Test
7+
* @package OCA\SoftwareCatalog\Tests
8+
*
9+
* @author Conduction Development Team <dev@conductio.nl>
10+
* @copyright 2024 Conduction B.V.
11+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
12+
*
13+
* @version GIT: <git-id>
14+
*
15+
* @link https://conductio.nl
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
// Define that we're running PHPUnit.
21+
define('PHPUNIT_RUN', 1);
22+
23+
// Include Composer's autoloader.
24+
require_once __DIR__ . '/../vendor/autoload.php';
25+
26+
// Register OCP/NCU classes from nextcloud/ocp package.
27+
// nextcloud/ocp has no autoload section in its composer.json, so we register it manually.
28+
spl_autoload_register(function (string $class): void {
29+
$prefixMap = [
30+
'OCP\\' => __DIR__ . '/../vendor/nextcloud/ocp/OCP/',
31+
'NCU\\' => __DIR__ . '/../vendor/nextcloud/ocp/NCU/',
32+
];
33+
34+
foreach ($prefixMap as $prefix => $dir) {
35+
if (strncmp($class, $prefix, strlen($prefix)) !== 0) {
36+
continue;
37+
}
38+
39+
$relative = str_replace(search: '\\', replace: '/', subject: substr($class, strlen($prefix)));
40+
$file = $dir . $relative . '.php';
41+
if (file_exists($file) === true) {
42+
require_once $file;
43+
}
44+
45+
break;
46+
}//end foreach
47+
48+
});

0 commit comments

Comments
 (0)