Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
Elasticsearch DSL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public
Elasticsearch DSL
Commits
30fb9aef
Commit
30fb9aef
authored
9 years ago
by
Mantas Varatiejus
Browse files
Options
Downloads
Patches
Plain Diff
Deprecate filters
parent
a644572a
No related branches found
No related tags found
No related merge requests found
Changes
63
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/Query/NestedQueryTest.php
+37
-30
37 additions, 30 deletions
tests/Query/NestedQueryTest.php
tests/Query/ScriptQueryTest.php
+54
-0
54 additions, 0 deletions
tests/Query/ScriptQueryTest.php
tests/Query/TypeQueryTest.php
+27
-0
27 additions, 0 deletions
tests/Query/TypeQueryTest.php
with
118 additions
and
30 deletions
tests/Query/NestedQueryTest.php
+
37
−
30
View file @
30fb9aef
...
...
@@ -13,51 +13,58 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\DSL\Query;
use
ONGR\ElasticsearchDSL\Query\BoolQuery
;
use
ONGR\ElasticsearchDSL\Query\NestedQuery
;
use
ONGR\ElasticsearchDSL\Query\TermsQuery
;
use
ONGR\ElasticsearchDSL\Query\TermQuery
;
class
NestedQueryTest
extends
\PHPUnit_Framework_TestCase
{
/**
* Tests toArray method.
* Data provider to testGetToArray.
*
* @return array
*/
public
function
testToArray
()
public
function
getArrayDataProvider
()
{
$missingFilterMock
=
$this
->
getMockBuilder
(
'ONGR\ElasticsearchDSL\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
=
[
'terms'
=>
[
'foo'
=>
'bar'
,
],
];
$query
=
new
NestedQuery
(
'test_path'
,
$missingFilterMock
);
$this
->
assertEquals
(
$result
,
$query
->
toArray
());
return
[
'query_only'
=>
[
'product.sub_item'
,
[],
[
'path'
=>
'product.sub_item'
,
'query'
=>
$query
],
],
'query_with_parameters'
=>
[
'product.sub_item'
,
[
'_cache'
=>
true
,
'_name'
=>
'named_result'
],
[
'path'
=>
'product.sub_item'
,
'query'
=>
$query
,
'_cache'
=>
true
,
'_name'
=>
'named_result'
,
],
],
];
}
/**
* Tests if Nested Query has parameters.
* Test for query toArray() method.
*
* @param string $path
* @param array $parameters
* @param array $expected
*
* @dataProvider getArrayDataProvider
*/
public
function
test
Parameters
(
)
public
function
test
ToArray
(
$path
,
$parameters
,
$expected
)
{
$nestedQuery
=
$this
->
getMockBuilder
(
'ONGR\ElasticsearchDSL\Query\NestedQuery'
)
->
disableOriginalConstructor
()
->
setMethods
(
null
)
->
getMock
();
$this
->
assertTrue
(
method_exists
(
$nestedQuery
,
'addParameter'
),
'Nested query must have addParameter method'
);
$this
->
assertTrue
(
method_exists
(
$nestedQuery
,
'setParameters'
),
'Nested query must have setParameters method'
);
$this
->
assertTrue
(
method_exists
(
$nestedQuery
,
'getParameters'
),
'Nested query must have getParameters method'
);
$this
->
assertTrue
(
method_exists
(
$nestedQuery
,
'hasParameter'
),
'Nested query must have hasParameter method'
);
$this
->
assertTrue
(
method_exists
(
$nestedQuery
,
'getParameter'
),
'Nested query must have getParameter method'
);
$query
=
new
TermsQuery
(
'foo'
,
'bar'
);
$query
=
new
NestedQuery
(
$path
,
$query
,
$parameters
);
$result
=
$query
->
toArray
();
$this
->
assertEquals
(
$expected
,
$result
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
tests/Query/ScriptQueryTest.php
0 → 100644
+
54
−
0
View file @
30fb9aef
<?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\Unit\DSL\Query
;
use
ONGR\ElasticsearchDSL\Query\ScriptQuery
;
class
ScriptQueryTest
extends
\PHPUnit_Framework_TestCase
{
/**
* Data provider for testToArray().
*
* @return array
*/
public
function
getArrayDataProvider
()
{
return
[
'simple_script'
=>
[
"doc['num1'].value > 1"
,
[],
[
'script'
=>
[
'inline'
=>
"doc['num1'].value > 1"
]],
],
'script_with_parameters'
=>
[
"doc['num1'].value > param1"
,
[
'params'
=>
[
'param1'
=>
5
]],
[
'script'
=>
[
'inline'
=>
"doc['num1'].value > param1"
,
'params'
=>
[
'param1'
=>
5
]]],
],
];
}
/**
* Test for filter toArray() method.
*
* @param string $script Script.
* @param array $parameters Optional parameters.
* @param array $expected Expected values.
*
* @dataProvider getArrayDataProvider
*/
public
function
testToArray
(
$script
,
$parameters
,
$expected
)
{
$filter
=
new
ScriptQuery
(
$script
,
$parameters
);
$result
=
$filter
->
toArray
();
$this
->
assertEquals
(
$expected
,
$result
);
}
}
This diff is collapsed.
Click to expand it.
tests/Query/TypeQueryTest.php
0 → 100644
+
27
−
0
View file @
30fb9aef
<?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\Unit\DSL\Query
;
use
ONGR\ElasticsearchDSL\Query\TypeQuery
;
class
TypeQueryTest
extends
\PHPUnit_Framework_TestCase
{
/**
* Test for query toArray() method.
*/
public
function
testToArray
()
{
$query
=
new
TypeQuery
(
'foo'
);
$expectedResult
=
[
'value'
=>
'foo'
];
$this
->
assertEquals
(
$expectedResult
,
$query
->
toArray
());
}
}
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment