tests: Complete test coverage of HtmlArmor
[lhc/web/wiklou.git] / tests / phpunit / includes / site / DBSiteStoreTest.php
index 48ef524..32dd7f2 100644 (file)
  */
 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
         */
@@ -38,7 +47,7 @@ class DBSiteStoreTest extends MediaWikiTestCase {
                $expectedSites = TestSites::getSites();
                TestSites::insertIntoDb();
 
-               $store = new DBSiteStore();
+               $store = $this->newDBSiteStore();
 
                $sites = $store->getSites();
 
@@ -62,9 +71,9 @@ class DBSiteStoreTest extends MediaWikiTestCase {
         * @covers DBSiteStore::saveSites
         */
        public function testSaveSites() {
-               $store = new DBSiteStore();
+               $store = $this->newDBSiteStore();
 
-               $sites = array();
+               $sites = [];
 
                $site = new Site();
                $site->setGlobalId( 'ertrywuutr' );
@@ -95,8 +104,8 @@ class DBSiteStoreTest extends MediaWikiTestCase {
         * @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() );
@@ -121,7 +130,7 @@ class DBSiteStoreTest extends MediaWikiTestCase {
         * @covers DBSiteStore::clear
         */
        public function testClear() {
-               $store = new DBSiteStore();
+               $store = $this->newDBSiteStore();
                $this->assertTrue( $store->clear() );
 
                $site = $store->getSite( 'enwiki' );
@@ -135,23 +144,23 @@ class DBSiteStoreTest extends MediaWikiTestCase {
         * @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() );
        }
 }