jenkins-bot has submitted this change and it was merged. Change subject: Avoid database access in MergeItemsTest by mocking ChangeOpFactoryProvider ......................................................................
Avoid database access in MergeItemsTest by mocking ChangeOpFactoryProvider Change-Id: Ie7e132283a89d70101511e19197ebc9c0bd739db --- M repo/tests/phpunit/includes/api/MergeItemsTest.php 1 file changed, 67 insertions(+), 16 deletions(-) Approvals: Hoo man: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/tests/phpunit/includes/api/MergeItemsTest.php b/repo/tests/phpunit/includes/api/MergeItemsTest.php index ef1261b..8ad1a55 100644 --- a/repo/tests/phpunit/includes/api/MergeItemsTest.php +++ b/repo/tests/phpunit/includes/api/MergeItemsTest.php @@ -8,14 +8,18 @@ use User; use Wikibase\Repo\Api\ApiErrorReporter; use Wikibase\Repo\Api\MergeItems; +use Wikibase\ChangeOp\ChangeOpFactoryProvider; use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\DataModel\Entity\ItemId; use Wikibase\Repo\Interactors\ItemMergeInteractor; use Wikibase\Repo\Interactors\RedirectCreationInteractor; +use Wikibase\Validators\TermValidatorFactory; use Wikibase\Repo\WikibaseRepo; use Wikibase\Test\EntityModificationTestHelper; use Wikibase\Test\MockRepository; +use Wikibase\Test\MockSiteStore; use Wikibase\Lib\Store\EntityRedirect; +use Wikibase\Lib\ClaimGuidGenerator; /** * @covers Wikibase\Repo\Api\MergeItems @@ -51,8 +55,6 @@ protected function setUp() { parent::setUp(); - $this->setUpSites(); - $this->entityModificationTestHelper = new EntityModificationTestHelper(); $this->apiModuleTestHelper = new ApiModuleTestHelper(); @@ -71,18 +73,9 @@ ) ); } - private function setUpSites() { - static $isSetup = false; - - if ( !$isSetup ) { - $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); - $sitesTable->clear(); - $sitesTable->saveSites( TestSites::getSites() ); - - $isSetup = true; - } - } - + /** + * @return EntityPermissionChecker + */ private function getPermissionCheckers() { $permissionChecker = $this->getMock( 'Wikibase\Repo\Store\EntityPermissionChecker' ); @@ -143,14 +136,22 @@ $resultBuilder = $apiHelperFactory->getResultBuilder( $module ); $summaryFormatter = $wikibaseRepo->getSummaryFormatter(); - $changeOpsFactory = $wikibaseRepo->getChangeOpFactoryProvider()->getMergeChangeOpFactory(); + $changeOpsFactoryProvider = new ChangeOpFactoryProvider( + $this->getConstraintProvider(), + new ClaimGuidGenerator(), + WikibaseRepo::getDefaultInstance()->getClaimGuidValidator(), + WikibaseRepo::getDefaultInstance()->getStatementGuidParser(), + $this->getSnakValidator(), + $this->getTermValidatorFactory(), + new MockSiteStore( TestSites::getSites() ) + ); $module->setServices( $idParser, $errorReporter, $resultBuilder, new ItemMergeInteractor( - $changeOpsFactory, + $changeOpsFactoryProvider->getMergeChangeOpFactory(), $this->mockRepository, $this->mockRepository, $this->getPermissionCheckers(), @@ -161,6 +162,56 @@ ); } + /** + * @return EntityConstraintProvider + */ + private function getConstraintProvider() { + $constraintProvider = $this->getMockBuilder( 'Wikibase\Validators\EntityConstraintProvider' ) + ->disableOriginalConstructor() + ->getMock(); + + $constraintProvider->expects( $this->any() ) + ->method( 'getUpdateValidators' ) + ->will( $this->returnValue( array() ) ); + + return $constraintProvider; + } + + /** + * @return SnakValidator + */ + private function getSnakValidator() { + $snakValidator = $this->getMockBuilder( 'Wikibase\Validators\SnakValidator' ) + ->disableOriginalConstructor() + ->getMock(); + + $snakValidator->expects( $this->any() ) + ->method( 'validate' ) + ->will( $this->returnValue( Status::newGood() ) ); + + return $snakValidator; + } + + /** + * @return TermValidatorFactory + */ + private function getTermValidatorFactory() { + $dupeDetector = $this->getMockBuilder( 'Wikibase\LabelDescriptionDuplicateDetector' ) + ->disableOriginalConstructor() + ->getMock(); + + $dupeDetector->expects( $this->any() ) + ->method( 'detectTermConflicts' ) + ->will( $this->returnValue( Status::newGood() ) ); + + return new TermValidatorFactory( + 100, + array( 'en', 'de', 'fr' ), + new BasicEntityIdParser(), + $dupeDetector + ); + } + private function callApiModule( $params, EntityRedirect $expectedRedirect = null ) { $module = $this->apiModuleTestHelper->newApiModule( 'Wikibase\Repo\Api\MergeItems', 'wbmergeitems', $params ); $this->overrideServices( $module, $expectedRedirect ); -- To view, visit https://gerrit.wikimedia.org/r/219152 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie7e132283a89d70101511e19197ebc9c0bd739db Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Bene <benestar.wikime...@gmail.com> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Lucie Kaffee <lucie.kaf...@wikimedia.de> Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits