wiki.techinc.nl/tests/phpunit/mocks/search/MockSearchResultSet.php
thiemowmde 52963bbcc0 tests: Make use of ?? and ??= operators in test code
I believe the more recent syntax is quite a bit more readable. The
most obvious benefit is that it allows for much less duplication.

Note this patch is intentionally only touching tests, so it can't
have any effect on production code.

Change-Id: Ibdde9e37edf80f0d3bb3cb9056bee5f7df8010ee
2024-08-08 15:51:20 +02:00

45 lines
1.1 KiB
PHP

<?php
class MockSearchResultSet extends SearchResultSet {
/**
* @var SearchResultSet[][] Map from result type to list of results for
* that type.
*/
private $interwikiResults;
/**
* @param SearchResult[]|callable[] $results
* @param ISearchResultSet[][]|callable[][] $interwikiResults Map from result type
* to list of results for that type.
*/
public function __construct( array $results, array $interwikiResults = [] ) {
parent::__construct( false, false );
$this->results = $results;
$this->interwikiResults = $interwikiResults;
}
public function numRows() {
return count( $this->results );
}
public function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) {
return (bool)( $this->interwikiResults[$type] ?? false );
}
public function extractResults() {
$results = parent::extractResults();
foreach ( $results as &$result ) {
// Resolve deferred results; needed to work around T203279
if ( is_callable( $result ) ) {
$result = $result();
}
}
return $results;
}
public function getInterwikiResults( $type = self::SECONDARY_RESULTS ) {
return $this->interwikiResults[$type] ?? [];
}
}