jenkins-bot has submitted this change and it was merged.

Change subject: Do not lose subtype exception info in RevisionBasedEntityLookup
......................................................................


Do not lose subtype exception info in RevisionBasedEntityLookup

T114290

Change-Id: I5fd0c37e40370b451106d7f05d1efc0abf69609f
(cherry picked from commit 6acec307f5752197244b4d74a42e99dc38e1df85)
---
M lib/includes/store/RevisionBasedEntityLookup.php
M lib/tests/phpunit/store/RevisionBasedEntityLookupTest.php
2 files changed, 67 insertions(+), 0 deletions(-)

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



diff --git a/lib/includes/store/RevisionBasedEntityLookup.php 
b/lib/includes/store/RevisionBasedEntityLookup.php
index 9008a5d..2dfc282 100644
--- a/lib/includes/store/RevisionBasedEntityLookup.php
+++ b/lib/includes/store/RevisionBasedEntityLookup.php
@@ -42,6 +42,8 @@
        public function getEntity( EntityId $entityId ) {
                try {
                        $revision = $this->lookup->getEntityRevision( $entityId 
);
+               } catch ( EntityLookupException $ex ) {
+                       throw $ex;
                } catch ( \Exception $ex ) {
                        // TODO: catch more specific exception once 
EntityRevisionLookup contract gets clarified
                        throw new EntityLookupException( $entityId, null, $ex );
@@ -61,6 +63,8 @@
        public function hasEntity( EntityId $entityId ) {
                try {
                        return $this->lookup->getLatestRevisionId( $entityId ) 
!== false;
+               } catch ( EntityLookupException $ex ) {
+                       throw $ex;
                } catch ( \Exception $ex ) {
                        // TODO: catch more specific exception once 
EntityRevisionLookup contract gets clarified
                        throw new EntityLookupException( $entityId, null, $ex );
diff --git a/lib/tests/phpunit/store/RevisionBasedEntityLookupTest.php 
b/lib/tests/phpunit/store/RevisionBasedEntityLookupTest.php
index 388dc11..83d7408 100644
--- a/lib/tests/phpunit/store/RevisionBasedEntityLookupTest.php
+++ b/lib/tests/phpunit/store/RevisionBasedEntityLookupTest.php
@@ -7,6 +7,7 @@
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\RevisionBasedEntityLookup;
+use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
 
 /**
  * @covers Wikibase\Lib\Store\RevisionBasedEntityLookup
@@ -81,4 +82,66 @@
                $this->assertEquals( $exists, $actual );
        }
 
+       public function 
testWhenEntityLookupExceptionIsThrown_getEntityPassesItAlong() {
+               $entityLookup = new RevisionBasedEntityLookup( 
$this->newEntityLookupExceptionThrowingRevisionLookup() );
+
+               $this->setExpectedException( 
'Wikibase\Lib\Store\RevisionedUnresolvedRedirectException' );
+               $entityLookup->getEntity( new ItemId( 'Q1' ) );
+       }
+
+       private function newEntityLookupExceptionThrowingRevisionLookup() {
+               $revisionLookup = $this->getMock( 
'Wikibase\Lib\Store\EntityRevisionLookup' );
+
+               $revisionLookup->expects( $this->any() )
+                       ->method( 'getEntityRevision' )
+                       ->will( $this->throwException( new 
RevisionedUnresolvedRedirectException(
+                               new ItemId( 'Q1' ),
+                               new ItemId( 'Q2' )
+                       ) ) );
+
+               $revisionLookup->expects( $this->any() )
+                       ->method( 'getLatestRevisionId' )
+                       ->will( $this->throwException( new 
RevisionedUnresolvedRedirectException(
+                               new ItemId( 'Q1' ),
+                               new ItemId( 'Q2' )
+                       ) ) );
+
+               return $revisionLookup;
+       }
+
+       public function 
testWhenEntityLookupExceptionIsThrown_hasEntityPassesItAlong() {
+               $entityLookup = new RevisionBasedEntityLookup( 
$this->newEntityLookupExceptionThrowingRevisionLookup() );
+
+               $this->setExpectedException( 
'Wikibase\Lib\Store\RevisionedUnresolvedRedirectException' );
+               $entityLookup->hasEntity( new ItemId( 'Q1' ) );
+       }
+
+       public function 
testWhenBadExceptionIsThrown_hasEntityRethrowsAsEntityLookupException() {
+               $entityLookup = new RevisionBasedEntityLookup( 
$this->newBadExceptionThrowingRevisionLookup() );
+
+               $this->setExpectedException( 
'Wikibase\DataModel\Services\Lookup\EntityLookupException' );
+               $entityLookup->hasEntity( new ItemId( 'Q1' ) );
+       }
+
+       private function newBadExceptionThrowingRevisionLookup() {
+               $revisionLookup = $this->getMock( 
'Wikibase\Lib\Store\EntityRevisionLookup' );
+
+               $revisionLookup->expects( $this->any() )
+                       ->method( 'getEntityRevision' )
+                       ->will( $this->throwException( new \Exception( 'Someone 
killed a kitten' ) ) );
+
+               $revisionLookup->expects( $this->any() )
+                       ->method( 'getLatestRevisionId' )
+                       ->will( $this->throwException( new \Exception( 'Someone 
killed a kitten' ) ) );
+
+               return $revisionLookup;
+       }
+
+       public function 
testWhenBadExceptionIsThrown_getEntityRethrowsAsEntityLookupException() {
+               $entityLookup = new RevisionBasedEntityLookup( 
$this->newBadExceptionThrowingRevisionLookup() );
+
+               $this->setExpectedException( 
'Wikibase\DataModel\Services\Lookup\EntityLookupException' );
+               $entityLookup->getEntity( new ItemId( 'Q1' ) );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5fd0c37e40370b451106d7f05d1efc0abf69609f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.27.0-wmf.1
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to