This document describes the testing infrastructure for the Compose Manager plugin.
# Run all PHP unit tests
php vendor/bin/phpunit
# Run with detailed output
php vendor/bin/phpunit --testdox
# Run specific test file
php vendor/bin/phpunit tests/unit/UtilTest.php
# Run with code coverage (requires Xdebug)
php vendor/bin/phpunit --coverage-html tests/coverage/html# Using the helper script
.\run-bats.cmd
# Or directly with Docker
docker run --rm -v "${PWD}:/code" -w /code bats/bats:latest tests/unit/*.batsThe workspace is configured with PHPUnit Test Explorer. After opening the project:
- Open the Test Explorer panel (beaker icon in sidebar)
- Tests will be automatically discovered
- Click the play button to run tests
- Failed tests show inline in the editor
tests/
├── framework/ # Submodule: plugin-tests framework
│ └── src/
│ ├── php/
│ │ ├── Mocks/ # Function & global mocks
│ │ ├── TestCase.php
│ │ └── bootstrap.php
│ └── bats/
│ └── helpers/ # BATS helper functions
├── unit/
│ ├── UtilTest.php # PHP unit tests
│ └── compose.bats # BATS shell tests
├── results/ # JUnit XML output (CI)
└── coverage/ # Code coverage reports
<?php
use PluginTests\TestCase;
class MyTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
// Setup mocks
$this->mockGlobals(['var' => ['NAME' => 'TestServer']]);
$this->mockFunction('parse_plugin_cfg', fn() => ['key' => 'value']);
}
public function testSomething(): void
{
$this->assertEquals('expected', actual_function());
}
}#!/usr/bin/env bats
load '../framework/src/bats/setup.bash'
@test "function returns expected value" {
result=$(my_function "input")
assert_equals "expected" "$result"
}
@test "script handles errors" {
run my_script --invalid-option
assert_failure
assert_output_contains "error"
}The .github/workflows/tests.yml workflow runs on every push and PR:
- PHP Tests: Runs PHPUnit with coverage
- BATS Tests: Runs bash tests
- Static Analysis: Runs PHPStan
Test results appear in the GitHub Actions UI with proper reporting.
parse_plugin_cfg()- Config parsingautov()- Asset versioningcsrf_token()- CSRF protectionnotify()- Notificationssyslog()- Logging
$var- Unraid variables$disks- Disk information$shares- Share data$dockerClient- Docker API
docker/docker-compose- Container operationslogger- System loggingnotify- Unraid notifications- File operation helpers
Generate HTML coverage report:
php vendor/bin/phpunit --coverage-html tests/coverage/html
start tests/coverage/html/index.htmlNote: Code coverage requires Xdebug PHP extension.