Skip to content

test: add Pest test harness with Security/Unit/Integration coverage - #105

Merged
TheWitness merged 2 commits into
mainfrom
test/expand-coverage
Sep 23, 2026
Merged

TheWitness merged 2 commits into
mainfrom
test/expand-coverage

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

This plugin had no Pest test infrastructure at all (only a placeholder tests/bootstrap-unit.php and tests/.cacti-version) - the existing CI workflow already gracefully skips its Pest step when phpunit.xml or tests/Security are absent. This PR builds the standard harness used across the rest of the plugin fleet and populates it with real coverage.

Test coverage added

  • Security: PHP compatibility scan (8.0-8.4 removed/added syntax) and a static structure check (required functions, INFO keys).
  • Unit: plugin_servcheck_version(), plugin_servcheck_uninstall() (drops all 9 tables), plugin_servcheck_setup_table() (creates all 6 tables via the plugin table-creation API), plugin_servcheck_upgrade() (the always-run steps once already past both version checkpoints: realm-file update, hook re-registration, final plugin_config UPDATE), plugin_servcheck_config_arrays() (menu entry, version-check page gating), plugin_servcheck_draw_navigation_text(), servcheck_config_settings(), servcheck_page_head(), servcheck_replicate_out()'s non-"all" no-op branch, plugin_servcheck_poller_bottom().
  • Integration: plugin_servcheck_install() - verifies every hook and the realm it registers, together with its full table set, in one end-to-end pass.

Intentionally not covered

plugin_servcheck_upgrade()'s two large version-gated migration cascades (0.3 and 0.4). These perform irreversible schema changes (table renames/drops, backup-table creation) and convert real credential data through servcheck_encrypt_credential() (real encryption via includes/functions.php, not a pure function safe to assert against in a unit test) - a much larger and riskier surface than this suite stubs.

Bootstrap additions (tests/bootstrap-unit.php, previously nearly empty)

api_plugin_register_hook/api_plugin_register_realm (logging), get_current_page/test_set_current_page, cacti_version_compare, db_table_exists, db_add_column/db_remove_column (logging), db_fetch_insert_id, get_selected_theme, exec_background (logging - safe here, plugin_servcheck_poller_bottom() include_once()s $config['library_path'], not the real lib/poller.php), replicate_out_table, and a settable db_fetch_cell fixture.

Other fix

tests/.cacti-version was pinned to a stale exact release (1.2.31), which made every local/CI run fail its own bootstrap version-match guard against a newer Cacti checkout. Corrected to 1.2.x.

Result

Verified via a real WSL Cacti install:

Tests:    25 passed (255 assertions)
Duration: 1.66s

This plugin had no Pest test infrastructure at all (only a placeholder
tests/bootstrap-unit.php and tests/.cacti-version) - the existing CI
workflow already gracefully skips its Pest step when phpunit.xml or
tests/Security are absent. Added the standard harness used across the
rest of the plugin fleet and populated it with real coverage:

- Security: PHP compatibility scan (8.0-8.4 removed/added syntax) and
  a static structure check (required functions, INFO keys).
- Unit: plugin_servcheck_version(), plugin_servcheck_uninstall()
  (drops all 9 tables), plugin_servcheck_setup_table() (creates all 6
  tables via the plugin table-creation API), plugin_servcheck_upgrade()
  (the always-run steps once already past both version checkpoints:
  realm-file update, hook re-registration, final plugin_config
  UPDATE), plugin_servcheck_config_arrays() (menu entry, version-check
  page gating), plugin_servcheck_draw_navigation_text(),
  servcheck_config_settings(), servcheck_page_head(),
  servcheck_replicate_out()'s non-"all" no-op branch,
  plugin_servcheck_poller_bottom().
- Integration: plugin_servcheck_install() (verifies every hook and the
  realm it registers, together with its full table set, end-to-end).

Intentionally NOT covered: plugin_servcheck_upgrade()'s two large
version-gated migration cascades (0.3 and 0.4). These perform
irreversible schema changes (table renames/drops, backup-table
creation) and convert real credential data through
servcheck_encrypt_credential() (real encryption via includes/functions.php,
not a pure function safe to assert against in a unit test) - a much
larger and riskier surface than this suite stubs.

Bootstrap additions (tests/bootstrap-unit.php, previously nearly
empty): api_plugin_register_hook/api_plugin_register_realm (logging),
get_current_page/test_set_current_page, cacti_version_compare,
db_table_exists, db_add_column/db_remove_column (logging),
db_fetch_insert_id, get_selected_theme, exec_background (logging - safe
here, plugin_servcheck_poller_bottom() include_once()s
$config['library_path'] not the real lib/poller.php),
replicate_out_table, and a settable db_fetch_cell fixture.

Also fixed a stale tests/.cacti-version pin (1.2.31 -> 1.2.x) that made
every local/CI run fail its own bootstrap version-match guard against
a newer Cacti checkout.

Verified via a real WSL Cacti install: 25 passed (255 assertions).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Moderate CI-selection and test-coverage issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 5 Medium severity

Open (5)
What changed in this PR

Adds a Pest testing harness with Security, Unit, and Integration coverage for the servcheck plugin.

Changes:

  • Adds PHPUnit/Pest configuration and Cacti-compatible test bootstrap stubs.
  • Adds lifecycle, setup, upgrade, navigation, poller, compatibility, and installation tests.
  • Updates the Cacti version fixture to support the moving 1.2.x branch.
File Description
tests/​Unit/​ServcheckUpgradeTest.php Tests upgrade behavior after migration checkpoints.
tests/​Unit/​ServcheckSetupTableTest.php Tests table provisioning.
tests/​Unit/​ServcheckPollerBottomTest.php Tests poller dispatch behavior.
tests/​Unit/​ServcheckLifecycleTest.php Tests version and uninstall behavior.
tests/​Unit/​ServcheckConfigAndNavigationTest.php Tests configuration and navigation helpers.
tests/​Security/​SetupStructureTest.php Validates setup structure and metadata.
tests/​Security/​PhpCompatibilityTest.php Checks PHP compatibility syntax.
tests/​Integration/​ServcheckInstallHooksTest.php Tests installation hooks, realm, and tables.
tests/​bootstrap-unit.php Adds Cacti test doubles and fixtures.
tests/​.cacti-version Allows testing against the moving Cacti 1.2.x branch.
phpunit.xml Defines Pest test suites and coverage configuration.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread phpunit.xml
Comment thread tests/Integration/ServcheckInstallHooksTest.php Outdated
Comment thread tests/Unit/ServcheckLifecycleTest.php Outdated
Comment thread tests/Unit/ServcheckSetupTableTest.php Outdated
Comment thread tests/Unit/ServcheckUpgradeTest.php Outdated
- CI workflow's Pest invocation only ran tests/Security, silently
  skipping tests/Unit and tests/Integration entirely (phpunit.xml
  already lists all three testsuite directories). Drop the explicit
  path argument so the full suite runs.
- Strengthen assertions across ServcheckInstallHooksTest,
  ServcheckLifecycleTest, and ServcheckSetupTableTest to check exact
  hook function names and the full/exact set of table names instead of
  a loose subset/count check.
- ServcheckUpgradeTest: broaden the "no migration cascade" assertion to
  also check for absent CREATE TABLE/DROP TABLE calls, not just RENAME
  COLUMN.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

CI dependency compatibility and test coverage issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (5)

Comment thread .github/workflows/plugin-ci-workflow.yml
Comment thread tests/Integration/ServcheckInstallHooksTest.php

@bmfmancini bmfmancini left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TheWitness
TheWitness merged commit 09d8615 into main Sep 23, 2026
4 checks passed
@TheWitness
TheWitness deleted the test/expand-coverage branch September 23, 2026 12:08
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.

3 participants