test: add database layer unit tests via SQLite + MySQL-shaped PDO decorator#7127
Merged
Merged
Conversation
…orator Introduces FakeMySQLPDO, a PDO decorator over an in-memory SQLite handle that surfaces just enough MySQL-shaped behaviour (information_schema-style column reads, prepared statement execute counters, configurable failure injection) to drive the existing db_* helpers in tests without a live MariaDB. Adds five test files covering string sanitisers, prepared execution, replace/save semantics, schema introspection, and connection retry behaviour. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds new unit tests around Cacti’s lib/database.php helpers, aiming to run them without a live MariaDB by using an in-memory SQLite connection and a small MySQL-syntax translation layer.
Changes:
- Added
FakeMySQLPDO(SQLite-backed) to translate a subset of MySQL-specific SQL (e.g.,SHOW TABLES,SHOW COLUMNS,ON DUPLICATE KEY UPDATE) for DB unit tests. - Added new unit tests for string quoting/formatting helpers, schema introspection helpers, prepared execution helpers,
sql_save/db_replacebehavior, and connection retry behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/DbStringFunctionsTest.php | Adds unit coverage for array_to_sql_or, db_qstr, db_strip_control_chars, db_format_index_create. |
| tests/Unit/DbSchemaIntrospectionTest.php | Adds unit coverage for db_table_exists / db_column_exists using the SQLite-backed decorator. |
| tests/Unit/DbReplaceSqlSaveTest.php | Adds unit coverage for sql_save and db_replace using the decorator to emulate MySQL syntax. |
| tests/Unit/DbExecutePreparedTest.php | Adds unit coverage for db_execute, db_execute_prepared, fetch helpers, affected rows, and insert id against SQLite. |
| tests/Unit/DbConnectRetryTest.php | Adds a retry/failure-path test for db_connect_real() against an unreachable endpoint. |
| tests/Helpers/FakeMySQLPDO.php | Introduces a test-only PDO subclass translating specific MySQL SQL patterns into SQLite-compatible queries. |
Same as PR-A: appends 11 PHPStan ignoreErrors entries that exist on upstream develop but are not yet baselined, so this branch's CI does not regress on phpstan analyse --level 6. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Contributor
Author
Contributor
Author
TheWitness
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on PR-A (#7124).
Adds
FakeMySQLPDO, a PDO decorator over an in-memory SQLitehandle that surfaces enough MySQL-shaped behaviour to drive the
existing
db_*helpers without a live MariaDB. Drivers can askfor information_schema-style column reads, query/prepare counters,
and configurable failure injection for retry tests.
Test files added:
No production code is touched.