mirror of
https://github.com/Codappix/search_core.git
synced 2024-12-22 18:56:10 +01:00
TASK: Add tests for new query factory code
This commit is contained in:
parent
c38f7b9d6a
commit
b5225b943c
1 changed files with 206 additions and 0 deletions
|
@ -363,4 +363,210 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
'Empty search request does not create expected query.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function storedFieldsAreAddedToQuery()
|
||||
{
|
||||
$searchRequest = new SearchRequest();
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
['searching.boost'],
|
||||
['searching.fields.stored_fields'],
|
||||
['searching.fields.script_fields'],
|
||||
['searching.fieldValueFactor']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
'_source, something,nothing',
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException)
|
||||
));
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertSame(
|
||||
['_source', 'something', 'nothing'],
|
||||
$query->toArray()['stored_fields'],
|
||||
'Stored fields were not added to query as expected.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function storedFieldsAreNotAddedToQuery()
|
||||
{
|
||||
$searchRequest = new SearchRequest();
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
['searching.boost'],
|
||||
['searching.fields.stored_fields'],
|
||||
['searching.fields.script_fields'],
|
||||
['searching.fieldValueFactor']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException)
|
||||
));
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertFalse(
|
||||
isset($query->toArray()['stored_fields']),
|
||||
'Stored fields were added to query even if not configured.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function scriptFieldsAreAddedToQuery()
|
||||
{
|
||||
$searchRequest = new SearchRequest('query value');
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
['searching.boost'],
|
||||
['searching.fields.stored_fields'],
|
||||
['searching.fields.script_fields'],
|
||||
['searching.fieldValueFactor']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
[
|
||||
'field1' => [
|
||||
'config' => 'something',
|
||||
],
|
||||
'field2' => [
|
||||
'config' => '{request.query}',
|
||||
],
|
||||
],
|
||||
$this->throwException(new InvalidArgumentException)
|
||||
));
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertSame(
|
||||
[
|
||||
'field1' => [
|
||||
'config' => 'something',
|
||||
],
|
||||
'field2' => [
|
||||
'config' => 'query value',
|
||||
],
|
||||
],
|
||||
$query->toArray()['script_fields'],
|
||||
'Script fields were not added to query as expected.'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function scriptFieldsAreNotAddedToQuery()
|
||||
{
|
||||
$searchRequest = new SearchRequest();
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
['searching.boost'],
|
||||
['searching.fields.stored_fields'],
|
||||
['searching.fields.script_fields'],
|
||||
['searching.fieldValueFactor']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException)
|
||||
));
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertTrue(
|
||||
!isset($query->toArray()['script_fields']),
|
||||
'Script fields were added to query even if not configured.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function sortIsAddedToQuery()
|
||||
{
|
||||
$searchRequest = new SearchRequest('query value');
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('getIfExists')
|
||||
->withConsecutive(
|
||||
['searching.minimumShouldMatch'],
|
||||
['searching.sort']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
null,
|
||||
[
|
||||
'field1' => [
|
||||
'config' => 'something',
|
||||
],
|
||||
'field2' => [
|
||||
'config' => '{request.query}',
|
||||
],
|
||||
]
|
||||
));
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertSame(
|
||||
[
|
||||
'field1' => [
|
||||
'config' => 'something',
|
||||
],
|
||||
'field2' => [
|
||||
'config' => 'query value',
|
||||
],
|
||||
],
|
||||
$query->toArray()['sort'],
|
||||
'Sort was not added to query as expected.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function sortIsNotAddedToQuery()
|
||||
{
|
||||
$searchRequest = new SearchRequest('query value');
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('getIfExists')
|
||||
->withConsecutive(
|
||||
['searching.minimumShouldMatch'],
|
||||
['searching.sort']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
null,
|
||||
null
|
||||
));
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertTrue(
|
||||
!isset($query->toArray()['sort']),
|
||||
'Sort was added to query even if not configured.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue