Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
10 / 12
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FauxSearchResultSet
83.33% covered (warning)
83.33%
10 / 12
50.00% covered (danger)
50.00%
1 / 2
4.07
0.00% covered (danger)
0.00%
0 / 1
 __construct
81.82% covered (warning)
81.82%
9 / 11
0.00% covered (danger)
0.00%
0 / 1
3.05
 getTotalHits
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3use MediaWiki\Title\Title;
4
5/**
6 * A manually constructed search result set.
7 * Mainly meant for supporting developer setups where the search operation might be
8 * mocked or proxied.
9 */
10class FauxSearchResultSet extends SearchResultSet {
11
12    /**
13     * @var int|null
14     * @see getTotalHits
15     */
16    private $totalHits;
17
18    /**
19     * @param array<Title|SearchResult> $results Search results
20     * @param int|null $totalHits See getTotalHits()
21     */
22    public function __construct( array $results, $totalHits = null ) {
23        $totalHits = max( count( $results ), $totalHits );
24        $hasMoreResults = count( $results ) < $totalHits;
25        parent::__construct( false, $hasMoreResults );
26        $this->results = array_map( static function ( $result ) {
27            if ( $result instanceof SearchResult ) {
28                return $result;
29            } elseif ( $result instanceof Title ) {
30                return new FauxSearchResult( $result );
31            } else {
32                throw new InvalidArgumentException( '$results must contain Title or SearchResult' );
33            }
34        }, $results );
35        $this->totalHits = $totalHits;
36    }
37
38    /** @inheritDoc */
39    public function getTotalHits() {
40        return $this->totalHits;
41    }
42
43}