Repository navigation
Conversation
…guard Database-backed tests reached the configured application database, so running the unit suite on a configured board could write into it. Add TestDatabase (connects only to binktermphp_test and verifies it) and Database::setInstanceForTesting()/resetInstanceForTesting(), which independently refuse any connection that is not binktermphp_test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
TITLE: Tests: isolated binktermphp_test database harness with a fail-closed guard
Problem
Database-backed unit tests reach the database through
Database::getInstance()or the application's.envDB_NAME, which is the configured application database. For example,UserManagerCreateTestdrivesscripts/user-manager.phpagainstDB_NAME. There is no isolated test database and nothing stops a test run from writing to a live board's database.Impact
Running the unit suite on a machine with a configured board risks writing fixtures into production data. Contributors cannot safely add tests for database-backed behavior.
Repair
tests/Unit/Support/TestDatabase.php: the shared way to get a PDO for the isolatedbinktermphp_testdatabase. It usesDB_HOST/DB_PORT/DB_USER/DB_PASS, never readsDB_NAME, never callsDatabase::getInstance(), and verifiescurrent_database()before returning the connection.Database::setInstanceForTesting(PDO $pdo): routes everyDatabase::getInstance()call, including those inside production code under test, to that connection. It checkscurrent_database()itself, independently of the helper, and refuses anything except exactlybinktermphp_test, leaving the existing singleton untouched.Database::resetInstanceForTesting()drops the singleton.Proof
tests/Unit/DatabaseTestIsolationTest.php, with no database server (PDO stubs):binktermphp,postgres,binktermphp_test_copyor an empty name are refused, and the singleton is unchanged;binktermphp_testconnection is installed and session-initialized (SET TIME ZONE 'UTC');It errors on the current branch and passes with the change.
tests/Unit/TestDatabaseConnectionTest.phpis the end-to-end check against a realbinktermphp_testdatabase. It skips when pdo_pgsql or the database is unavailable. (Proof against a real PostgreSQL instance is recorded separately.)The rest of
tests/Unitis unchanged.