summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder')
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/AbstractDSLTest.php97
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/AggregationTest.php58
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/FilterTest.php58
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/QueryTest.php85
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/SuggestTest.php32
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/VersionTest.php67
6 files changed, 397 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/AbstractDSLTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/AbstractDSLTest.php
new file mode 100644
index 00000000..3e44f463
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/AbstractDSLTest.php
@@ -0,0 +1,97 @@
+<?php
+namespace Elastica\Test\QueryBuilder\DSL;
+
+use Elastica\Exception\NotImplementedException;
+use Elastica\QueryBuilder\DSL;
+use Elastica\Test\Base as BaseTest;
+
+abstract class AbstractDSLTest extends BaseTest
+{
+ /**
+ * @param DSL $dsl
+ * @param string $methodName
+ * @param string $className
+ * @param array $arguments
+ */
+ protected function _assertImplemented(DSL $dsl, $methodName, $className, $arguments)
+ {
+ // Check method existence
+ $this->assertTrue(method_exists($dsl, $methodName));
+
+ // Check returned value
+ $return = call_user_func_array(array($dsl, $methodName), $arguments);
+ $this->assertTrue(class_exists($className), 'Class not exists but NotImplementedException is not thrown');
+ $this->assertInstanceOf($className, $return);
+
+ // Check method signature
+ $class = new \ReflectionClass($className);
+ $method = new \ReflectionMethod(get_class($dsl), $methodName);
+ if (!$class->hasMethod('__construct')) {
+ $this->assertEmpty($method->getParameters(), 'Constructor is not defined, but method has some parameters');
+ } else {
+ $this->_assertParametersEquals($class->getMethod('__construct')->getParameters(), $method->getParameters());
+ }
+ }
+
+ /**
+ * @param DSL $dsl
+ * @param string $name
+ */
+ protected function _assertNotImplemented(DSL $dsl, $methodName, $arguments)
+ {
+ try {
+ call_user_func(array($dsl, $methodName), $arguments);
+ $this->fail('NotImplementedException is not thrown');
+ } catch (NotImplementedException $ex) {
+ // expected
+ }
+ }
+
+ /**
+ * @param \ReflectionParameter[] $left
+ * @param \ReflectionParameter[] $right
+ */
+ protected function _assertParametersEquals($left, $right)
+ {
+ $this->assertEquals(count($left), count($right), 'Parameters count mismatch');
+
+ for ($i = 0; $i < count($left); $i++) {
+ $this->assertEquals($left[$i]->getName(), $right[$i]->getName(), 'Parameters names mismatch');
+ $this->assertEquals($left[$i]->isOptional(), $right[$i]->isOptional(), 'Parameters optionality mismatch');
+ $this->assertEquals($this->_getHintName($left[$i]), $this->_getHintName($right[$i]), 'Parameters typehints mismatch');
+ $this->assertEquals($this->_getDefaultValue($left[$i]), $this->_getDefaultValue($right[$i]), 'Default values mismatch');
+ }
+ }
+
+ /**
+ * @param \ReflectionParameter $param
+ *
+ * @return string|null
+ */
+ protected function _getDefaultValue(\ReflectionParameter $param)
+ {
+ if ($param->isOptional()) {
+ return $param->getDefaultValue();
+ }
+ }
+
+ /**
+ * @param \ReflectionParameter $param
+ *
+ * @return string|null
+ */
+ protected function _getHintName(\ReflectionParameter $param)
+ {
+ if (version_compare(phpversion(), '5.4', '>=') && $param->isCallable()) {
+ return 'callable';
+ }
+
+ if ($param->isArray()) {
+ return 'array';
+ }
+
+ if ($class = $param->getClass()) {
+ return $class->getName();
+ }
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/AggregationTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/AggregationTest.php
new file mode 100644
index 00000000..67c70862
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/AggregationTest.php
@@ -0,0 +1,58 @@
+<?php
+namespace Elastica\Test\QueryBuilder\DSL;
+
+use Elastica\Filter\Exists;
+use Elastica\QueryBuilder\DSL;
+
+class AggregationTest extends AbstractDSLTest
+{
+ /**
+ * @group unit
+ */
+ public function testType()
+ {
+ $aggregationDSL = new DSL\Aggregation();
+
+ $this->assertInstanceOf('Elastica\QueryBuilder\DSL', $aggregationDSL);
+ $this->assertEquals(DSL::TYPE_AGGREGATION, $aggregationDSL->getType());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testInterface()
+ {
+ $aggregationDSL = new DSL\Aggregation();
+
+ $this->_assertImplemented($aggregationDSL, 'avg', 'Elastica\Aggregation\Avg', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'cardinality', 'Elastica\Aggregation\Cardinality', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'date_histogram', 'Elastica\Aggregation\DateHistogram', array('name', 'field', 1));
+ $this->_assertImplemented($aggregationDSL, 'date_range', 'Elastica\Aggregation\DateRange', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'extended_stats', 'Elastica\Aggregation\ExtendedStats', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'filter', 'Elastica\Aggregation\Filter', array('name', new Exists('field')));
+ $this->_assertImplemented($aggregationDSL, 'filters', 'Elastica\Aggregation\Filters', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'geo_distance', 'Elastica\Aggregation\GeoDistance', array('name', 'field', 'origin'));
+ $this->_assertImplemented($aggregationDSL, 'geohash_grid', 'Elastica\Aggregation\GeohashGrid', array('name', 'field'));
+ $this->_assertImplemented($aggregationDSL, 'global_agg', 'Elastica\Aggregation\GlobalAggregation', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'histogram', 'Elastica\Aggregation\Histogram', array('name', 'field', 1));
+ $this->_assertImplemented($aggregationDSL, 'ipv4_range', 'Elastica\Aggregation\IpRange', array('name', 'field'));
+ $this->_assertImplemented($aggregationDSL, 'max', 'Elastica\Aggregation\Max', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'min', 'Elastica\Aggregation\Min', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'missing', 'Elastica\Aggregation\Missing', array('name', 'field'));
+ $this->_assertImplemented($aggregationDSL, 'nested', 'Elastica\Aggregation\Nested', array('name', 'path'));
+ $this->_assertImplemented($aggregationDSL, 'percentiles', 'Elastica\Aggregation\Percentiles', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'range', 'Elastica\Aggregation\Range', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'reverse_nested', 'Elastica\Aggregation\ReverseNested', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'scripted_metric', 'Elastica\Aggregation\ScriptedMetric', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'significant_terms', 'Elastica\Aggregation\SignificantTerms', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'stats', 'Elastica\Aggregation\Stats', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'sum', 'Elastica\Aggregation\Sum', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'terms', 'Elastica\Aggregation\Terms', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'top_hits', 'Elastica\Aggregation\TopHits', array('name'));
+ $this->_assertImplemented($aggregationDSL, 'value_count', 'Elastica\Aggregation\ValueCount', array('name', 'field'));
+
+ $this->_assertNotImplemented($aggregationDSL, 'children', array('name'));
+ $this->_assertNotImplemented($aggregationDSL, 'geo_bounds', array('name'));
+ $this->_assertNotImplemented($aggregationDSL, 'percentile_ranks', array('name'));
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/FilterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/FilterTest.php
new file mode 100644
index 00000000..755bd18a
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/FilterTest.php
@@ -0,0 +1,58 @@
+<?php
+namespace Elastica\Test\QueryBuilder\DSL;
+
+use Elastica\Filter\Exists;
+use Elastica\Query\Match;
+use Elastica\QueryBuilder\DSL;
+
+class FilterTest extends AbstractDSLTest
+{
+ /**
+ * @group unit
+ */
+ public function testType()
+ {
+ $filterDSL = new DSL\Filter();
+
+ $this->assertInstanceOf('Elastica\QueryBuilder\DSL', $filterDSL);
+ $this->assertEquals(DSL::TYPE_FILTER, $filterDSL->getType());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testInterface()
+ {
+ $filterDSL = new DSL\Filter();
+
+ $this->_assertImplemented($filterDSL, 'bool', 'Elastica\Filter\BoolFilter', array());
+ $this->_assertImplemented($filterDSL, 'bool_and', 'Elastica\Filter\BoolAnd', array(array(new Exists('field'))));
+ $this->_assertImplemented($filterDSL, 'bool_not', 'Elastica\Filter\BoolNot', array(new Exists('field')));
+ $this->_assertImplemented($filterDSL, 'bool_or', 'Elastica\Filter\BoolOr', array(array(new Exists('field'))));
+ $this->_assertImplemented($filterDSL, 'exists', 'Elastica\Filter\Exists', array('field'));
+ $this->_assertImplemented($filterDSL, 'geo_bounding_box', 'Elastica\Filter\GeoBoundingBox', array('field', array(1, 2)));
+ $this->_assertImplemented($filterDSL, 'geo_distance', 'Elastica\Filter\GeoDistance', array('key', 'location', 'distance'));
+ $this->_assertImplemented($filterDSL, 'geo_distance_range', 'Elastica\Filter\GeoDistanceRange', array('key', 'location'));
+ $this->_assertImplemented($filterDSL, 'geo_polygon', 'Elastica\Filter\GeoPolygon', array('key', array()));
+ $this->_assertImplemented($filterDSL, 'geo_shape_pre_indexed', 'Elastica\Filter\GeoShapePreIndexed', array('path', 'indexedId', 'indexedType', 'indexedIndex', 'indexedPath'));
+ $this->_assertImplemented($filterDSL, 'geo_shape_provided', 'Elastica\Filter\GeoShapeProvided', array('path', array()));
+ $this->_assertImplemented($filterDSL, 'geohash_cell', 'Elastica\Filter\GeohashCell', array('field', 'location'));
+ $this->_assertImplemented($filterDSL, 'has_child', 'Elastica\Filter\HasChild', array(new Match(), 'type'));
+ $this->_assertImplemented($filterDSL, 'has_parent', 'Elastica\Filter\HasParent', array(new Match(), 'type'));
+ $this->_assertImplemented($filterDSL, 'ids', 'Elastica\Filter\Ids', array('type', array()));
+ $this->_assertImplemented($filterDSL, 'indices', 'Elastica\Filter\Indices', array(new Exists('field'), array()));
+ $this->_assertImplemented($filterDSL, 'limit', 'Elastica\Filter\Limit', array(1));
+ $this->_assertImplemented($filterDSL, 'match_all', 'Elastica\Filter\MatchAll', array());
+ $this->_assertImplemented($filterDSL, 'missing', 'Elastica\Filter\Missing', array('field'));
+ $this->_assertImplemented($filterDSL, 'nested', 'Elastica\Filter\Nested', array());
+ $this->_assertImplemented($filterDSL, 'numeric_range', 'Elastica\Filter\NumericRange', array());
+ $this->_assertImplemented($filterDSL, 'prefix', 'Elastica\Filter\Prefix', array('field', 'prefix'));
+ $this->_assertImplemented($filterDSL, 'query', 'Elastica\Filter\Query', array(new Match()));
+ $this->_assertImplemented($filterDSL, 'range', 'Elastica\Filter\Range', array('field', array()));
+ $this->_assertImplemented($filterDSL, 'regexp', 'Elastica\Filter\Regexp', array('field', 'regex'));
+ $this->_assertImplemented($filterDSL, 'script', 'Elastica\Filter\Script', array('script'));
+ $this->_assertImplemented($filterDSL, 'term', 'Elastica\Filter\Term', array());
+ $this->_assertImplemented($filterDSL, 'terms', 'Elastica\Filter\Terms', array('field', array()));
+ $this->_assertImplemented($filterDSL, 'type', 'Elastica\Filter\Type', array('type'));
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/QueryTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/QueryTest.php
new file mode 100644
index 00000000..d4669119
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/QueryTest.php
@@ -0,0 +1,85 @@
+<?php
+namespace Elastica\Test\QueryBuilder\DSL;
+
+use Elastica\Filter\Exists;
+use Elastica\Query\Match;
+use Elastica\QueryBuilder\DSL;
+
+class QueryTest extends AbstractDSLTest
+{
+ /**
+ * @group unit
+ */
+ public function testType()
+ {
+ $queryDSL = new DSL\Query();
+
+ $this->assertInstanceOf('Elastica\QueryBuilder\DSL', $queryDSL);
+ $this->assertEquals(DSL::TYPE_QUERY, $queryDSL->getType());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testMatch()
+ {
+ $queryDSL = new DSL\Query();
+
+ $match = $queryDSL->match('field', 'match');
+ $this->assertEquals('match', $match->getParam('field'));
+ $this->assertInstanceOf('Elastica\Query\Match', $match);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testInterface()
+ {
+ $queryDSL = new DSL\Query();
+
+ $this->_assertImplemented($queryDSL, 'bool', 'Elastica\Query\BoolQuery', array());
+ $this->_assertImplemented($queryDSL, 'boosting', 'Elastica\Query\Boosting', array());
+ $this->_assertImplemented($queryDSL, 'common_terms', 'Elastica\Query\Common', array('field', 'query', 0.001));
+ $this->_assertImplemented($queryDSL, 'constant_score', 'Elastica\Query\ConstantScore', array(new Match()));
+ $this->_assertImplemented($queryDSL, 'dis_max', 'Elastica\Query\DisMax', array());
+ $this->_assertImplemented($queryDSL, 'filtered', 'Elastica\Query\Filtered', array(new Match(), new Exists('field')));
+ $this->_assertImplemented($queryDSL, 'function_score', 'Elastica\Query\FunctionScore', array());
+ $this->_assertImplemented($queryDSL, 'fuzzy', 'Elastica\Query\Fuzzy', array('field', 'type'));
+ $this->_assertImplemented($queryDSL, 'fuzzy_like_this', 'Elastica\Query\FuzzyLikeThis', array());
+ $this->_assertImplemented($queryDSL, 'has_child', 'Elastica\Query\HasChild', array(new Match()));
+ $this->_assertImplemented($queryDSL, 'has_parent', 'Elastica\Query\HasParent', array(new Match(), 'type'));
+ $this->_assertImplemented($queryDSL, 'ids', 'Elastica\Query\Ids', array('type', array()));
+ $this->_assertImplemented($queryDSL, 'match', 'Elastica\Query\Match', array('field', 'values'));
+ $this->_assertImplemented($queryDSL, 'match_all', 'Elastica\Query\MatchAll', array());
+ $this->_assertImplemented($queryDSL, 'more_like_this', 'Elastica\Query\MoreLikeThis', array());
+ $this->_assertImplemented($queryDSL, 'multi_match', 'Elastica\Query\MultiMatch', array());
+ $this->_assertImplemented($queryDSL, 'nested', 'Elastica\Query\Nested', array());
+ $this->_assertImplemented($queryDSL, 'prefix', 'Elastica\Query\Prefix', array());
+ $this->_assertImplemented($queryDSL, 'query_string', 'Elastica\Query\QueryString', array());
+ $this->_assertImplemented($queryDSL, 'range', 'Elastica\Query\Range', array('field', array()));
+ $this->_assertImplemented($queryDSL, 'regexp', 'Elastica\Query\Regexp', array('field', 'value', 1.0));
+ $this->_assertImplemented($queryDSL, 'simple_query_string', 'Elastica\Query\SimpleQueryString', array('query'));
+ $this->_assertImplemented($queryDSL, 'term', 'Elastica\Query\Term', array());
+ $this->_assertImplemented($queryDSL, 'terms', 'Elastica\Query\Terms', array('field', array()));
+ $this->_assertImplemented($queryDSL, 'top_children', 'Elastica\Query\TopChildren', array(new Match(), 'type'));
+ $this->_assertImplemented($queryDSL, 'wildcard', 'Elastica\Query\Wildcard', array());
+
+ $this->_assertNotImplemented($queryDSL, 'custom_boost_factor', array());
+ $this->_assertNotImplemented($queryDSL, 'custom_filters_score', array());
+ $this->_assertNotImplemented($queryDSL, 'custom_score', array());
+ $this->_assertNotImplemented($queryDSL, 'field', array());
+ $this->_assertNotImplemented($queryDSL, 'fuzzy_like_this_field', array());
+ $this->_assertNotImplemented($queryDSL, 'geo_shape', array());
+ $this->_assertNotImplemented($queryDSL, 'indices', array());
+ $this->_assertNotImplemented($queryDSL, 'minimum_should_match', array());
+ $this->_assertNotImplemented($queryDSL, 'more_like_this_field', array());
+ $this->_assertNotImplemented($queryDSL, 'span_first', array());
+ $this->_assertNotImplemented($queryDSL, 'span_multi_term', array());
+ $this->_assertNotImplemented($queryDSL, 'span_near', array());
+ $this->_assertNotImplemented($queryDSL, 'span_not', array());
+ $this->_assertNotImplemented($queryDSL, 'span_or', array());
+ $this->_assertNotImplemented($queryDSL, 'span_term', array());
+ $this->_assertNotImplemented($queryDSL, 'template', array());
+ $this->_assertNotImplemented($queryDSL, 'text', array());
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/SuggestTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/SuggestTest.php
new file mode 100644
index 00000000..b70e0ba7
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/DSL/SuggestTest.php
@@ -0,0 +1,32 @@
+<?php
+namespace Elastica\Test\QueryBuilder\DSL;
+
+use Elastica\QueryBuilder\DSL;
+
+class SuggestTest extends AbstractDSLTest
+{
+ /**
+ * @group unit
+ */
+ public function testType()
+ {
+ $suggestDSL = new DSL\Suggest();
+
+ $this->assertInstanceOf('Elastica\QueryBuilder\DSL', $suggestDSL);
+ $this->assertEquals(DSL::TYPE_SUGGEST, $suggestDSL->getType());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testInterface()
+ {
+ $suggestDSL = new DSL\Suggest();
+
+ $this->_assertImplemented($suggestDSL, 'completion', 'Elastica\Suggest\Completion', array('name', 'field'));
+ $this->_assertImplemented($suggestDSL, 'phrase', 'Elastica\Suggest\Phrase', array('name', 'field'));
+ $this->_assertImplemented($suggestDSL, 'term', 'Elastica\Suggest\Term', array('name', 'field'));
+
+ $this->_assertNotImplemented($suggestDSL, 'context', array());
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/VersionTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/VersionTest.php
new file mode 100644
index 00000000..d92848a7
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/QueryBuilder/VersionTest.php
@@ -0,0 +1,67 @@
+<?php
+namespace Elastica\Test\QueryBuilder;
+
+use Elastica\QueryBuilder\DSL;
+use Elastica\QueryBuilder\Version;
+use Elastica\Test\Base as BaseTest;
+
+class VersionTest extends BaseTest
+{
+ /**
+ * @group unit
+ */
+ public function testVersions()
+ {
+ $dsl = array(
+ new DSL\Query(),
+ new DSL\Filter(),
+ new DSL\Aggregation(),
+ new DSL\Suggest(),
+ );
+
+ $versions = array(
+ new Version\Version090(),
+ new Version\Version100(),
+ new Version\Version110(),
+ new Version\Version120(),
+ new Version\Version130(),
+ new Version\Version140(),
+ new Version\Version150(),
+ );
+
+ foreach ($versions as $version) {
+ $this->assertVersions($version, $dsl);
+ }
+ }
+
+ private function assertVersions(Version $version, array $dsl)
+ {
+ foreach ($version->getQueries() as $query) {
+ $this->assertTrue(
+ method_exists($dsl[0], $query),
+ 'query "'.$query.'" in '.get_class($version).' must be defined in '.get_class($dsl[0])
+ );
+ }
+
+ foreach ($version->getFilters() as $filter) {
+ $this->assertTrue(
+ method_exists($dsl[1], $filter),
+ 'filter "'.$filter.'" in '.get_class($version).' must be defined in '.get_class($dsl[1])
+ );
+ }
+
+ foreach ($version->getAggregations() as $aggregation) {
+ $this->assertTrue(
+ method_exists($dsl[2], $aggregation),
+ 'aggregation "'.$aggregation.'" in '.get_class($version).' must be defined in '.get_class($dsl[2])
+ );
+ }
+
+ foreach ($version->getSuggesters() as $suggester) {
+ $this->assertTrue(
+ method_exists($dsl[3], $suggester),
+ 'suggester "'.$suggester.'" in '.get_class($version).' must be defined in '.get_class($dsl[3])
+ );
+ }
+ }
+}