mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-25 04:16:11 +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');
|
$searchRequest = new SearchRequest('SearchWord');
|
||||||
|
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
|
|
||||||
$query = $this->subject->create($searchRequest);
|
$query = $this->subject->create($searchRequest);
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
|
@ -73,9 +71,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
*/
|
*/
|
||||||
public function filterIsAddedToQuery()
|
public function filterIsAddedToQuery()
|
||||||
{
|
{
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
|
|
||||||
$searchRequest = new SearchRequest('SearchWord');
|
$searchRequest = new SearchRequest('SearchWord');
|
||||||
$searchRequest->setFilter(['field' => 'content']);
|
$searchRequest->setFilter(['field' => 'content']);
|
||||||
|
@ -95,9 +91,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
*/
|
*/
|
||||||
public function emptyFilterIsNotAddedToQuery()
|
public function emptyFilterIsNotAddedToQuery()
|
||||||
{
|
{
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
|
|
||||||
$searchRequest = new SearchRequest('SearchWord');
|
$searchRequest = new SearchRequest('SearchWord');
|
||||||
$searchRequest->setFilter([
|
$searchRequest->setFilter([
|
||||||
|
@ -122,9 +116,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
*/
|
*/
|
||||||
public function facetsAreAddedToQuery()
|
public function facetsAreAddedToQuery()
|
||||||
{
|
{
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
$searchRequest = new SearchRequest('SearchWord');
|
$searchRequest = new SearchRequest('SearchWord');
|
||||||
$searchRequest->addFacet(new FacetRequest('Identifier', 'FieldName'));
|
$searchRequest->addFacet(new FacetRequest('Identifier', 'FieldName'));
|
||||||
$searchRequest->addFacet(new FacetRequest('Identifier 2', 'FieldName 2'));
|
$searchRequest->addFacet(new FacetRequest('Identifier 2', 'FieldName 2'));
|
||||||
|
@ -153,9 +145,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
*/
|
*/
|
||||||
public function sizeIsAddedToQuery()
|
public function sizeIsAddedToQuery()
|
||||||
{
|
{
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
$searchRequest = new SearchRequest('SearchWord');
|
$searchRequest = new SearchRequest('SearchWord');
|
||||||
$searchRequest->setLimit(45);
|
$searchRequest->setLimit(45);
|
||||||
$searchRequest->setOffset(35);
|
$searchRequest->setOffset(35);
|
||||||
|
@ -179,9 +169,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
public function searchTermIsAddedToQuery()
|
public function searchTermIsAddedToQuery()
|
||||||
{
|
{
|
||||||
$searchRequest = new SearchRequest('SearchWord');
|
$searchRequest = new SearchRequest('SearchWord');
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
$query = $this->subject->create($searchRequest);
|
$query = $this->subject->create($searchRequest);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
|
@ -189,9 +177,11 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
'bool' => [
|
'bool' => [
|
||||||
'must' => [
|
'must' => [
|
||||||
[
|
[
|
||||||
'match' => [
|
'multi_match' => [
|
||||||
'_all' => [
|
'type' => 'most_fields',
|
||||||
'query' => 'SearchWord',
|
'query' => 'SearchWord',
|
||||||
|
'fields' => [
|
||||||
|
'_all',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -219,9 +209,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
'50%',
|
'50%',
|
||||||
null
|
null
|
||||||
));
|
));
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
$query = $this->subject->create($searchRequest);
|
$query = $this->subject->create($searchRequest);
|
||||||
|
|
||||||
$this->assertArraySubset(
|
$this->assertArraySubset(
|
||||||
|
@ -229,10 +217,13 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
'bool' => [
|
'bool' => [
|
||||||
'must' => [
|
'must' => [
|
||||||
[
|
[
|
||||||
'match' => [
|
'multi_match' => [
|
||||||
'_all' => [
|
'type' => 'most_fields',
|
||||||
'minimum_should_match' => '50%',
|
'query' => 'SearchWord',
|
||||||
|
'fields' => [
|
||||||
|
'_all',
|
||||||
],
|
],
|
||||||
|
'minimum_should_match' => '50%',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -253,12 +244,14 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
$this->configuration->expects($this->any())
|
$this->configuration->expects($this->any())
|
||||||
->method('get')
|
->method('get')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
|
['searching.fields.query'],
|
||||||
['searching.boost'],
|
['searching.boost'],
|
||||||
['searching.fields.stored_fields'],
|
['searching.fields.stored_fields'],
|
||||||
['searching.fields.script_fields'],
|
['searching.fields.script_fields'],
|
||||||
['searching.fieldValueFactor']
|
['searching.fieldValueFactor']
|
||||||
)
|
)
|
||||||
->will($this->onConsecutiveCalls(
|
->will($this->onConsecutiveCalls(
|
||||||
|
'_all',
|
||||||
[
|
[
|
||||||
'search_title' => 3,
|
'search_title' => 3,
|
||||||
'search_abstract' => 1.5,
|
'search_abstract' => 1.5,
|
||||||
|
@ -308,12 +301,14 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
$this->configuration->expects($this->any())
|
$this->configuration->expects($this->any())
|
||||||
->method('get')
|
->method('get')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
|
['searching.fields.query'],
|
||||||
['searching.boost'],
|
['searching.boost'],
|
||||||
['searching.fields.stored_fields'],
|
['searching.fields.stored_fields'],
|
||||||
['searching.fields.script_fields'],
|
['searching.fields.script_fields'],
|
||||||
['searching.fieldValueFactor']
|
['searching.fieldValueFactor']
|
||||||
)
|
)
|
||||||
->will($this->onConsecutiveCalls(
|
->will($this->onConsecutiveCalls(
|
||||||
|
'_all',
|
||||||
$this->throwException(new InvalidArgumentException),
|
$this->throwException(new InvalidArgumentException),
|
||||||
$this->throwException(new InvalidArgumentException),
|
$this->throwException(new InvalidArgumentException),
|
||||||
$this->throwException(new InvalidArgumentException),
|
$this->throwException(new InvalidArgumentException),
|
||||||
|
@ -328,9 +323,11 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
'bool' => [
|
'bool' => [
|
||||||
'must' => [
|
'must' => [
|
||||||
[
|
[
|
||||||
'match' => [
|
'multi_match' => [
|
||||||
'_all' => [
|
'type' => 'most_fields',
|
||||||
'query' => 'SearchWord',
|
'query' => 'SearchWord',
|
||||||
|
'fields' => [
|
||||||
|
'_all',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -352,9 +349,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
{
|
{
|
||||||
$searchRequest = new SearchRequest();
|
$searchRequest = new SearchRequest();
|
||||||
|
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
|
|
||||||
$query = $this->subject->create($searchRequest);
|
$query = $this->subject->create($searchRequest);
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
|
@ -433,12 +428,14 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
$this->configuration->expects($this->any())
|
$this->configuration->expects($this->any())
|
||||||
->method('get')
|
->method('get')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
|
['searching.fields.query'],
|
||||||
['searching.boost'],
|
['searching.boost'],
|
||||||
['searching.fields.stored_fields'],
|
['searching.fields.stored_fields'],
|
||||||
['searching.fields.script_fields'],
|
['searching.fields.script_fields'],
|
||||||
['searching.fieldValueFactor']
|
['searching.fieldValueFactor']
|
||||||
)
|
)
|
||||||
->will($this->onConsecutiveCalls(
|
->will($this->onConsecutiveCalls(
|
||||||
|
'_all',
|
||||||
$this->throwException(new InvalidArgumentException),
|
$this->throwException(new InvalidArgumentException),
|
||||||
$this->throwException(new InvalidArgumentException),
|
$this->throwException(new InvalidArgumentException),
|
||||||
[
|
[
|
||||||
|
@ -522,9 +519,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
]
|
]
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
|
|
||||||
$query = $this->subject->create($searchRequest);
|
$query = $this->subject->create($searchRequest);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
|
@ -559,9 +554,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
null
|
null
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->configuration->expects($this->any())
|
$this->configureConfigurationMockWithDefault();
|
||||||
->method('get')
|
|
||||||
->will($this->throwException(new InvalidArgumentException));
|
|
||||||
|
|
||||||
$query = $this->subject->create($searchRequest);
|
$query = $this->subject->create($searchRequest);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
|
@ -569,4 +562,17 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
||||||
'Sort was added to query even if not configured.'
|
'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