Skip to content
Snippets Groups Projects
Commit a211e96f authored by Mantas Simkus's avatar Mantas Simkus
Browse files

Added Unit/DSL/Query/Span tests

parent b65d08a1
No related branches found
No related tags found
No related merge requests found
<?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\Span;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanFirstQuery;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanQueryInterface;
/**
* Unit test for SpanFirstQuery.
*/
class SpanFirstQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Object.
*/
protected $mock;
/**
* Create mock object.
*/
protected function setUp()
{
$this->mock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Query\Span\SpanQueryInterface')->getMock();
$this->mock->expects($this->atMost(1))
->method('getType')
->will($this->returnValue('span_or'));
$this->mock->expects($this->atMost(1))
->method('toArray')
->will($this->returnValue(['key' => 'value']));
}
/**
* Reset mock object.
*/
public function tearDown()
{
$this->mock = null;
}
/**
* Tests toArray method.
*/
public function testSpanFirstQueryToArray()
{
/** @var SpanQueryInterface $mock */
$mock = $this->mock;
$query = new SpanFirstQuery($mock, 5);
$result = [
'match' => [
'span_or' => [ 'key' => 'value'],
],
'end' => 5,
];
$this->assertEquals($result, $query->toArray());
}
/**
* Tests get Type method.
*/
public function testSpanFirstQueryGetType()
{
/** @var SpanQueryInterface $mock */
$mock = $this->mock;
$query = new SpanFirstQuery($mock, 5);
$result = $query->getType();
$this->assertEquals('span_first', $result);
}
}
<?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\Span;
use ONGR\ElasticsearchBundle\DSL\BuilderInterface;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanMultiTermQuery;
/**
* Unit test for SpanMultiTermQuery.
*/
class SpanMultiTermQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var array.
*/
protected $mock;
/**
* Create mock object.
*/
protected function setUp()
{
$allowedQueries = ['\FuzzyQuery', '\PrefixQuery', '\TermQuery', '\WildcardQuery', '\RegexpQuery'];
// Same constructors for all of these queries.
foreach ($allowedQueries as $query) {
$this->mock[$query] = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Query' . "{$query}")
->setConstructorArgs(['field', 'value'])
->getMock();
$this->mock[$query]->expects($this->atMost(1))
->method('getType')
->will($this->returnValue('span'));
$this->mock[$query]->expects($this->atMost(1))
->method('toArray')
->will($this->returnValue(['field' => 'value']));
}
}
/**
* Reset mock object.
*/
public function tearDown()
{
$this->mock = null;
}
/**
* Tests toArray method using these queries: Fuzzy, Prefix, Term, Wildcard, Regexp.
*/
public function testSpanMultiTermQueryToArray()
{
/** @var BuilderInterface $mock */
$mock = $this->mock;
foreach ($mock as $mocked) {
$query = new SpanMultiTermQuery($mocked);
$result = [
'match' => [
'span' => [
'field' => 'value',
],
],
];
$this->assertEquals($result, $query->toArray());
}
}
/**
* Tests toArray method using this query: Range.
*/
public function testSpanMultiTermQueryToArrayNext()
{
/** @var BuilderInterface $mock */
$mock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Query\RangeQuery')
->setConstructorArgs(['field', ['gte']])
->getMock();
$mock->expects($this->once())
->method('getType')
->will($this->returnValue('range'));
$mock->expects($this->once())
->method('toArray')
->will($this->returnValue(['field' => ['gte']]));
$query = new SpanMultiTermQuery($mock);
$result = [
'match' => [
'range' => [
'field' => ['gte'],
],
],
];
$this->assertEquals($result, $query->toArray());
}
/**
* Tests get Type method.
*/
public function testSpanMultiTermQueryGetType()
{
/** @var BuilderInterface $mock */
$mock = $this->mock['\FuzzyQuery'];
$query = new SpanMultiTermQuery($mock);
$result = $query->getType();
$this->assertEquals('span_multi', $result);
}
}
<?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\Span;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanNearQuery;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanQueryInterface;
/**
* Unit test for SpanNearQuery.
*/
class SpanNearQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Object.
*/
protected $mock;
/**
* Create mock object.
*/
protected function setUp()
{
$this->mock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Query\Span\SpanQueryInterface')->getMock();
$this->mock->expects($this->atMost(1))
->method('getType')
->will($this->returnValue('span_or'));
$this->mock->expects($this->atMost(1))
->method('toArray')
->will($this->returnValue(['key' => 'value']));
}
/**
* Reset mock object.
*/
public function tearDown()
{
$this->mock = null;
}
/**
* Tests toArray method.
*/
public function testSpanMultiTermQueryToArray()
{
/** @var SpanQueryInterface $mock */
$mock = $this->mock;
$query = new SpanNearQuery(['name']);
$query->setSlop(5);
$query->addQuery($mock);
$result = [
'clauses' => [
0 => [
'span_or' => [
'key' => 'value',
],
],
],
'slop' => 5,
0 => 'name',
];
$this->assertEquals($result, $query->toArray());
}
/**
* Tests get Type method.
*/
public function testSpanNearQueryGetType()
{
$query = new SpanNearQuery(['name']);
$result = $query->getType();
$this->assertEquals('span_near', $result);
}
}
<?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\Span;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanNotQuery;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanQueryInterface;
/**
* Unit test for SpanNotQuery.
*/
class SpanNotQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Object.
*/
protected $mock;
/**
* Create mock object.
*/
protected function setUp()
{
$this->mock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Query\Span\SpanQueryInterface')->getMock();
$this->mock->expects($this->atMost(2))
->method('getType')
->will($this->returnValue('span_or'));
$this->mock->expects($this->atMost(2))
->method('toArray')
->will($this->returnValue(['key' => 'value']));
}
/**
* Reset mock object.
*/
public function tearDown()
{
$this->mock = null;
}
/**
* Tests get Type method.
*/
public function testSpanNotQueryGetType()
{
/** @var SpanQueryInterface $mock */
$mock = $this->mock;
$query = new SpanNotQuery($mock, $mock);
$result = $query->getType();
$this->assertEquals('span_not', $result);
}
/**
* Tests toArray method.
*/
public function testSpanNotQueryToArray()
{
/** @var SpanQueryInterface $mock */
$mock = $this->mock;
$query = new SpanNotQuery($mock, $mock);
$result = [
'include' => [
'span_or' => ['key' => 'value'],
],
'exclude' => [
'span_or' => ['key' => 'value'],
],
];
$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\Span;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanOrQuery;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanQueryInterface;
/**
* Unit test for SpanOrQuery.
*/
class SpanOrQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Object.
*/
protected $mock;
/**
* Create mock object.
*/
protected function setUp()
{
$this->mock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Query\Span\SpanQueryInterface')->getMock();
$this->mock->expects($this->atMost(1))
->method('getType')
->will($this->returnValue('span_or'));
$this->mock->expects($this->atMost(1))
->method('toArray')
->will($this->returnValue(['key' => 'value']));
}
/**
* Reset mock object.
*/
public function tearDown()
{
$this->mock = null;
}
/**
* Tests get Type method.
*/
public function testSpanOrQueryGetType()
{
$query = new SpanOrQuery();
$result = $query->getType();
$this->assertEquals('span_or', $result);
}
/**
* Tests toArray method.
*/
public function testSpanOrQueryToArray()
{
/** @var SpanQueryInterface $mock */
$mock = $this->mock;
$query = new SpanOrQuery();
$query->addQuery($mock);
$result = [
'clauses' => [
0 => [
'span_or' => ['key' => 'value'],
],
],
];
$this->assertEquals($result, $query->toArray());
$result = $query->getQueries();
$this->assertInternalType('array',$result);
$this->assertEquals(1,count($result));
}
}
<?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\Span;
use ONGR\ElasticsearchBundle\DSL\Query\Span\SpanTermQuery;
/**
* Unit test for SpanTermQuery.
*/
class SpanTermQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests get Type method.
*/
public function testSpanTermQueryGetType()
{
$query = new SpanTermQuery('field', 'value');
$result = $query->getType();
$this->assertEquals('span_term', $result);
}
}
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