[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Replace SiteLookup mocks with HashSiteStore

2017-01-03 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/330201 )

Change subject: Replace SiteLookup mocks with HashSiteStore
..


Replace SiteLookup mocks with HashSiteStore

In some cases it does not make that much of a difference, but in some
cases this greatly reduces the complexity of the code, making it much
easier to read.

Change-Id: If5580a400451d1bb714be9a760b5c7e87df67567
---
M repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
M repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
M repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
M repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
M repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnDeleteJobTest.php
M repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnMoveJobTest.php
6 files changed, 29 insertions(+), 68 deletions(-)

Approvals:
  Aude: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php 
b/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
index 7a9da5d..e01ef84 100644
--- a/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
+++ b/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
@@ -3,7 +3,9 @@
 namespace Wikibase\Repo\Tests\Api;
 
 use ApiBase;
+use HashSiteStore;
 use MediaWikiSite;
+use Site;
 use SiteLookup;
 use Title;
 use ApiUsageException;
@@ -38,17 +40,13 @@
 * @return SiteLookup
 */
public function getSiteLookupMock() {
-   $dummySite = new MediaWikiSite();
+   $site = $this->getMock( Site::class );
 
-   $siteLookupMock = $this->getMockBuilder( SiteLookup::class )
-   ->disableOriginalConstructor()
-   ->getMock();
+   $site->expects( $this->any() )
+   ->method( 'getGlobalId' )
+   ->will( $this->returnValue( 'FooSite' ) );
 
-   $siteLookupMock->expects( $this->any() )
-   ->method( 'getSite' )
-   ->will( $this->returnValue( $dummySite ) );
-
-   return $siteLookupMock;
+   return new HashSiteStore( [ $site ] );
}
 
/**
diff --git 
a/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php 
b/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
index 39119b8..0372014 100644
--- a/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
+++ b/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
@@ -4,6 +4,7 @@
 
 use DataValues\DataValue;
 use DataValues\DecimalValue;
+use HashSiteStore;
 use Language;
 use PHPUnit_Framework_TestCase;
 use Site;
@@ -104,14 +105,7 @@
$acme->setGlobalId( 'acme' );
$acme->setLinkPath( "http://acme.com/$1; );
 
-   $mock = $this->getMock( SiteLookup::class );
-   $mock->expects( $this->any() )
-   ->method( 'getSite' )
-   ->will( $this->returnValueMap( [
-   [ 'acme', $acme ],
-   ] ) );
-
-   return $mock;
+   return new HashSiteStore( [ $acme ] );
}
 
 }
diff --git a/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
index d5b3ddb..518000f 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Repo\Tests\Specials;
 
 use FauxResponse;
+use HashSiteStore;
 use InvalidArgumentException;
 use Site;
 use SiteLookup;
@@ -53,22 +54,11 @@
 * @return SiteLookup
 */
private function getMockSiteLookup() {
-   $mock = $this->getMock( SiteLookup::class );
-   $mock->expects( $this->any() )
-   ->method( 'getSite' )
-   ->will( $this->returnCallback( function( $siteId ) {
-   if ( substr( $siteId, -4 ) !== 'wiki' ) {
-   return null;
-   }
+   $dewiki = new Site();
+   $dewiki->setGlobalId( 'dewiki' );
+   $dewiki->setLinkPath( 'http://dewiki.com/$1' );
 
-   $site = new Site();
-   $site->setGlobalId( $siteId );
-   $site->setLinkPath( 'http://'.$siteId.'.com/$1' 
);
-
-   return $site;
-   } ) );
-
-   return $mock;
+   return new HashSiteStore( [ $dewiki ] );
}
 
/**
diff --git a/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php 

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Replace SiteLookup mocks with HashSiteStore

2017-01-03 Thread WMDE
Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/330201 )

Change subject: Replace SiteLookup mocks with HashSiteStore
..

Replace SiteLookup mocks with HashSiteStore

In some cases it does not make that much of a difference, but in some
cases this greatly reduces the complexity of the code, making it much
easier to read.

Change-Id: If5580a400451d1bb714be9a760b5c7e87df67567
---
M repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
M repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
M repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
M repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
M repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnDeleteJobTest.php
M repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnMoveJobTest.php
6 files changed, 29 insertions(+), 68 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php 
b/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
index 7a9da5d..e01ef84 100644
--- a/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
+++ b/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
@@ -3,7 +3,9 @@
 namespace Wikibase\Repo\Tests\Api;
 
 use ApiBase;
+use HashSiteStore;
 use MediaWikiSite;
+use Site;
 use SiteLookup;
 use Title;
 use ApiUsageException;
@@ -38,17 +40,13 @@
 * @return SiteLookup
 */
public function getSiteLookupMock() {
-   $dummySite = new MediaWikiSite();
+   $site = $this->getMock( Site::class );
 
-   $siteLookupMock = $this->getMockBuilder( SiteLookup::class )
-   ->disableOriginalConstructor()
-   ->getMock();
+   $site->expects( $this->any() )
+   ->method( 'getGlobalId' )
+   ->will( $this->returnValue( 'FooSite' ) );
 
-   $siteLookupMock->expects( $this->any() )
-   ->method( 'getSite' )
-   ->will( $this->returnValue( $dummySite ) );
-
-   return $siteLookupMock;
+   return new HashSiteStore( [ $site ] );
}
 
/**
diff --git 
a/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php 
b/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
index 39119b8..0372014 100644
--- a/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
+++ b/repo/tests/phpunit/includes/Localizer/MessageParameterFormatterTest.php
@@ -4,6 +4,7 @@
 
 use DataValues\DataValue;
 use DataValues\DecimalValue;
+use HashSiteStore;
 use Language;
 use PHPUnit_Framework_TestCase;
 use Site;
@@ -104,14 +105,7 @@
$acme->setGlobalId( 'acme' );
$acme->setLinkPath( "http://acme.com/$1; );
 
-   $mock = $this->getMock( SiteLookup::class );
-   $mock->expects( $this->any() )
-   ->method( 'getSite' )
-   ->will( $this->returnValueMap( [
-   [ 'acme', $acme ],
-   ] ) );
-
-   return $mock;
+   return new HashSiteStore( [ $acme ] );
}
 
 }
diff --git a/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
index d5b3ddb..518000f 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Repo\Tests\Specials;
 
 use FauxResponse;
+use HashSiteStore;
 use InvalidArgumentException;
 use Site;
 use SiteLookup;
@@ -53,22 +54,11 @@
 * @return SiteLookup
 */
private function getMockSiteLookup() {
-   $mock = $this->getMock( SiteLookup::class );
-   $mock->expects( $this->any() )
-   ->method( 'getSite' )
-   ->will( $this->returnCallback( function( $siteId ) {
-   if ( substr( $siteId, -4 ) !== 'wiki' ) {
-   return null;
-   }
+   $dewiki = new Site();
+   $dewiki->setGlobalId( 'dewiki' );
+   $dewiki->setLinkPath( 'http://dewiki.com/$1' );
 
-   $site = new Site();
-   $site->setGlobalId( $siteId );
-   $site->setLinkPath( 'http://'.$siteId.'.com/$1' 
);
-
-   return $site;
-   } ) );
-
-   return $mock;
+   return new HashSiteStore( [ $dewiki ] );
}
 
/**
diff --git a/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php