Thiemo Mättig (WMDE) has uploaded a new change for review.

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

Change subject: Clean up ItemsPerSiteBuilderTest
......................................................................

Clean up ItemsPerSiteBuilderTest

I may be wrong but I don't think it's a good idea to make this Item
static.

Also the getter seems unnecesarry. Simplified to a const.

Change-Id: I147c709c2b6ff64b3a6a5898bff13fc30e4cc6b3
---
M repo/tests/phpunit/includes/store/sql/ItemsPerSiteBuilderTest.php
1 file changed, 24 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/95/177195/1

diff --git a/repo/tests/phpunit/includes/store/sql/ItemsPerSiteBuilderTest.php 
b/repo/tests/phpunit/includes/store/sql/ItemsPerSiteBuilderTest.php
index d04b516..9c953d7 100644
--- a/repo/tests/phpunit/includes/store/sql/ItemsPerSiteBuilderTest.php
+++ b/repo/tests/phpunit/includes/store/sql/ItemsPerSiteBuilderTest.php
@@ -21,12 +21,8 @@
  * @author Marius Hoch < h...@online.de >
  */
 class ItemsPerSiteBuilderTest extends \MediaWikiTestCase {
-       /**
-        * @return int
-        */
-       private function getBatchSize() {
-               return 5;
-       }
+
+       const BATCH_SIZE = 5;
 
        /**
         * @return ItemId
@@ -39,48 +35,43 @@
         * @return Item
         */
        private function getTestItem() {
-               static $item = null;
-
-               if ( !$item  ) {
-                       $item = Item::newEmpty();
-                       $item->setId( $this->getTestItemId() );
-               }
-
+               $item = Item::newEmpty();
+               $item->setId( $this->getTestItemId() );
                return $item;
        }
 
        /**
         * @return SiteLinkTable
         */
-       private function getSiteLinkTableMock() {
-               $siteLinkTableMock = $this->getMockBuilder( 
'Wikibase\Lib\Store\SiteLinkTable' )
+       private function getSiteLinkTable() {
+               $mock = $this->getMockBuilder( 
'Wikibase\Lib\Store\SiteLinkTable' )
                        ->disableOriginalConstructor()
                        ->getMock();
 
                $item = $this->getTestItem();
-               $siteLinkTableMock->expects( $this->exactly( 10 ) )
+               $mock->expects( $this->exactly( 10 ) )
                        ->method( 'saveLinksOfItem' )
                        ->will( $this->returnValue( true ) )
                        ->with( $this->equalTo( $item ) );
 
-               return $siteLinkTableMock;
+               return $mock;
        }
 
        /**
         * @return EntityLookup
         */
-       private function getEntityLookupMock() {
-               $entityLookupMock = $this->getMockBuilder( 
'Wikibase\Lib\Store\EntityLookup' )
+       private function getEntityLookup() {
+               $mock = $this->getMockBuilder( 
'Wikibase\Lib\Store\EntityLookup' )
                        ->disableOriginalConstructor()
                        ->getMock();
 
                $item = $this->getTestItem();
-               $entityLookupMock->expects( $this->exactly( 10 ) )
+               $mock->expects( $this->exactly( 10 ) )
                        ->method( 'getEntity' )
                        ->will( $this->returnValue( $item ) )
                        ->with( $this->equalTo( $this->getTestItemId() ) );
 
-               return $entityLookupMock;
+               return $mock;
        }
 
        /**
@@ -88,8 +79,8 @@
         */
        private function getItemsPerSiteBuilder() {
                return new ItemsPerSiteBuilder(
-                       $this->getSiteLinkTableMock(),
-                       $this->getEntityLookupMock()
+                       $this->getSiteLinkTable(),
+                       $this->getEntityLookup()
                );
        }
 
@@ -97,7 +88,7 @@
         * @return EntityIdPager
         */
        private function getEntityIdPager() {
-               $entityIdPager = $this->getMock( 
'Wikibase\Repo\Store\EntityIdPager' );
+               $mock = $this->getMock( 'Wikibase\Repo\Store\EntityIdPager' );
 
                $itemIds = array(
                        $this->getTestItemId(),
@@ -107,27 +98,27 @@
                        $this->getTestItemId()
                );
 
-               $entityIdPager->expects( $this->at( 0 ) )
+               $mock->expects( $this->at( 0 ) )
                        ->method( 'fetchIds' )
                        ->will( $this->returnValue( $itemIds ) )
-                       ->with( $this->equalTo( $this->getBatchSize() ) );
+                       ->with( $this->equalTo( self::BATCH_SIZE ) );
 
-               $entityIdPager->expects( $this->at( 1 ) )
+               $mock->expects( $this->at( 1 ) )
                        ->method( 'fetchIds' )
                        ->will( $this->returnValue( $itemIds ) )
-                       ->with( $this->equalTo( $this->getBatchSize() ) );
+                       ->with( $this->equalTo( self::BATCH_SIZE ) );
 
-               $entityIdPager->expects( $this->at( 2 ) )
+               $mock->expects( $this->at( 2 ) )
                        ->method( 'fetchIds' )
                        ->will( $this->returnValue( array() ) )
-                       ->with( $this->equalTo( $this->getBatchSize() ) );
+                       ->with( $this->equalTo( self::BATCH_SIZE ) );
 
-               return $entityIdPager;
+               return $mock;
        }
 
        public function testRebuild() {
                $itemsPerSiteBuilder = $this->getItemsPerSiteBuilder();
-               $itemsPerSiteBuilder->setBatchSize( $this->getBatchSize() );
+               $itemsPerSiteBuilder->setBatchSize( self::BATCH_SIZE );
 
                $entityIdPager = $this->getEntityIdPager();
                $itemsPerSiteBuilder->rebuild( $entityIdPager );
@@ -136,4 +127,5 @@
                // so no need for assertions
                $this->assertTrue( true );
        }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/177195
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I147c709c2b6ff64b3a6a5898bff13fc30e4cc6b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to