Skip to content

test: expand Unit/Integration coverage for lifecycle, menus, and schema - #64

Open
TheWitness wants to merge 1 commit into
developfrom
test/expand-coverage
Open

TheWitness wants to merge 1 commit into
developfrom
test/expand-coverage

Conversation

@TheWitness

Copy link
Copy Markdown
Member

This plugin already had thorough Unit coverage for plugin_maint_check_host()/plugin_maint_check_schedule() (the actual maintenance-window logic) plus extensive Security coverage. The gap was setup.php's plugin lifecycle and setup functions, which were only checked for static existence. Closed that gap, running the full suite against a real Cacti install in WSL (composer-managed Pest, not a plugin-local vendor tree) until everything passed.

Added coverage

  • Unit: plugin_maint_version(), plugin_maint_uninstall(), plugin_maint_check_config()/plugin_maint_upgrade(), maint_config_arrays() (menu registration), maint_draw_navigation_text(), maint_device_action_array() (dropdown action registration), and maint_setup_database() (verifies both tables it provisions).
  • Integration: plugin_maint_install() (verifies every hook, the realm, and the tables it provisions, together, in one pass) — this plugin had no tests/Integration category before.

Security

No new unserialize() hardening was needed: every unserialize() call in this plugin already goes through sanitize_unserialize_selected_items().

Intentionally not covered

maint_device_edit_top_links() (print-only, depends on real request context), maint_device_action_prepare() (large print-heavy confirmation-dialog renderer), and maint_device_action_execute() (creates/updates real schedule rows with substantial branching) are left uncovered as comparatively low-value relative to the effort of safely mocking their dependencies, consistent with similarly-scoped functions skipped elsewhere in this coverage-expansion pass.

Test infrastructure

tests/bootstrap-unit.php gained api_plugin_register_hook/api_plugin_register_realm call-logging stubs and upgraded api_plugin_db_table_create to log its calls, reusing this repo's existing maint_test_queue()/maint_test_next() fixture convention where applicable. phpunit.xml now includes tests/Integration in the testsuite.

Result

Tests: 50 passed (161 assertions), up from 41.

This plugin already had thorough Unit coverage for
plugin_maint_check_host()/plugin_maint_check_schedule() (the actual
maintenance-window logic) plus extensive Security coverage. The gap
was setup.php's plugin lifecycle and setup functions, which were only
checked for static existence. Closed that gap:

- Unit: plugin_maint_version(), plugin_maint_uninstall(),
  plugin_maint_check_config()/plugin_maint_upgrade(),
  maint_config_arrays() (menu registration), maint_draw_navigation_text(),
  maint_device_action_array() (dropdown action registration), and
  maint_setup_database() (verifies both tables it provisions).
- Integration: plugin_maint_install() (verifies every hook, the
  realm, and the tables it provisions, together, in one pass) - this
  plugin had no tests/Integration category before.

No new unserialize() hardening was needed: every unserialize() call in
this plugin already goes through sanitize_unserialize_selected_items().

Intentionally left uncovered: maint_device_edit_top_links() (print-only,
depends on real request context), maint_device_action_prepare() (large
print-heavy confirmation-dialog renderer), and
maint_device_action_execute() (creates/updates real schedule rows with
substantial branching) are left uncovered as comparatively low-value
relative to the effort of safely mocking their dependencies, consistent
with similarly-scoped functions skipped elsewhere in this
coverage-expansion pass.

tests/bootstrap-unit.php gained api_plugin_register_hook/
api_plugin_register_realm call-logging stubs and upgraded
api_plugin_db_table_create to log its calls, reusing this repo's
existing maint_test_queue()/maint_test_next() fixture convention where
applicable. phpunit.xml now includes tests/Integration in the
testsuite.

Verified via a real WSL Cacti install (composer-managed Pest, not a
plugin-local vendor tree): 50 passed (161 assertions), up from 41.

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

Unresolved moderate findings affect integration-test validity and assertion completeness.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Expands automated coverage for the maintenance plugin’s lifecycle, navigation, actions, schema setup, and installation registration.

Changes:

  • Adds unit tests for lifecycle, menus, navigation, actions, and database setup.
  • Adds installation hook, realm, and table registration coverage.
  • Extends test stubs and includes tests/Integration in PHPUnit.
File Summary
tests/​Unit/​MaintLifecycleTest.php Adds lifecycle and version tests.
tests/​Unit/​MaintDeviceActionsAndDatabaseTest.php Adds action and schema tests; moderate findings (1 vote each) require asserting labels/mappings and complete table definitions, including the composite primary key.
tests/​Unit/​MaintConfigAndNavigationTest.php Adds menu and navigation tests; a moderate finding (1 vote) requires asserting complete breadcrumb values, not only keys.
tests/​Integration/​MaintInstallHooksTest.php Adds installation registration coverage; a moderate finding (2 votes) notes that the unit bootstrap stubs APIs, so this is not Cacti-backed integration coverage.
tests/​bootstrap-unit.php Adds recording stubs for hook, realm, and schema calls.
phpunit.xml Includes integration tests, but a moderate finding (1 vote) notes they still use the unit bootstrap.

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

});

it('registers every hook maint depends on, its realm, and provisions its tables', function () {
plugin_maint_install();

@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

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