mirror of
https://github.com/Codappix/search_core.git
synced 2024-12-25 14:36:09 +01:00
TASK: Fix broken unit tests
Adjust tests to match new queries built with multiple fields.
This commit is contained in:
parent
0006148a52
commit
e3151e802c
1 changed files with 45 additions and 39 deletions
|
@ -56,9 +56,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
{
|
||||
$searchRequest = new SearchRequest('SearchWord');
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertInstanceOf(
|
||||
|
@ -73,9 +71,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
*/
|
||||
public function filterIsAddedToQuery()
|
||||
{
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
|
||||
$searchRequest = new SearchRequest('SearchWord');
|
||||
$searchRequest->setFilter(['field' => 'content']);
|
||||
|
@ -95,9 +91,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
*/
|
||||
public function emptyFilterIsNotAddedToQuery()
|
||||
{
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
|
||||
$searchRequest = new SearchRequest('SearchWord');
|
||||
$searchRequest->setFilter([
|
||||
|
@ -122,9 +116,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
*/
|
||||
public function facetsAreAddedToQuery()
|
||||
{
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
$searchRequest = new SearchRequest('SearchWord');
|
||||
$searchRequest->addFacet(new FacetRequest('Identifier', 'FieldName'));
|
||||
$searchRequest->addFacet(new FacetRequest('Identifier 2', 'FieldName 2'));
|
||||
|
@ -153,9 +145,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
*/
|
||||
public function sizeIsAddedToQuery()
|
||||
{
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
$searchRequest = new SearchRequest('SearchWord');
|
||||
$searchRequest->setLimit(45);
|
||||
$searchRequest->setOffset(35);
|
||||
|
@ -179,9 +169,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
public function searchTermIsAddedToQuery()
|
||||
{
|
||||
$searchRequest = new SearchRequest('SearchWord');
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
$query = $this->subject->create($searchRequest);
|
||||
|
||||
$this->assertSame(
|
||||
|
@ -189,9 +177,11 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
'bool' => [
|
||||
'must' => [
|
||||
[
|
||||
'match' => [
|
||||
'_all' => [
|
||||
'query' => 'SearchWord',
|
||||
'multi_match' => [
|
||||
'type' => 'most_fields',
|
||||
'query' => 'SearchWord',
|
||||
'fields' => [
|
||||
'_all',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -219,9 +209,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
'50%',
|
||||
null
|
||||
));
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
$query = $this->subject->create($searchRequest);
|
||||
|
||||
$this->assertArraySubset(
|
||||
|
@ -229,10 +217,13 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
'bool' => [
|
||||
'must' => [
|
||||
[
|
||||
'match' => [
|
||||
'_all' => [
|
||||
'minimum_should_match' => '50%',
|
||||
'multi_match' => [
|
||||
'type' => 'most_fields',
|
||||
'query' => 'SearchWord',
|
||||
'fields' => [
|
||||
'_all',
|
||||
],
|
||||
'minimum_should_match' => '50%',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -253,12 +244,14 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
['searching.fields.query'],
|
||||
['searching.boost'],
|
||||
['searching.fields.stored_fields'],
|
||||
['searching.fields.script_fields'],
|
||||
['searching.fieldValueFactor']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
'_all',
|
||||
[
|
||||
'search_title' => 3,
|
||||
'search_abstract' => 1.5,
|
||||
|
@ -308,12 +301,14 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
['searching.fields.query'],
|
||||
['searching.boost'],
|
||||
['searching.fields.stored_fields'],
|
||||
['searching.fields.script_fields'],
|
||||
['searching.fieldValueFactor']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
'_all',
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
|
@ -328,9 +323,11 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
'bool' => [
|
||||
'must' => [
|
||||
[
|
||||
'match' => [
|
||||
'_all' => [
|
||||
'query' => 'SearchWord',
|
||||
'multi_match' => [
|
||||
'type' => 'most_fields',
|
||||
'query' => 'SearchWord',
|
||||
'fields' => [
|
||||
'_all',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -352,9 +349,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
{
|
||||
$searchRequest = new SearchRequest();
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertInstanceOf(
|
||||
|
@ -433,12 +428,14 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
['searching.fields.query'],
|
||||
['searching.boost'],
|
||||
['searching.fields.stored_fields'],
|
||||
['searching.fields.script_fields'],
|
||||
['searching.fieldValueFactor']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
'_all',
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
[
|
||||
|
@ -522,9 +519,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
]
|
||||
));
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertSame(
|
||||
|
@ -559,9 +554,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
null
|
||||
));
|
||||
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->throwException(new InvalidArgumentException));
|
||||
$this->configureConfigurationMockWithDefault();
|
||||
|
||||
$query = $this->subject->create($searchRequest);
|
||||
$this->assertTrue(
|
||||
|
@ -569,4 +562,17 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
'Sort was added to query even if not configured.'
|
||||
);
|
||||
}
|
||||
|
||||
protected function configureConfigurationMockWithDefault()
|
||||
{
|
||||
$this->configuration->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnCallback(function ($configName) {
|
||||
if ($configName === 'searching.fields.query') {
|
||||
return '_all';
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue