Page MenuHomePhabricator

Add convenience methods to create RepoDomainDb/ClientDomainDb from IDatabase
Closed, ResolvedPublic

Description

We have code like this in lots of tests now:

new RepoDomainDb( LBFactorySingle::newFromConnection( $this->db ), $this->db->getDomainID() )

It would be nice to extract it into a convenience method somewhere. I’m not sure where that method should live, though… would RepoDomainDb::newFromConnection() make sense?

Event Timeline

I’m also tempted to say the method should throw if it’s called outside of tests (i.e. when !defined( 'MW_PHPUNIT_TEST' )), but I’m not sure.

Change 700489 had a related patch set uploaded (by Tobias Andersson; author: Tobias Andersson):

[mediawiki/extensions/Wikibase@master] Add RepoDomainDB test convenience method

https://gerrit.wikimedia.org/r/700489

Change 700490 had a related patch set uploaded (by Tobias Andersson; author: Tobias Andersson):

[mediawiki/extensions/Wikibase@master] Use new RepoDomainDB convenience method

https://gerrit.wikimedia.org/r/700490

I didn't see the need for a ClientDomainDB version of this but maybe I'm wrong.

Change 700489 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Add RepoDomainDB test convenience method

https://gerrit.wikimedia.org/r/700489

Change 700490 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Use new RepoDomainDB convenience method

https://gerrit.wikimedia.org/r/700490

Ladsgroup subscribed.

Some not done yet:

amsa@amsa-Latitude-7480:~/Wikibase$ grep -ri LBFactorySingle
lib/tests/phpunit/Rdbms/LocalRepoDbTestHelper.php:use Wikimedia\Rdbms\LBFactorySingle;
lib/tests/phpunit/Rdbms/LocalRepoDbTestHelper.php:		$lbFactory = LBFactorySingle::newFromConnection( $db );
lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php:use Wikimedia\Rdbms\LBFactorySingle;
lib/tests/phpunit/Store/Sql/SiteLinkTableTest.php:				LBFactorySingle::newFromConnection( $this->db ),
lib/includes/Rdbms/RepoDomainDb.php:use Wikimedia\Rdbms\LBFactorySingle;
lib/includes/Rdbms/RepoDomainDb.php:		$lbFactory = LBFactorySingle::newFromConnection( $db );
client/tests/phpunit/integration/includes/Store/Sql/DirectSqlStoreTest.php:use Wikimedia\Rdbms\LBFactorySingle;
client/tests/phpunit/integration/includes/Store/Sql/DirectSqlStoreTest.php:	LBFactorySingle::newFromConnection( $this->db ),
client/tests/phpunit/integration/includes/Usage/Sql/EntityUsageTableBuilderTest.php:use Wikimedia\Rdbms\LBFactorySingle;
client/tests/phpunit/integration/includes/Usage/Sql/EntityUsageTableBuilderTest.php:			LBFactorySingle::newFromConnection( $this->db ),

LocalRepoDbTestHelper is interesting because it looks like @Jakob_WMDE already did this task but for the factory. Wish i had noticed this before, now we have two ways of doing this in the test.

Change 700833 had a related patch set uploaded (by Tobias Andersson; author: Tobias Andersson):

[mediawiki/extensions/Wikibase@master] Use existing RepoDomainDb helper trait

https://gerrit.wikimedia.org/r/700833

Change 700833 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Use existing RepoDomainDb helper trait

https://gerrit.wikimedia.org/r/700833