Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
84332b28
Commit
84332b28
authored
Jan 13, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unittest coverage for suggester query (and related classes)
parent
4c35b3ac
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
550 additions
and
1 deletion
+550
-1
library/Solarium/Result/Suggester/Term.php
library/Solarium/Result/Suggester/Term.php
+1
-1
tests/Solarium/Client/RequestBuilder/SuggesterTest.php
tests/Solarium/Client/RequestBuilder/SuggesterTest.php
+80
-0
tests/Solarium/Client/ResponseParser/SuggesterTest.php
tests/Solarium/Client/ResponseParser/SuggesterTest.php
+91
-0
tests/Solarium/ClientTest.php
tests/Solarium/ClientTest.php
+24
-0
tests/Solarium/Query/SuggesterTest.php
tests/Solarium/Query/SuggesterTest.php
+105
-0
tests/Solarium/Result/Suggester/TermTest.php
tests/Solarium/Result/Suggester/TermTest.php
+123
-0
tests/Solarium/Result/SuggesterTest.php
tests/Solarium/Result/SuggesterTest.php
+126
-0
No files found.
library/Solarium/Result/Suggester/Term.php
View file @
84332b28
...
...
@@ -42,7 +42,7 @@
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Suggester_
t
erm
implements
IteratorAggregate
,
Countable
class
Solarium_Result_Suggester_
T
erm
implements
IteratorAggregate
,
Countable
{
/**
...
...
tests/Solarium/Client/RequestBuilder/SuggesterTest.php
0 → 100644
View file @
84332b28
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Client_RequestBuilder_SuggesterTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Suggester
*/
protected
$_query
;
/**
* @var Solarium_Client_RequestBuilder_Suggester
*/
protected
$_builder
;
public
function
setUp
()
{
$this
->
_query
=
new
Solarium_Query_Suggester
;
$this
->
_builder
=
new
Solarium_Client_RequestBuilder_Suggester
;
}
public
function
testBuildParams
()
{
$this
->
_query
->
setCollate
(
true
);
$this
->
_query
->
setCount
(
13
);
$this
->
_query
->
setDictionary
(
'suggest'
);
$this
->
_query
->
setQuery
(
'ap ip'
);
$this
->
_query
->
setOnlyMorePopular
(
true
);
$request
=
$this
->
_builder
->
build
(
$this
->
_query
);
$this
->
assertEquals
(
array
(
'spellcheck'
=>
'true'
,
'q'
=>
'ap ip'
,
'spellcheck.dictionary'
=>
'suggest'
,
'spellcheck.count'
=>
13
,
'spellcheck.onlyMorePopular'
=>
'true'
,
'spellcheck.collate'
=>
'true'
,
'wt'
=>
'json'
,
),
$request
->
getParams
()
);
$this
->
assertEquals
(
Solarium_Client_Request
::
METHOD_GET
,
$request
->
getMethod
()
);
}
}
\ No newline at end of file
tests/Solarium/Client/ResponseParser/SuggesterTest.php
0 → 100644
View file @
84332b28
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Client_ResponseParser_SuggesterTest
extends
PHPUnit_Framework_TestCase
{
public
function
testParse
()
{
$data
=
array
(
'responseHeader'
=>
array
(
'status'
=>
1
,
'QTime'
=>
13
,
),
'spellcheck'
=>
array
(
'suggestions'
=>
array
(
'd'
,
array
(
'numFound'
=>
2
,
'startOffset'
=>
3
,
'endOffset'
=>
7
,
'suggestion'
=>
array
(
'disk'
,
'ddr'
)
),
'vid'
,
array
(
'numFound'
=>
1
,
'startOffset'
=>
2
,
'endOffset'
=>
5
,
'suggestion'
=>
array
(
'video'
,
)
),
'collation'
,
'disk video'
),
),
);
$query
=
new
Solarium_Query_Suggester
();
$resultStub
=
$this
->
getMock
(
'Solarium_Result_Suggester'
,
array
(),
array
(),
''
,
false
);
$resultStub
->
expects
(
$this
->
any
())
->
method
(
'getData'
)
->
will
(
$this
->
returnValue
(
$data
));
$resultStub
->
expects
(
$this
->
any
())
->
method
(
'getQuery'
)
->
will
(
$this
->
returnValue
(
$query
));
$parser
=
new
Solarium_Client_ResponseParser_Suggester
;
$result
=
$parser
->
parse
(
$resultStub
);
$expected
=
array
(
'd'
=>
new
Solarium_Result_Suggester_Term
(
2
,
3
,
7
,
array
(
'disk'
,
'ddr'
)),
'vid'
=>
new
Solarium_Result_Suggester_Term
(
1
,
2
,
5
,
array
(
'video'
))
);
$this
->
assertEquals
(
$expected
,
$result
[
'results'
]);
$this
->
assertEquals
(
'disk video'
,
$result
[
'collation'
]);
}
}
tests/Solarium/ClientTest.php
View file @
84332b28
...
...
@@ -656,6 +656,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer
->
terms
(
$query
);
}
public
function
testSuggester
()
{
$query
=
new
Solarium_Query_Suggester
();
$observer
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'execute'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$query
));
$observer
->
suggester
(
$query
);
}
public
function
testCreateQuery
()
{
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
...
...
@@ -812,6 +824,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer
->
createTerms
(
$options
);
}
public
function
testCreateSuggester
()
{
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
$observer
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'createQuery'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'createQuery'
)
->
with
(
$this
->
equalTo
(
Solarium_Client
::
QUERYTYPE_SUGGESTER
),
$this
->
equalTo
(
$options
));
$observer
->
createSuggester
(
$options
);
}
public
function
testTriggerEvent
()
{
$eventName
=
'Test'
;
...
...
tests/Solarium/Query/SuggesterTest.php
0 → 100644
View file @
84332b28
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Query_SuggesterTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Suggester
*/
protected
$_query
;
public
function
setUp
()
{
$this
->
_query
=
new
Solarium_Query_Suggester
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Client
::
QUERYTYPE_SUGGESTER
,
$this
->
_query
->
getType
());
}
public
function
testSetAndGetQuery
()
{
$value
=
'testquery'
;
$this
->
_query
->
setQuery
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getQuery
()
);
}
public
function
testSetAndGetDictionary
()
{
$value
=
'myDictionary'
;
$this
->
_query
->
setDictionary
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getDictionary
()
);
}
public
function
testSetAndGetCount
()
{
$value
=
11
;
$this
->
_query
->
setCount
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getCount
()
);
}
public
function
testSetAndGetOnlyMorePopular
()
{
$value
=
false
;
$this
->
_query
->
setOnlyMorePopular
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getOnlyMorePopular
()
);
}
public
function
testSetAndGetCollate
()
{
$value
=
false
;
$this
->
_query
->
setCollate
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getCollate
()
);
}
}
\ No newline at end of file
tests/Solarium/Result/Suggester/TermTest.php
0 → 100644
View file @
84332b28
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Result_Suggester_TermTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Suggester_Term
*/
protected
$_result
;
/**
* @var int
*/
protected
$_numFound
;
/**
* @var int
*/
protected
$_startOffset
;
/**
* @var int
*/
protected
$_endOffset
;
/**
* @var array
*/
protected
$_suggestions
;
public
function
setUp
()
{
$this
->
_numFound
=
5
;
$this
->
_startOffset
=
2
;
$this
->
_endOffset
=
6
;
$this
->
_suggestions
=
array
(
'suggestion1'
,
'suggestion2'
,
);
$this
->
_result
=
new
Solarium_Result_Suggester_Term
(
$this
->
_numFound
,
$this
->
_startOffset
,
$this
->
_endOffset
,
$this
->
_suggestions
);
}
public
function
testGetNumFound
()
{
$this
->
assertEquals
(
$this
->
_numFound
,
$this
->
_result
->
getNumFound
()
);
}
public
function
testGetStartOffset
()
{
$this
->
assertEquals
(
$this
->
_startOffset
,
$this
->
_result
->
getStartOffset
()
);
}
public
function
testGetEndOffset
()
{
$this
->
assertEquals
(
$this
->
_endOffset
,
$this
->
_result
->
getEndOffset
()
);
}
public
function
testGetSuggestions
()
{
$this
->
assertEquals
(
$this
->
_suggestions
,
$this
->
_result
->
getSuggestions
()
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_suggestions
),
count
(
$this
->
_result
));
}
public
function
testIterator
()
{
$results
=
array
();
foreach
(
$this
->
_result
AS
$key
=>
$doc
)
{
$results
[
$key
]
=
$doc
;
}
$this
->
assertEquals
(
$this
->
_suggestions
,
$results
);
}
}
\ No newline at end of file
tests/Solarium/Result/SuggesterTest.php
0 → 100644
View file @
84332b28
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Result_SuggesterTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Suggester
*/
protected
$_result
;
/**
* @var array
*/
protected
$_data
;
/**
* @var string
*/
protected
$_collation
;
public
function
setUp
()
{
$this
->
_data
=
array
(
'term1'
=>
'data1'
,
'term2'
=>
'data2'
,
);
$this
->
_collation
=
'collation result'
;
$this
->
_result
=
new
Solarium_Result_SuggesterDummy
(
$this
->
_data
,
$this
->
_collation
);
}
public
function
testGetStatus
()
{
$this
->
assertEquals
(
1
,
$this
->
_result
->
getStatus
()
);
}
public
function
testGetQueryTime
()
{
$this
->
assertEquals
(
12
,
$this
->
_result
->
getQueryTime
()
);
}
public
function
testGetResults
()
{
$this
->
assertEquals
(
$this
->
_data
,
$this
->
_result
->
getResults
());
}
public
function
testGetTerm
()
{
$this
->
assertEquals
(
$this
->
_data
[
'term1'
],
$this
->
_result
->
getTerm
(
'term1'
));
}
public
function
testGetTermsWithInvalidFieldName
()
{
$this
->
assertEquals
(
array
(),
$this
->
_result
->
getTerm
(
'term3'
));
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_data
),
count
(
$this
->
_result
));
}
public
function
testIterator
()
{
$results
=
array
();
foreach
(
$this
->
_result
AS
$key
=>
$doc
)
{
$results
[
$key
]
=
$doc
;
}
$this
->
assertEquals
(
$this
->
_data
,
$results
);
}
public
function
testGetCollation
()
{
$this
->
assertEquals
(
$this
->
_collation
,
$this
->
_result
->
getCollation
());
}
}
class
Solarium_Result_SuggesterDummy
extends
Solarium_Result_Suggester
{
protected
$_parsed
=
true
;
public
function
__construct
(
$results
,
$collation
)
{
$this
->
_results
=
$results
;
$this
->
_collation
=
$collation
;
$this
->
_status
=
1
;
$this
->
_queryTime
=
12
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment