Skip to content

[3.0] Feature/plugin test support#5819

Open
ralf1070 wants to merge 2 commits into
kimai:devfrom
ralf1070:feature/plugin-test-support-v3
Open

[3.0] Feature/plugin test support#5819
ralf1070 wants to merge 2 commits into
kimai:devfrom
ralf1070:feature/plugin-test-support-v3

Conversation

@ralf1070

Copy link
Copy Markdown

Summary

Adds infrastructure for testing Kimai plugins within the main Kimai test environment:

  • Selective plugin loading in test environment: New LOAD_PLUGINS_IN_TEST env var in Kernel::registerBundles() controls which plugins are loaded during tests. Accepts a comma-separated list of bundle names (e.g. RemoteWorkBundle,WorkContractBundle). Without it, behavior is unchanged — no plugins are loaded in the test environment.
  • bin/test-plugins script: Standalone PHP script that discovers all installed plugins with a phpunit.xml and Tests/ directory, then runs PHPUnit for each one. Supports --plugin <name> to run a single plugin's tests. Extra CLI arguments are passed through (e.g. bin/test-plugins --filter testSomething). Disabled plugins (.disabled marker) are skipped.
  • composer tests-plugins: Composer script entry pointing to bin/test-plugins, consistent with existing composer tests, tests-unit, and tests-integration.
  • $_ENV/$_SERVER compatibility: Checks both $_ENV and $_SERVER for LOAD_PLUGINS_IN_TEST, since PHPUnit <env force="true"> sets $_ENV while Docker/shell env sets $_SERVER.
  • phpunit.xml.dist: Removed force="true" from DATABASE_URL so an existing environment variable (e.g. from a Docker container) takes precedence over the default.

Two-level test architecture

The test infrastructure uses a two-level approach to separate central concerns from plugin-specific needs:

Level 1: bin/test-plugins (central baseline)

Before each plugin suite, the script establishes a clean baseline:

  • Clears the Symfony test cache with APP_DEBUG=0 (matching PHPUnit's non-debug container) and all plugins loaded via LOAD_PLUGINS_IN_TEST
  • This ensures the compiled container includes the correct bundle registrations, even after core tests (composer tests) have run with a different container configuration

Level 2: Plugin bootstrap.php (plugin-specific)

Each plugin's bootstrap handles its own needs, e.g.:

  • doctrine:schema:update --force to ensure plugin-specific tables exist (idempotent — creates missing tables after core test reset, no-op when current)
  • Database initialization for CI/local environments (BOOTSTRAP_RESET_DATABASE=true)

This separation means bin/test-plugins doesn't need to know about plugin-specific database schemas, and plugins don't need to worry about cache state.

Usage

# Run all plugin test suites
composer tests-plugins
bin/test-plugins

# Run a single plugin
composer tests-plugins -- --plugin RemoteWorkBundle
bin/test-plugins --plugin RemoteWorkBundle

# With PHPUnit arguments
bin/test-plugins --plugin RemoteWorkBundle --filter testSomething
bin/test-plugins --stop-on-failure

Plugin phpunit.xml example

<phpunit bootstrap="Tests/bootstrap.php">
    <php>
        <env name="KERNEL_CLASS" value="App\Kernel" force="true"/>
        <env name="LOAD_PLUGINS_IN_TEST" value="MyPlugin,OtherPlugin" force="true"/>
        <env name="DATABASE_URL" value="mysql://test:test@127.0.0.1:3306/kimai_test?..."/>
    </php>
</phpunit>

Test plan

  • bin/test-plugins discovers and runs plugin test suites
  • composer tests-plugins invokes bin/test-plugins
  • --plugin <name> runs only a single plugin's test suite
  • Extra PHPUnit arguments are passed through correctly
  • Plugins without phpunit.xml or Tests/ directory are skipped
  • Disabled plugins (.disabled) are skipped
  • Cache is cleared with APP_DEBUG=0 before each suite (prevents stale non-debug container)
  • Plugin bootstrap recovers plugin tables after core test reset
  • Works both locally and inside Docker containers

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I verified that my code applies to the guidelines (composer code-check)
  • I updated the documentation (see here)
  • I agree that this code is used in Kimai (see license)

@kevinpapst kevinpapst added this to the 3.0 milestone Feb 10, 2026
@kevinpapst kevinpapst changed the title Feature/plugin test support v3 [3.0] Feature/plugin test support Feb 24, 2026
ralf1070 added 2 commits June 5, 2026 17:12
- Kernel: support LOAD_PLUGINS_IN_TEST env var ($_ENV and $_SERVER)
  to selectively load plugins in the test environment
- bin/test-plugins: discover and run all plugin test suites
  - Clear test cache with APP_DEBUG=0 before each suite (matches
    PHPUnit non-debug container)
  - Pass LOAD_PLUGINS_IN_TEST with all discovered plugins
  - Plugin bootstrap.php handles its own schema needs
- composer.json: add tests-plugins script
@ralf1070 ralf1070 force-pushed the feature/plugin-test-support-v3 branch from 31a4824 to 56897a1 Compare June 5, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants