public function StemmerTest::testPreprocessSearchQuery in Search API 8
Tests the preprocessSearchQuery() method.
@covers ::preprocessSearchQuery
@dataProvider preprocessSearchQueryDataProvider
Parameters
string[]|null $languages: The languages to set for the query.
bool $should_process: Whether keys are expected to be processed by the processor or not.
File
- tests/
src/ Unit/ Processor/ StemmerTest.php, line 135
Class
- StemmerTest
- Tests the "Stemmer" processor.
Namespace
Drupal\Tests\search_api\Unit\ProcessorCode
public function testPreprocessSearchQuery(array $languages = NULL, $should_process) {
/** @var \Drupal\search_api\Query\QueryInterface|\PHPUnit\Framework\MockObject\MockObject $query */
$query = $this
->createMock(QueryInterface::class);
$query
->method('getLanguages')
->willReturn($languages);
// Unfortunately, returning a reference (as getKeys() has to do for
// processing to work) doesn't seem to be possible with a mock object. But
// since the only code we really want to test is the language check, using
// an exception works just as well, and is quite simple.
$query
->method('getKeys')
->willThrowException(new \RuntimeException());
try {
$this->processor
->preprocessSearchQuery($query);
$this
->assertFalse($should_process, "Keys weren't processed but should have been.");
} catch (\RuntimeException $e) {
$this
->assertTrue($should_process, "Keys were processed but shouldn't have been.");
}
}