Skip to content
Snippets Groups Projects
Commit 338267cd authored by Mantas's avatar Mantas
Browse files

added SpanContaining query

parent 0745aebc
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\ElasticsearchDSL\Query\Span;
/**
* Elasticsearch span containing query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-containing-query.html
*/
class SpanContainingQuery implements SpanQueryInterface
{
/**
* @param SpanQueryInterface
*/
private $big;
/**
* @param SpanQueryInterface
*/
private $little;
/**
* @param SpanQueryInterface $big
* @param SpanQueryInterface $little
*/
public function __construct(SpanQueryInterface $big, SpanQueryInterface $little)
{
$this->big = $big;
$this->little = $little;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'span_containing';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$out = [
'little' => $this->little->toArray(),
'big' => $this->big->toArray(),
];
return [$this->getType() => $out];
}
}
<?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\ElasticsearchDSL\Tests\Query\Span;
use ONGR\ElasticsearchDSL\Query\Span\SpanContainingQuery;
/**
* Unit test for SpanContainingQuery.
*/
class SpanContainingQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests for toArray().
*/
public function testToArray()
{
$query = new SpanContainingQuery(
$this->getSpanQueryMack('foo'),
$this->getSpanQueryMack('bar')
);
$result = [
'span_containing' => [
'little' => [
'span_term' => ['user' => 'bar'],
],
'big' => [
'span_term' => ['user' => 'foo'],
],
],
];
$this->assertEquals($result, $query->toArray());
}
/**
* @param string $value
*
* @returns \PHPUnit_Framework_MockObject_MockObject
*/
private function getSpanQueryMack($value)
{
$mock = $this->getMock('ONGR\ElasticsearchDSL\Query\Span\SpanQueryInterface');
$mock
->expects($this->once())
->method('toArray')
->willReturn(['span_term' => ['user' => $value]]);
return $mock;
}
}
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