[MediaWiki-commits] [Gerrit] Reduce inheritance in EntityContentTest - change (mediawiki...Wikibase)

2014-11-18 Thread WMDE
Thiemo Mättig (WMDE) has uploaded a new change for review.

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

Change subject: Reduce inheritance in EntityContentTest
..

Reduce inheritance in EntityContentTest

Especially the redirect stuff is only needed in ItemContentTest.

Change-Id: If76715ff5275c7ecb381413dd4f073aef0603b4e
---
M repo/includes/content/ItemContent.php
M repo/tests/phpunit/includes/content/EntityContentTest.php
M repo/tests/phpunit/includes/content/ItemContentTest.php
M repo/tests/phpunit/includes/content/PropertyContentTest.php
4 files changed, 58 insertions(+), 72 deletions(-)


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

diff --git a/repo/includes/content/ItemContent.php 
b/repo/includes/content/ItemContent.php
index 46cd222..4f59b97 100644
--- a/repo/includes/content/ItemContent.php
+++ b/repo/includes/content/ItemContent.php
@@ -3,15 +3,12 @@
 namespace Wikibase;
 
 use InvalidArgumentException;
-use Language;
 use LogicException;
 use MWException;
 use Title;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\Lib\Store\EntityRedirect;
 use Wikibase\Repo\ItemSearchTextGenerator;
-use Wikibase\Repo\View\ClaimsView;
-use Wikibase\Repo\View\FingerprintView;
 
 /**
  * Content object for articles representing Wikibase items.
diff --git a/repo/tests/phpunit/includes/content/EntityContentTest.php 
b/repo/tests/phpunit/includes/content/EntityContentTest.php
index 7028b28..e7b8b6c 100644
--- a/repo/tests/phpunit/includes/content/EntityContentTest.php
+++ b/repo/tests/phpunit/includes/content/EntityContentTest.php
@@ -69,45 +69,16 @@
}
 
/**
-* @return string
-*/
-   protected abstract function getContentClass();
-
-   /**
 * @return EntityId
 */
protected abstract function getDummyId();
 
/**
-* @param EntityId $id
+* @param EntityId $entityId
 *
 * @return EntityContent
 */
-   protected function newEmpty( EntityId $id = null ) {
-   $class = $this-getContentClass();
-   $empty = $class::newEmpty();
-
-   if ( $id ) {
-   $empty-getEntity()-setId( $id );
-   }
-
-   return $empty;
-   }
-
-   /**
-* @param EntityId $id
-* @param EntityId $target
-*
-* @return EntityContent
-*/
-   protected function newRedirect( EntityId $id, EntityId $target ) {
-   //FIXME: use the respective EntityHandler instead of going via 
the global title lookup!
-   $titleLookup = 
WikibaseRepo::getDefaultInstance()-getEntityTitleLookup();
-   $title = $titleLookup-getTitleForId( $target );
-
-   $class = $this-getContentClass();
-   return $class::newFromRedirect( new EntityRedirect( $id, 
$target ), $title );
-   }
+   protected abstract function newEmpty( EntityId $entityId = null );
 
/**
 * @dataProvider getTextForSearchIndexProvider
diff --git a/repo/tests/phpunit/includes/content/ItemContentTest.php 
b/repo/tests/phpunit/includes/content/ItemContentTest.php
index 7437fc1..c541520 100644
--- a/repo/tests/phpunit/includes/content/ItemContentTest.php
+++ b/repo/tests/phpunit/includes/content/ItemContentTest.php
@@ -8,7 +8,6 @@
 use Diff\DiffOp\DiffOpRemove;
 use Title;
 use Wikibase\DataModel\Claim\Claim;
-use Wikibase\DataModel\Claim\Claims;
 use Wikibase\DataModel\Entity\Diff\EntityDiff;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\ItemId;
@@ -21,6 +20,7 @@
 use Wikibase\ItemContent;
 use Wikibase\Lib\Store\EntityRedirect;
 use Wikibase\Repo\Content\EntityContentDiff;
+use Wikibase\Repo\WikibaseRepo;
 
 /**
  * @covers Wikibase\ItemContent
@@ -45,17 +45,39 @@
}
 
/**
-* @see EntityContentTest::getContentClass
-*/
-   protected function getContentClass() {
-   return '\Wikibase\ItemContent';
-   }
-
-   /**
-* @return EntityId
+* @return ItemId
 */
protected function getDummyId() {
return new ItemId( 'Q100' );
+   }
+
+   /**
+* @param EntityId $itemId
+*
+* @return ItemContent
+*/
+   protected function newEmpty( EntityId $itemId = null ) {
+   $empty = ItemContent::newEmpty();
+
+   if ( $itemId !== null ) {
+   $empty-getItem()-setId( $itemId );
+   }
+
+   return $empty;
+   }
+
+   /**
+* @param ItemId $itemId
+* @param ItemId $targetId
+*
+* @return ItemContent
+*/
+   private function newRedirect( ItemId $itemId, ItemId $targetId ) {
+   // FIXME: Use the respective EntityHandler instead of going via 
the global title lookup!
+   $titleLookup = 

[MediaWiki-commits] [Gerrit] Reduce inheritance in EntityContentTest - change (mediawiki...Wikibase)

2014-11-18 Thread Jeroen De Dauw (Code Review)
Jeroen De Dauw has submitted this change and it was merged.

Change subject: Reduce inheritance in EntityContentTest
..


Reduce inheritance in EntityContentTest

Especially the redirect stuff is only needed in ItemContentTest.

Change-Id: If76715ff5275c7ecb381413dd4f073aef0603b4e
---
M repo/includes/content/ItemContent.php
M repo/tests/phpunit/includes/content/EntityContentTest.php
M repo/tests/phpunit/includes/content/ItemContentTest.php
M repo/tests/phpunit/includes/content/PropertyContentTest.php
4 files changed, 58 insertions(+), 72 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved



diff --git a/repo/includes/content/ItemContent.php 
b/repo/includes/content/ItemContent.php
index 46cd222..4f59b97 100644
--- a/repo/includes/content/ItemContent.php
+++ b/repo/includes/content/ItemContent.php
@@ -3,15 +3,12 @@
 namespace Wikibase;
 
 use InvalidArgumentException;
-use Language;
 use LogicException;
 use MWException;
 use Title;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\Lib\Store\EntityRedirect;
 use Wikibase\Repo\ItemSearchTextGenerator;
-use Wikibase\Repo\View\ClaimsView;
-use Wikibase\Repo\View\FingerprintView;
 
 /**
  * Content object for articles representing Wikibase items.
diff --git a/repo/tests/phpunit/includes/content/EntityContentTest.php 
b/repo/tests/phpunit/includes/content/EntityContentTest.php
index 7028b28..e7b8b6c 100644
--- a/repo/tests/phpunit/includes/content/EntityContentTest.php
+++ b/repo/tests/phpunit/includes/content/EntityContentTest.php
@@ -69,45 +69,16 @@
}
 
/**
-* @return string
-*/
-   protected abstract function getContentClass();
-
-   /**
 * @return EntityId
 */
protected abstract function getDummyId();
 
/**
-* @param EntityId $id
+* @param EntityId $entityId
 *
 * @return EntityContent
 */
-   protected function newEmpty( EntityId $id = null ) {
-   $class = $this-getContentClass();
-   $empty = $class::newEmpty();
-
-   if ( $id ) {
-   $empty-getEntity()-setId( $id );
-   }
-
-   return $empty;
-   }
-
-   /**
-* @param EntityId $id
-* @param EntityId $target
-*
-* @return EntityContent
-*/
-   protected function newRedirect( EntityId $id, EntityId $target ) {
-   //FIXME: use the respective EntityHandler instead of going via 
the global title lookup!
-   $titleLookup = 
WikibaseRepo::getDefaultInstance()-getEntityTitleLookup();
-   $title = $titleLookup-getTitleForId( $target );
-
-   $class = $this-getContentClass();
-   return $class::newFromRedirect( new EntityRedirect( $id, 
$target ), $title );
-   }
+   protected abstract function newEmpty( EntityId $entityId = null );
 
/**
 * @dataProvider getTextForSearchIndexProvider
diff --git a/repo/tests/phpunit/includes/content/ItemContentTest.php 
b/repo/tests/phpunit/includes/content/ItemContentTest.php
index 7437fc1..c541520 100644
--- a/repo/tests/phpunit/includes/content/ItemContentTest.php
+++ b/repo/tests/phpunit/includes/content/ItemContentTest.php
@@ -8,7 +8,6 @@
 use Diff\DiffOp\DiffOpRemove;
 use Title;
 use Wikibase\DataModel\Claim\Claim;
-use Wikibase\DataModel\Claim\Claims;
 use Wikibase\DataModel\Entity\Diff\EntityDiff;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\ItemId;
@@ -21,6 +20,7 @@
 use Wikibase\ItemContent;
 use Wikibase\Lib\Store\EntityRedirect;
 use Wikibase\Repo\Content\EntityContentDiff;
+use Wikibase\Repo\WikibaseRepo;
 
 /**
  * @covers Wikibase\ItemContent
@@ -45,17 +45,39 @@
}
 
/**
-* @see EntityContentTest::getContentClass
-*/
-   protected function getContentClass() {
-   return '\Wikibase\ItemContent';
-   }
-
-   /**
-* @return EntityId
+* @return ItemId
 */
protected function getDummyId() {
return new ItemId( 'Q100' );
+   }
+
+   /**
+* @param EntityId $itemId
+*
+* @return ItemContent
+*/
+   protected function newEmpty( EntityId $itemId = null ) {
+   $empty = ItemContent::newEmpty();
+
+   if ( $itemId !== null ) {
+   $empty-getItem()-setId( $itemId );
+   }
+
+   return $empty;
+   }
+
+   /**
+* @param ItemId $itemId
+* @param ItemId $targetId
+*
+* @return ItemContent
+*/
+   private function newRedirect( ItemId $itemId, ItemId $targetId ) {
+   // FIXME: Use the respective EntityHandler instead of going via 
the global title lookup!
+   $titleLookup = 
WikibaseRepo::getDefaultInstance()-getEntityTitleLookup();
+   $title =