Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / mocks / search / MockSearchResultSet.php
blobc3f6c75de59e19b8e5ccd73b8b1a7e6b00c9b527
1 <?php
3 class MockSearchResultSet extends SearchResultSet {
4 /**
5 * @var SearchResultSet[][] Map from result type to list of results for
6 * that type.
7 */
8 private $interwikiResults;
10 /**
11 * @param SearchResult[]|callable[] $results
12 * @param ISearchResultSet[][]|callable[][] $interwikiResults Map from result type
13 * to list of results for that type.
15 public function __construct( array $results, array $interwikiResults = [] ) {
16 parent::__construct( false, false );
17 $this->results = $results;
18 $this->interwikiResults = $interwikiResults;
21 public function numRows() {
22 return count( $this->results );
25 public function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) {
26 return (bool)( $this->interwikiResults[$type] ?? false );
29 public function extractResults() {
30 $results = parent::extractResults();
32 foreach ( $results as &$result ) {
33 // Resolve deferred results; needed to work around T203279
34 if ( is_callable( $result ) ) {
35 $result = $result();
39 return $results;
42 public function getInterwikiResults( $type = self::SECONDARY_RESULTS ) {
43 return $this->interwikiResults[$type] ?? [];
46 public function getTotalHits() {
47 return $this->numRows();