X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiQuerySearchTest.php;h=708ebc52b8c2974e6812a011d8a7ad74befb3d9f;hb=7ecbff2360a07755f771c648ed1e27ee3dca8ad5;hp=0700cf77de311e8f49661dccbf641164fad9736b;hpb=f459a71f75941a83335d6d63ee12079a4b586793;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiQuerySearchTest.php b/tests/phpunit/includes/api/ApiQuerySearchTest.php index 0700cf77de..708ebc52b8 100644 --- a/tests/phpunit/includes/api/ApiQuerySearchTest.php +++ b/tests/phpunit/includes/api/ApiQuerySearchTest.php @@ -10,22 +10,22 @@ class ApiQuerySearchTest extends ApiTestCase { 'empty search result' => [ [], [] ], 'has search results' => [ [ 'Zomg' ], - [ $this->mockResult( 'Zomg' ) ], + [ $this->mockResultClosure( 'Zomg' ) ], ], 'filters broken search results' => [ [ 'A', 'B' ], [ - $this->mockResult( 'a' ), - $this->mockResult( 'Zomg' )->setBrokenTitle( true ), - $this->mockResult( 'b' ), + $this->mockResultClosure( 'a' ), + $this->mockResultClosure( 'Zomg', [ 'setBrokenTitle' => true ] ), + $this->mockResultClosure( 'b' ), ], ], 'filters results with missing revision' => [ [ 'B', 'A' ], [ - $this->mockResult( 'Zomg' )->setMissingRevision( true ), - $this->mockResult( 'b' ), - $this->mockResult( 'a' ), + $this->mockResultClosure( 'Zomg', [ 'setMissingRevision' => true ] ), + $this->mockResultClosure( 'b' ), + $this->mockResultClosure( 'a' ), ], ], ]; @@ -56,7 +56,10 @@ class ApiQuerySearchTest extends ApiTestCase { [ SearchResultSet::SECONDARY_RESULTS => [ 'utwiki' => new MockSearchResultSet( [ - $this->mockResult( 'Qwerty' )->setInterwikiPrefix( 'utwiki' ), + $this->mockResultClosure( + 'Qwerty', + [ 'setInterwikiPrefix' => 'utwiki' ] + ), ] ), ], ] @@ -102,8 +105,28 @@ class ApiQuerySearchTest extends ApiTestCase { ] ); } - private function mockResult( $title ) { - return MockSearchResult::newFromtitle( Title::newFromText( $title ) ); + /** + * Returns a closure that evaluates to a MockSearchResult, to be resolved by + * MockSearchEngine::addMockResults() or MockresultSet::extractResults(). + * + * This is needed because MockSearchResults cannot be instantiated in a data provider, + * since they load revisions. This would hit the "real" database instead of the mock + * database, which in turn may cause cache pollution and other inconsistencies, see T202641. + * + * @param string $title + * @param array $setters + * @return callable function(): MockSearchResult + */ + private function mockResultClosure( $title, $setters = [] ) { + return function () use ( $title, $setters ){ + $result = MockSearchResult::newFromTitle( Title::newFromText( $title ) ); + + foreach ( $setters as $method => $param ) { + $result->$method( $param ); + } + + return $result; + }; } }