Many integration tests involve database access. For example, they use:
- LBFactory::getDatabase()
- LoadBalancer::getConnection()
All of these methods involve a DBConnRef that properly handles the database domain (e.g. what $db->getDomainId() returns). However, MediaWikiIntegrationTestCase has a member field called "db", which was provided for easy access to a database handles. The problem is that it was created before DBConnRef and just directly points to a Database object (instead of a DBConnRef wrapper). This makes usage of MediaWikiIntegrationTestCase::db idiosyncratic and subject to unexpected database domain changes due to other code getting a connection to a domain that is not the current one.
The field is currently defined using an LB method that is supposed to be internal:
$this->db = $lb->getConnectionInternal( DB_PRIMARY );
This fix for this is to:
- Fix uses of $this->db that block https://gerrit.wikimedia.org/r/c/mediawiki/core/+/519305
- Remove use of $this->db from subclasses of MediaWikiIntegrationTestCase that override the field (e.g. $this->db = ... in setUp()) but can just use MediaWikiIntegrationTestCase::getDB() in each test function. For example, DatabaseIntegrationTest currently has $this->db = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase().
- Remove use of $this->db from subclasses of MediaWikiIntegrationTestCase that rely on the parent class to set the field. They can use MediaWikiIntegrationTestCase::getDB() in each test method instead.
When grepping, note that many classes do harmless things like $this->db = new DatabaseTestHelper(...) and are not subclasses of MediaWikiIntegrationTestCase.
Code search: https://codesearch.wmcloud.org/search/?q=-%3Edb-%3E&files=Test%5C.php%24&excludeFiles=&repos=