mirror of
https://github.com/Cacti/plugin_thold.git
synced 2026-10-30 00:26:54 +09:00
* chore: harmonize CI workflow, templates, and test structure
Part of the fleet-wide plugin_* harmonization effort.
- Pin actions/checkout, shivammathur/setup-php, actions/upload-artifact to
current release commit SHAs (was floating @v4/@v2).
- Stop logging the MySQL root password in CI output (cat ~/.my.cnf ->
chmod 600).
- Harden MySQL bootstrap: quoted --defaults-file, grants added for both
'cactiuser'@'localhost' and 'cactiuser'@'127.0.0.1'.
- Add "Restore vendor ownership for Pest" step after Composer install.
- Switch the PHP syntax-check step to the vendor-excluding, null-delimited
find/xargs pattern used in plugin_audit.
- Remove the unused "Configure Apache" step (apache2/libapache2-mod-php are
not installed and not needed).
- Simplify the Pest invocation to rely solely on phpunit.xml's <testsuites>.
- No CodeQL workflow added: this repo has no JavaScript/Python/Ruby content
(PHP only), so there is nothing for CodeQL to scan.
- Consolidate tests/Security/Php74CompatibilityTest.php into
tests/Security/PhpCompatibilityTest.php, now checking for PHP 8.3/8.4-only
syntax (this plugin's floor is PHP 8.2 per the CI matrix).
- Remove tests/TestCase.php and its require in tests/bootstrap-unit.php: not
referenced by any uses(TestCase::class) call in this plugin's tests.
- Add .github/ISSUE_TEMPLATE/{bug_report,feature_request}.md and
.github/PULL_REQUEST_TEMPLATE.md, styled after Cacti/cacti's own templates.
- Document CI/dependency baselines in copilot-instructions.md.
* chore: add i18n build/verify workflow and bump MariaDB floor to 11.8
- Document the locales/build_gettext.sh + cacti.pot workflow in
copilot-instructions.md (Weblate owns per-language .po/.mo sync).
- Add a CI step that regenerates cacti.pot and fails if it is stale,
ignoring the POT-Creation-Date timestamp.
- Mark locales/build_gettext.sh executable.
- Bump the CI MariaDB service image floor to 11.8 (from mariadb:10.6 /
mysql:8.0).
* fix: mariadb:11.8 healthcheck and i18n step permissions
- mariadb:11.8 no longer ships mysqladmin; use mariadb-admin for the
service container healthcheck.
- Run chmod/build_gettext.sh with sudo in the i18n verification step,
since locales/ is owned by www-data by the time it runs.
* chore: regenerate locales/po/cacti.pot with current source strings
Ran the real locales/build_gettext.sh (xgettext/msgmerge/msgfmt) to
refresh the translation template against current source. Per the i18n
workflow documented in copilot-instructions.md, only the regenerated
cacti.pot is committed here; Weblate owns syncing the per-language
.po/.mo files from it.
* fix: restore tests/TestCase.php, still used by classic PHPUnit-style tests
An earlier harmonization commit deleted tests/TestCase.php as
apparently-unused dead code, but ~28 test classes across
tests/Unit use classic 'extends TestCase' inheritance rather than
Pest's uses() helper, so the earlier usage check missed them. This
broke bootstrap for every Pest run with 'Class TestCase not found'.
* fix: satisfy php-cs-fixer short-array/single-quote rules in PhpCompatibilityTest
Matches the project's PSR coding standard (short array syntax, single
quotes for non-interpolated strings) that php-cs-fixer enforces in CI.
* fix: make locales/build_gettext.sh string extraction order deterministic
`find` without `sort` returns filesystem/readdir-order results, which
can differ between machines (e.g. a local regen vs. a GitHub Actions
runner), producing a spurious reordering diff in cacti.pot even when
no strings actually changed. Pipe through `sort` and regenerate
cacti.pot with the now-deterministic order.
* fix: correct TestCase.php encoding (was UTF-16, must be UTF-8)
The restored file was accidentally written as UTF-16LE (a Windows
PowerShell redirection default), so PHP never recognized the
opening <?php tag and the class was never defined, still leaving
'Class TestCase not found' even after the file's restoration.
* fix(ci): remove broken 'Import Thold Plugin Sample Data' step
This step invoked cli/cli_import.php, which does not exist anywhere
in Cacti core (the real script is cli/import_template.php, and even
that expects standard Cacti template XML, not this fixture's custom
thold_hi/thold_low/etc. row format). Nothing in the test suite
actually consumes this imported data, so remove the broken step
along with its non-functional script and fixture rather than build
an importer for a feature with no consumer.
* fix: Address Copilot review findings on the harmonization PR
- tests/Security/PhpCompatibilityTest.php: fixed the #[Override]/#[Deprecated]
attribute regexes to also match the fully qualified (`#[\Override]`,
`#[\Deprecated]`) form, added a realpath() false-guard for the plugin root,
included the relative file path in both RuntimeException messages, added
typed-class-constant and dynamic-class-constant-fetch checks (PHP 8.3), and
restored each()/create_function() removed-in-PHP-8.0 guards that the
consolidation had dropped. Also excludes include/vendor/ (not just vendor/)
from the recursive source scan.
- .github/workflows/plugin-ci-workflow.yml: the "Create MySQL Config" step's
root password is now masked via `::add-mask::` before it's echoed into
~/.my.cnf, so it no longer appears in plaintext in the Actions log (chmod
600 alone only protected the file after creation, not the command's own
echoed source in the log).
* fix: Address remaining Copilot review findings
- CHANGELOG.md: added an entry documenting the CI/template harmonization
change (was previously missing per review feedback).
- locales/po/cacti.pot (+ .po/.mo): regenerated via locales/build_gettext.sh
so the new "Verify translation template is up to date" CI check actually
passes against the current source tree instead of comparing against a
stale committed POT.
- locales/build_gettext.sh: added --from-code=UTF-8 to the xgettext
invocation - without it, xgettext aborts outright on any non-ASCII string
in the source (e.g. a "…" character), silently leaving the previous
cacti.pot in place and defeating the up-to-date check entirely.
- tests/Security/PhpCompatibilityTest.php: dropped the PHP 8.3-only checks
(kept only the PHP 8.4-only ones) and corrected the floor comment, since
this repo's actual CI matrix only runs PHP 8.3/8.4 (no 8.2) - it tracks
Cacti's `develop` branch, not `1.2.x`.
- tests/Security/PhpCompatibilityTest.php: renamed the local
plugin_test_read_source_file() helper to schema_test_read_source_file(),
matching this repo's own naming convention (schema_ prefix for non-
lifecycle helpers).
- tests/Helpers/ThresholdScenario.php: fixed a flush-left statement inside
inMaintenance() to use tab indentation, matching the surrounding code.
- README.md / tests/README.md / copilot-instructions.md: corrected stale
PHP-floor references (7.4/8.1 -> 8.2) and a stale test-filename reference
(Php82CompatibilityTest.php -> the consolidated PhpCompatibilityTest.php)
left over from the harmonization pass.
* fix(test): don't flag jQuery .each()/->each() as removed PHP each()
The each()-removed-in-PHP-8.0 check matched jQuery's $.each(/.each(
calls too, which have nothing to do with the removed PHP global
function. Exclude any each( preceded by . or > via a negative
lookbehind.
168 lines
6.9 KiB
PHP
168 lines
6.9 KiB
PHP
<?php
|
|
/*
|
|
+-------------------------------------------------------------------------+
|
|
| Copyright (C) 2004-2026 The Cacti Group |
|
|
| |
|
|
| This program is free software; you can redistribute it and/or |
|
|
| modify it under the terms of the GNU General Public License |
|
|
| as published by the Free Software Foundation; either version 2 |
|
|
| of the License, or (at your option) any later version. |
|
|
| |
|
|
| This program is distributed in the hope that it will be useful, |
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
| GNU General Public License for more details. |
|
|
+-------------------------------------------------------------------------+
|
|
| Cacti: The Complete RRDtool-based Graphing Solution |
|
|
+-------------------------------------------------------------------------+
|
|
| This code is designed, written, and maintained by the Cacti Group. See |
|
|
| about.php and/or the AUTHORS file for specific developer information. |
|
|
+-------------------------------------------------------------------------+
|
|
| http://www.cacti.net/ |
|
|
+-------------------------------------------------------------------------+
|
|
*/
|
|
|
|
/*
|
|
* Verify plugin source files do not use PHP 8.3+/8.4-only syntax.
|
|
* This plugin's floor version is PHP 8.2, matching the shared CI test
|
|
* matrix (php: ['8.2', '8.3', '8.4']).
|
|
*/
|
|
|
|
// Discovered recursively so new production PHP files are covered automatically.
|
|
$pluginRoot = realpath(__DIR__ . '/../..');
|
|
|
|
if ($pluginRoot === false) {
|
|
throw new RuntimeException('Unable to resolve the plugin root directory');
|
|
}
|
|
|
|
$files = [];
|
|
|
|
$iterator = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator($pluginRoot, FilesystemIterator::SKIP_DOTS)
|
|
);
|
|
|
|
foreach ($iterator as $file) {
|
|
if ($file->getExtension() !== 'php') {
|
|
continue;
|
|
}
|
|
|
|
$relativeFile = ltrim(str_replace($pluginRoot, '', $file->getPathname()), DIRECTORY_SEPARATOR);
|
|
$relativeFile = str_replace(DIRECTORY_SEPARATOR, '/', $relativeFile);
|
|
|
|
if (strpos($relativeFile, 'tests/') === 0 || strpos($relativeFile, 'vendor/') === 0 || strpos($relativeFile, 'include/vendor/') === 0) {
|
|
continue;
|
|
}
|
|
|
|
$files[] = $relativeFile;
|
|
}
|
|
|
|
sort($files);
|
|
|
|
function plugin_test_read_source_file($relativeFile) {
|
|
$path = realpath(__DIR__ . '/../../' . $relativeFile);
|
|
|
|
if ($path === false) {
|
|
throw new RuntimeException("Unable to resolve required plugin source: {$relativeFile}");
|
|
}
|
|
|
|
$contents = file_get_contents($path);
|
|
|
|
if ($contents === false) {
|
|
throw new RuntimeException("Unable to read required plugin source: {$relativeFile}");
|
|
}
|
|
|
|
return $contents;
|
|
}
|
|
|
|
it('does not use asymmetric visibility (PHP 8.4)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
expect(preg_match('/\bprivate\s*\(\s*set\s*\)|\bprotected\s*\(\s*set\s*\)/', $contents))->toBe(0,
|
|
"{$relativeFile} uses asymmetric visibility which requires PHP 8.4"
|
|
);
|
|
}
|
|
});
|
|
|
|
it('does not use the #[Override] attribute (PHP 8.3)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
expect(preg_match('/#\[\s*\\\\?Override\s*\]/i', $contents))->toBe(0,
|
|
"{$relativeFile} uses #[Override] which requires PHP 8.3"
|
|
);
|
|
}
|
|
});
|
|
|
|
it('does not use the #[Deprecated] attribute (PHP 8.4)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
expect(preg_match('/#\[\s*\\\\?Deprecated\b/i', $contents))->toBe(0,
|
|
"{$relativeFile} uses #[Deprecated] which requires PHP 8.4"
|
|
);
|
|
}
|
|
});
|
|
|
|
it('does not use json_validate() (PHP 8.3)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
expect(preg_match('/\bjson_validate\s*\(/', $contents))->toBe(0,
|
|
"{$relativeFile} uses json_validate() which requires PHP 8.3"
|
|
);
|
|
}
|
|
});
|
|
|
|
it('does not use array_find()/array_any()/array_all() (PHP 8.4)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
expect(preg_match('/\barray_(find|any|all)\s*\(/', $contents))->toBe(0,
|
|
"{$relativeFile} uses array_find()/array_any()/array_all() which requires PHP 8.4"
|
|
);
|
|
}
|
|
});
|
|
|
|
it('does not use typed class constants (PHP 8.3)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
expect(preg_match('/\bconst\s+(?:\?\s*)?[A-Za-z_\\\\][A-Za-z0-9_\\\\]*(?:\s*\|\s*(?:\?\s*)?[A-Za-z_\\\\][A-Za-z0-9_\\\\]*)*\s+[A-Za-z_][A-Za-z0-9_]*\s*=/', $contents))->toBe(0,
|
|
"{$relativeFile} uses a typed class constant which requires PHP 8.3"
|
|
);
|
|
}
|
|
});
|
|
|
|
it('does not use a dynamic class constant fetch (PHP 8.3)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
expect(preg_match('/::\s*\{\s*\$/', $contents))->toBe(0,
|
|
"{$relativeFile} uses a dynamic class constant fetch (Foo::" . '{$bar}' . ") which requires PHP 8.3"
|
|
);
|
|
}
|
|
});
|
|
|
|
it('does not use each() (removed in PHP 8.0)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
// (?<![.>]) excludes jQuery-style calls like $.each(/.each(/->each( - not the removed global each().
|
|
expect(preg_match('/(?<![.>])\beach\s*\(/', $contents))->toBe(0,
|
|
"{$relativeFile} uses each() which was removed in PHP 8.0"
|
|
);
|
|
}
|
|
});
|
|
|
|
it('does not use create_function() (removed in PHP 8.0)', function () use ($files) {
|
|
foreach ($files as $relativeFile) {
|
|
$contents = plugin_test_read_source_file($relativeFile);
|
|
|
|
expect(preg_match('/(?<![.>])\bcreate_function\s*\(/', $contents))->toBe(0,
|
|
"{$relativeFile} uses create_function() which was removed in PHP 8.0"
|
|
);
|
|
}
|
|
});
|
|
|