Skip to content
Snippets Groups Projects
Commit c656ba2c authored by Simonas Šerlinskas's avatar Simonas Šerlinskas
Browse files

Merge branch 'LTRocky-fixed2'

parent fe6014c9
No related branches found
No related tags found
No related merge requests found
......@@ -26,9 +26,9 @@ class BoolTest extends \PHPUnit_Framework_TestCase
public function testBoolIsRelevant()
{
$bool = new Bool();
$this->assertEquals(false, $bool->isRelevant());
$this->assertFalse($bool->isRelevant());
$bool->addToBool(new MissingFilter('test'));
$this->assertEquals(true, $bool->isRelevant());
$this->assertTrue($bool->isRelevant());
}
/**
......
......@@ -20,8 +20,8 @@ class PostFilterTest extends \PHPUnit_Framework_TestCase
*/
public function testIfGetType()
{
$filter = new PostFilter();
$this->assertEquals('post_filter', $filter->getType());
$postFilter = new PostFilter();
$this->assertEquals('post_filter', $postFilter->getType());
}
/**
......@@ -29,7 +29,43 @@ class PostFilterTest extends \PHPUnit_Framework_TestCase
*/
public function testIfIsRelevantFunctionIsReturningFalse()
{
$bool = new PostFilter();
$this->assertFalse($bool->isRelevant());
$postFilter = new PostFilter();
$this->assertFalse($postFilter->isRelevant());
}
/**
* Test addFilter method.
*/
public function testAddFilter()
{
$missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
->setMethods(['addToBool'])
->disableOriginalConstructor()
->getMock();
$missingFilterMock->expects($this->once())
->method('addToBool')
->withAnyParameters();
$postFilter = new PostFilter();
$postFilter->setFilter($missingFilterMock);
$postFilter->addFilter($missingFilterMock, 'test');
}
/**
* Test setBoolParameters method.
*/
public function testSetBoolParameters()
{
$missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
->setMethods(['setParameters'])
->disableOriginalConstructor()
->getMock();
$missingFilterMock->expects($this->once())
->method('setParameters')
->withAnyParameters();
$postFilter = new PostFilter();
$postFilter->setFilter($missingFilterMock);
$postFilter->setBoolParameters(['test_param']);
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
/**
* Test for ParametersTrait.
*/
class ParametersTraitTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ParametersTrait
*/
private $parametersTraitMock;
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->parametersTraitMock = $this->getMockForTrait('ONGR\ElasticsearchBundle\DSL\ParametersTrait');
}
/**
* Tests addParameter method.
*/
public function testGetAndAddParameter()
{
$this->parametersTraitMock->addParameter('acme', 123);
$this->assertEquals(123, $this->parametersTraitMock->getParameter('acme'));
$this->parametersTraitMock->addParameter('bar', 321);
$this->assertEquals(321, $this->parametersTraitMock->getParameter('bar'));
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Query;
use ONGR\ElasticsearchBundle\DSL\Query\HasChildQuery;
class HasChildQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests whether __constructor calls setParameters method.
*/
public function testConstructor()
{
$missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
->setConstructorArgs(['test_field'])
->getMock();
$query = new HasChildQuery('test_type', $missingFilterMock, ['test_parameter1']);
$this->assertEquals(['test_parameter1'], $query->getParameters());
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Query;
use ONGR\ElasticsearchBundle\DSL\Query\HasParentQuery;
class HasParentQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests whether __constructor calls setParameters method.
*/
public function testConstructor()
{
$missingFilter = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
->setConstructorArgs(['test_field'])
->getMock();
$query = new HasParentQuery('test_type', $missingFilter, ['test_parameter1']);
$this->assertEquals(['test_parameter1'], $query->getParameters());
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Query;
use ONGR\ElasticsearchBundle\DSL\Query\FilteredQuery;
use ONGR\ElasticsearchBundle\DSL\Query\IndicesQuery;
use ONGR\ElasticsearchBundle\Test\EncapsulationTestAwareTrait;
class IndicesQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Data provider for testToArrayManyIndices function.
*
* @return array
*/
public function getArrayWithManyIndicesDataProvider()
{
$queryMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Query\Query')
->getMock();
$queryMock->expects($this->any())
->method('toArray')
->willReturn(['testKey' => 'testValue']);
$queryMock->expects($this->any())
->method('getType')
->willReturn('testType');
return [
[
$queryMock,
[
'test_indice1',
'test_indice2',
],
[
'indices' => [
'test_indice1',
'test_indice2',
],
'query' => [
'testType' => [
'testKey' => 'testValue',
],
],
],
],
];
}
/**
* Test toArray() method when the number of indices > 1.
*
* @param Query $query Query for testing.
* @param array $parameters Optional parameters.
* @param array $expected Expected values.
*
* @dataProvider getArrayWithManyIndicesDataProvider
*/
public function testToArrayWithManyIndices($query, $parameters, $expected)
{
$query = new IndicesQuery($parameters, $query);
$this->assertEquals($expected, $query->toArray());
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Query;
use ONGR\ElasticsearchBundle\DSL\Query\NestedQuery;
class NestedQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests toArray method.
*/
public function testToArray()
{
$missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
->setConstructorArgs(['test_field'])
->getMock();
$missingFilterMock->expects($this->any())
->method('getType')
->willReturn('test_type');
$missingFilterMock->expects($this->any())
->method('toArray')
->willReturn(['testKey' => 'testValue']);
$result = [
'path' => 'test_path',
'query' => [
'test_type' => ['testKey' => 'testValue'],
],
];
$query = new NestedQuery('test_path', $missingFilterMock);
$this->assertEquals($result, $query->toArray());
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Query;
use ONGR\ElasticsearchBundle\DSL\Query\Query;
class QueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests setBoolParameters method.
*/
public function testSetBoolParameters()
{
$missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
->setConstructorArgs(['test_field'])
->getMock();
$missingFilterMock->expects($this->once())
->method('setParameters');
$query = new Query();
$query->setQuery($missingFilterMock);
$query->setBoolParameters([false]);
}
/**
* Tests addQuery method.
*/
public function testAddQuery()
{
$missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
->disableOriginalConstructor()
->setMethods(['addToBool'])
->getMock();
$missingFilterMock->expects($this->once())
->method('addToBool')
->withAnyParameters();
$postFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\PostFilter')
->disableOriginalConstructor()
->getMock();
$query = new Query();
$query->setQuery($missingFilterMock);
$query->addQuery($postFilterMock);
}
/**
* Tests getType method.
*/
public function testGetType()
{
$query = new Query();
$this->assertEquals('query', $query->getType());
}
/**
* Tests toArray method.
*/
public function testToArray()
{
$missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
->disableOriginalConstructor()
->getMock();
$missingFilterMock->expects($this->once())
->method('getType')
->willReturn('test_type');
$missingFilterMock->expects($this->once())
->method('toArray')
->willReturn('test_array');
$query = new Query();
$query->setQuery($missingFilterMock);
$this->assertEquals(['test_type' => 'test_array'], $query->toArray());
}
}
......@@ -32,7 +32,6 @@ class ContextTest extends \PHPUnit_Framework_TestCase
$context->setContext(new Phrase('', ''));
$result = $context->toArray();
$this->assertArrayHasKey($name, $result);
$data = $result[$name];
......@@ -40,7 +39,6 @@ class ContextTest extends \PHPUnit_Framework_TestCase
$completion = $data['completion'];
$this->assertArrayHasKey('size', $completion);
$this->assertEquals($completion['size'], 123);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment