*/
class DBSiteStoreTest extends MediaWikiTestCase {
+ /**
+ * @return DBSiteStore
+ */
+ private function newDBSiteStore() {
+ // NOTE: Use the real DB load balancer for now. Eventually, the test framework should
+ // provide a LoadBalancer that is safe to use in unit tests.
+ return new DBSiteStore( wfGetLB() );
+ }
+
/**
* @covers DBSiteStore::getSites
*/
$expectedSites = TestSites::getSites();
TestSites::insertIntoDb();
- $store = new DBSiteStore();
+ $store = $this->newDBSiteStore();
$sites = $store->getSites();
* @covers DBSiteStore::saveSites
*/
public function testSaveSites() {
- $store = new DBSiteStore();
+ $store = $this->newDBSiteStore();
- $sites = array();
+ $sites = [];
$site = new Site();
$site->setGlobalId( 'ertrywuutr' );
$site = $store->getSite( 'ertrywuutr' );
$this->assertInstanceOf( 'Site', $site );
$this->assertEquals( 'en', $site->getLanguageCode() );
- $this->assertTrue( is_integer( $site->getInternalId() ) );
+ $this->assertTrue( is_int( $site->getInternalId() ) );
$this->assertTrue( $site->getInternalId() >= 0 );
$site = $store->getSite( 'sdfhxujgkfpth' );
$this->assertInstanceOf( 'Site', $site );
$this->assertEquals( 'nl', $site->getLanguageCode() );
- $this->assertTrue( is_integer( $site->getInternalId() ) );
+ $this->assertTrue( is_int( $site->getInternalId() ) );
$this->assertTrue( $site->getInternalId() >= 0 );
}
* @covers DBSiteStore::reset
*/
public function testReset() {
- $store1 = new DBSiteStore();
- $store2 = new DBSiteStore();
+ $store1 = $this->newDBSiteStore();
+ $store2 = $this->newDBSiteStore();
// initialize internal cache
$this->assertGreaterThan( 0, $store1->getSites()->count() );
* @covers DBSiteStore::clear
*/
public function testClear() {
- $store = new DBSiteStore();
+ $store = $this->newDBSiteStore();
$this->assertTrue( $store->clear() );
$site = $store->getSite( 'enwiki' );
* @covers DBSiteStore::getSites
*/
public function testGetSitesDefaultOrder() {
- $store = new DBSiteStore();
+ $store = $this->newDBSiteStore();
$siteB = new Site();
$siteB->setGlobalId( 'B' );
$siteA = new Site();
$siteA->setGlobalId( 'A' );
- $store->saveSites( array( $siteB, $siteA ) );
+ $store->saveSites( [ $siteB, $siteA ] );
$sites = $store->getSites();
- $siteIdentifiers = array();
+ $siteIdentifiers = [];
/** @var Site $site */
foreach ( $sites as $site ) {
$siteIdentifiers[] = $site->getGlobalId();
}
- $this->assertSame( array( 'A', 'B' ), $siteIdentifiers );
+ $this->assertSame( [ 'A', 'B' ], $siteIdentifiers );
// Note: SiteList::getGlobalIdentifiers uses an other internal state. Iteration must be
// tested separately.
- $this->assertSame( array( 'A', 'B' ), $sites->getGlobalIdentifiers() );
+ $this->assertSame( [ 'A', 'B' ], $sites->getGlobalIdentifiers() );
}
}