Skip to content

refactor: safe PHP 7.4 modernization + Pest unit-test framework - #98

Closed
TheWitness wants to merge 11 commits into
mainfrom
refactor/modernization
Closed

refactor: safe PHP 7.4 modernization + Pest unit-test framework#98
TheWitness wants to merge 11 commits into
mainfrom
refactor/modernization

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

  • Safe PHP 7.4-compatible modernization (arrays, null coalescing) with corrupted-refactor fixes restored.
  • SQL filter hardening in admin screens (proxies/CA search).
  • Dropped declare(strict_types=1) repo-wide for PHP 7.4 compatibility.
  • Added CI workflow (.github/workflows/plugin-ci-workflow.yml) and Pest unit-test scaffolding (phpunit.xml, tests/bootstrap-unit.php, tests/TestCase.php, tests/Pest.php, tests/.cacti-version), adapted for this branch's existing tests/Unit layout:
    • Pest step targets tests/Unit (where ArraysDefinitionTest.php lives) instead of a tests/Security directory that doesn't exist here.
    • Added a db_table_exists stub to the bootstrap, required by includes/arrays.php.
    • Removed ArraysDefinitionTest.php's broken require of a non-existent tests/Helpers/GlobalStubs.php; the bootstrap now supplies those stubs automatically via Pest.
    • tests/Integration and tests/e2e remain standalone PHP CLI scripts and are intentionally excluded from the Pest testsuite.

TheWitness and others added 10 commits November 30, 2024 08:28
* add mqtt test

* formatting

* update

* add DOH

* update
Revert bulk array()->[] rewrite damage affecting:
- is_array, in_array, xml2array
- call_user_func_array, filter_var_array
- Function declarations with _array suffix

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ction declarations

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Copilot AI lite review requested due to automatic review settings September 12, 2026 23:33

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.

🟡 Changes recommended

The SQL quoting and notification mapping tests need correction, and CI coverage lacks a configured driver.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Modernizes the plugin for PHP 7.4, hardens proxy/CA SQL filters, and adds Pest testing with CI.

Changes:

  • Updates PHP syntax and query arguments for PHP 7.4 compatibility.
  • Escapes and groups administrative search filters.
  • Adds Pest scaffolding, regression checks, and GitHub Actions CI.
File summaries
File Summary Review note
tests/Unit/test_filter_sql_quoting.php Adds SQL quoting checks. Critical (3 votes): Assertion does not verify payload escaping.
tests/Unit/ArraysDefinitionTest.php Tests array definitions and notification behavior. Moderate (2 votes): Tests reimplement the mapping loop and do not exercise the populated branch.
tests/TestCase.php Adds the PHPUnit base fixture.
tests/Pest.php Adds Pest configuration.
tests/Integration/test_servcheck_filter_sql_wiring.php Checks SQL hardening wiring.
tests/e2e/test_servcheck_no_raw_filter_sql.php Detects raw filter SQL.
tests/bootstrap-unit.php Provides test bootstrap paths and stubs.
tests/.cacti-version Defines the expected Cacti version.
setup.php Modernizes setup syntax.
servcheck_test.php Modernizes request and query arrays.
servcheck_proxies.php Hardens proxy filtering and modernizes arrays.
servcheck_process.php Modernizes process query arguments.
servcheck_ca.php Hardens CA filtering and modernizes arrays.
poller_servcheck.php Modernizes poller query arguments.
phpunit.xml Configures the Pest test suite.
includes/tests.php Modernizes cURL and test arrays.
includes/mxlookup.php Modernizes lookup arrays.
includes/functions.php Modernizes graph and query arrays.
includes/arrays.php Modernizes definitions and notification arrays.
.gitignore Ignores .omc artifacts.
.github/workflows/plugin-ci-workflow.yml Adds CI installation and test execution. Critical (3 votes): Coverage commands lack an installed Xdebug or PCOV driver.
Review details

Suppressed comments (3)

.github/workflows/plugin-ci-workflow.yml:197

  • This workflow only invokes Pest for tests/Unit; the Integration and e2e scripts are explicitly excluded from that testsuite and are never run anywhere else. Consequently, the SQL-hardening checks in those new scripts cannot fail CI; add a direct PHP CLI step for the standalone checks or convert them to Pest tests.
    - name: Run Pest Unit Tests
      run: |
        cd ${{ github.workspace }}/cacti
        if [ -f plugins/servcheck/phpunit.xml ]; then
          include/vendor/bin/pest --configuration=plugins/servcheck/phpunit.xml \
            --coverage-clover=plugins/servcheck/coverage/clover.xml \
            plugins/servcheck/tests/Unit

.github/workflows/plugin-ci-workflow.yml:114

  • MYSQL_AUTH_USR is expanded by the shell into --defaults-file=~/.my.cnf; tilde expansion does not run recursively after parameter expansion, so the MySQL client will look for a literal ~/.my.cnf and then fail authentication. Use an absolute path (or pass --defaults-file="$HOME/.my.cnf" directly in each command).
        MYSQL_AUTH_USR: '--defaults-file=~/.my.cnf'

tests/Unit/test_filter_sql_quoting.php:15

  • tests/Unit is the configured Pest testsuite and the workflow passes that directory to Pest, so this standalone script is loaded during test discovery; exit(0) terminates the whole runner before Pest can execute or report ArraysDefinitionTest. This can produce a false-green run. Convert this file to a Pest spec or move it to a standalone directory and invoke it with PHP.
	exit(0);
  • Files reviewed: 20/21 changed files
  • Comments generated: 3
  • Review effort level: Lite

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

Comment thread .github/workflows/plugin-ci-workflow.yml
Comment thread tests/Unit/test_filter_sql_quoting.php Outdated
Comment thread tests/Unit/ArraysDefinitionTest.php Outdated
bmfmancini
bmfmancini previously approved these changes Sep 12, 2026
bmfmancini
bmfmancini previously approved these changes Sep 12, 2026
@TheWitness
TheWitness changed the base branch from develop to main September 12, 2026 23:51
@TheWitness
TheWitness dismissed bmfmancini’s stale review September 12, 2026 23:51

The base branch was changed.

@TheWitness

Copy link
Copy Markdown
Member Author

Closing — the develop/main divergence made this too messy to merge cleanly. Will revisit separately.

@TheWitness TheWitness closed this Sep 13, 2026
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.

5 participants