jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/343532 )

Change subject: Avoid database access in ItemHandlerTest data provider
......................................................................


Avoid database access in ItemHandlerTest data provider

ItemContent constructor access the database when a redirect title
is passed. (to check if the redirect has same content model
and the title doesn't already have content model set on the object)

We can work around this by setting the content model on the
title object.

It would be nicer if we could altogether avoid database access
in the constructor (maybe by removing the check and checking
elsewhere when creating redirects?) but not sure and don't want
to do that in this patch.

Change-Id: I16c3252892595ef79a9f865c850e02066093d053
---
M repo/tests/phpunit/includes/Content/ItemHandlerTest.php
1 file changed, 21 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Thiemo Mättig (WMDE): Looks good to me, approved



diff --git a/repo/tests/phpunit/includes/Content/ItemHandlerTest.php 
b/repo/tests/phpunit/includes/Content/ItemHandlerTest.php
index 91bd4c6..05ed012 100644
--- a/repo/tests/phpunit/includes/Content/ItemHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/ItemHandlerTest.php
@@ -78,8 +78,8 @@
                $item2 = $this->newEntity();
                $item2->setLabel( 'en', 'Bar' );
 
-               $itemContent1 = $this->newRedirectContent( $item1->getId(), new 
ItemId( 'Q112' ) );
-               $itemContent2 = $this->newRedirectContent( $item1->getId(), new 
ItemId( 'Q113' ) );
+               $itemContent1 = $this->newRedirectItemContent( $item1->getId(), 
new ItemId( 'Q112' ) );
+               $itemContent2 = $this->newRedirectItemContent( $item1->getId(), 
new ItemId( 'Q113' ) );
 
                $rev1 = $this->fakeRevision( $this->newEntityContent( $item1 ), 
11 );
                $rev2 = $this->fakeRevision( $itemContent1, 12 );
@@ -95,6 +95,25 @@
        }
 
        /**
+        * @param ItemId $id
+        * @param ItemId $targetId
+        *
+        * @return ItemContent
+        */
+       protected function newRedirectItemContent( ItemId $id, ItemId $targetId 
) {
+               $redirect = new EntityRedirect( $id, $targetId );
+
+               $handler = $this->getHandler();
+               $title = $handler->getTitleForId( $redirect->getTargetId() );
+
+               // set content model to avoid db call to look up content model 
when
+               // constructing ItemContent in the tests, especially in the 
data providers.
+               $title->setContentModel( $handler->getModelID() );
+
+               return ItemContent::newFromRedirect( $redirect, $title );
+       }
+
+       /**
         * @param EntityDocument|null $entity
         *
         * @return EntityContent

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I16c3252892595ef79a9f865c850e02066093d053
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to