Merge "DifferenceEngine: use a fake title when there's no real title"
[lhc/web/wiklou.git] / tests / phpunit / mocks / search / MockSearchResultSet.php
1 <?php
2
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;
9
10 /**
11 * @param SearchResult[]|callable[] $results
12 * @param SearchResultSet[][]|callable[][] $interwikiResults Map from result type
13 * to list of results for that type.
14 */
15 public function __construct( array $results, array $interwikiResults = [] ) {
16 parent::__construct( false, false );
17 $this->results = $results;
18 $this->interwikiResults = $interwikiResults;
19 }
20
21 public function numRows() {
22 return count( $this->results );
23 }
24
25 public function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) {
26 return isset( $this->interwikiResults[$type] ) &&
27 count( $this->interwikiResults[$type] ) > 0;
28 }
29
30 public function extractResults() {
31 $results = parent::extractResults();
32
33 foreach ( $results as &$result ) {
34 // Resolve deferred results; needed to work around T203279
35 if ( is_callable( $result ) ) {
36 $result = $result();
37 }
38 }
39
40 return $results;
41 }
42
43 public function getInterwikiResults( $type = self::SECONDARY_RESULTS ) {
44 if ( $this->hasInterwikiResults( $type ) ) {
45 return $this->interwikiResults[$type];
46 } else {
47 return null;
48 }
49 }
50 }