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
c040d36a
Commit
c040d36a
authored
May 09, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- unittest improvements and style fixes
parent
01c05ed2
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
350 additions
and
20 deletions
+350
-20
library/Solarium/Client.php
library/Solarium/Client.php
+6
-2
library/Solarium/Client/Request.php
library/Solarium/Client/Request.php
+1
-2
library/Solarium/Client/RequestBuilder/Select/Component/MoreLikeThis.php
...m/Client/RequestBuilder/Select/Component/MoreLikeThis.php
+1
-1
library/Solarium/Client/ResponseParser/Update.php
library/Solarium/Client/ResponseParser/Update.php
+0
-2
library/Solarium/Plugin/Abstract.php
library/Solarium/Plugin/Abstract.php
+16
-8
library/Solarium/Query/Select/Helper.php
library/Solarium/Query/Select/Helper.php
+1
-1
library/Solarium/Result/QueryType.php
library/Solarium/Result/QueryType.php
+1
-1
library/Solarium/Version.php
library/Solarium/Version.php
+1
-1
tests/Solarium/ClientTest.php
tests/Solarium/ClientTest.php
+70
-0
tests/Solarium/ConfigurableTest.php
tests/Solarium/ConfigurableTest.php
+22
-1
tests/Solarium/Plugin/AbstractTest.php
tests/Solarium/Plugin/AbstractTest.php
+62
-0
tests/Solarium/Query/PingTest.php
tests/Solarium/Query/PingTest.php
+48
-0
tests/Solarium/Query/SelectTest.php
tests/Solarium/Query/SelectTest.php
+32
-0
tests/Solarium/Query/UpdateTest.php
tests/Solarium/Query/UpdateTest.php
+5
-0
tests/Solarium/ResultTest.php
tests/Solarium/ResultTest.php
+77
-0
tests/bootstrap.php
tests/bootstrap.php
+7
-1
No files found.
library/Solarium/Client.php
View file @
c040d36a
...
...
@@ -231,6 +231,10 @@ class Solarium_Client extends Solarium_Configurable
public
function
registerPlugin
(
$key
,
$class
,
$options
=
array
())
{
$plugin
=
new
$class
(
$this
,
$options
);
if
(
!
(
$plugin
instanceof
Solarium_Plugin_Abstract
))
{
throw
new
Solarium_Exception
(
'All plugins must extend Solarium_Plugin_Abstract'
);
}
$this
->
_plugins
[
$key
]
=
$plugin
;
return
$this
;
...
...
@@ -285,8 +289,8 @@ class Solarium_Client extends Solarium_Configurable
*/
protected
function
_callPlugins
(
$event
,
$params
,
$resultOverride
=
false
)
{
foreach
(
$this
->
_plugins
AS
$plugin
)
{
$result
=
call_user_func_array
(
array
(
$plugin
,
$event
),
$params
);
foreach
(
$this
->
_plugins
AS
$plugin
)
{
$result
=
call_user_func_array
(
array
(
$plugin
,
$event
),
$params
);
if
(
$result
!==
null
&&
$resultOverride
)
{
return
$result
;
...
...
library/Solarium/Client/Request.php
View file @
c040d36a
...
...
@@ -289,11 +289,10 @@ class Solarium_Client_Request extends Solarium_Configurable
/**
* Add a request header
*
* @header string $key
* @header string|array $value
* @return Solarium_Client_Request
*/
public
function
addHeader
(
$
key
,
$
value
)
public
function
addHeader
(
$value
)
{
$this
->
_headers
[]
=
$value
;
...
...
library/Solarium/Client/RequestBuilder/Select/Component/MoreLikeThis.php
View file @
c040d36a
...
...
@@ -54,7 +54,7 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThis
public
function
build
(
$component
,
$request
)
{
// enable morelikethis
$request
->
addParam
(
'mlt'
,
'true'
);
$request
->
addParam
(
'mlt'
,
'true'
);
$request
->
addParam
(
'mlt.fl'
,
$component
->
getFields
());
$request
->
addParam
(
'mlt.mintf'
,
$component
->
getMinimumTermFrequency
());
...
...
library/Solarium/Client/ResponseParser/Update.php
View file @
c040d36a
...
...
@@ -53,8 +53,6 @@ class Solarium_Client_ResponseParser_Update extends Solarium_Client_ResponsePars
public
function
parse
(
$result
)
{
$data
=
$result
->
getData
();
$query
=
$result
->
getQuery
();
$resultClass
=
$query
->
getResultClass
();
return
array
(
'status'
=>
$data
[
'responseHeader'
][
'status'
],
...
...
library/Solarium/Plugin/Abstract.php
View file @
c040d36a
...
...
@@ -68,7 +68,8 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void|Solarium_Client_Request
*/
public
function
preCreateRequest
(
$query
)
{
}
{
}
/**
* @param Solarium_Query $query
...
...
@@ -76,14 +77,16 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void
*/
public
function
postCreateRequest
(
$query
,
$request
)
{
}
{
}
/**
* @param Solarium_Client_Request $request
* @return void|Solarium_Client_Response
*/
public
function
preExecuteRequest
(
$request
)
{
}
{
}
/**
* @param Solarium_Client_Request $request
...
...
@@ -91,7 +94,8 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void
*/
public
function
postExecuteRequest
(
$request
,
$response
)
{
}
{
}
/**
* @param Solarium_Query $query
...
...
@@ -99,7 +103,8 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void|Solarium_Result
*/
public
function
preCreateResult
(
$query
,
$response
)
{
}
{
}
/**
* @param Solarium_Query $query
...
...
@@ -108,14 +113,16 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void
*/
public
function
postCreateResult
(
$query
,
$response
,
$result
)
{
}
{
}
/**
* @param Solarium_Query $query
* @return void|Solarium_Result
*/
public
function
preExecute
(
$query
)
{
}
{
}
/**
* @param Solarium_Query $query
...
...
@@ -123,6 +130,7 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void
*/
public
function
postExecute
(
$query
,
$result
)
{
}
{
}
}
\ No newline at end of file
library/Solarium/Query/Select/Helper.php
View file @
c040d36a
...
...
@@ -173,7 +173,7 @@ class Solarium_Query_Select_Helper
*/
public
function
functionCall
(
$name
,
$params
=
array
())
{
return
$name
.
'('
.
implode
(
$params
,
','
)
.
')'
;
return
$name
.
'('
.
implode
(
$params
,
','
)
.
')'
;
}
}
\ No newline at end of file
library/Solarium/Result/QueryType.php
View file @
c040d36a
...
...
@@ -83,7 +83,7 @@ class Solarium_Result_QueryType extends Solarium_Result
*/
protected
function
_mapData
(
$mapData
)
{
foreach
(
$mapData
AS
$key
=>
$data
)
{
foreach
(
$mapData
AS
$key
=>
$data
)
{
$this
->
{
'_'
.
$key
}
=
$data
;
}
}
...
...
library/Solarium/Version.php
View file @
c040d36a
...
...
@@ -69,7 +69,7 @@ class Solarium_Version
*
* @var string
*/
const
VERSION
=
'
1
.0.0'
;
const
VERSION
=
'
2
.0.0'
;
/**
...
...
tests/Solarium/ClientTest.php
View file @
c040d36a
...
...
@@ -56,6 +56,76 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$this
->
assertThat
(
$client
->
getAdapter
(),
$this
->
isInstanceOf
(
$adapterClass
));
}
public
function
testRegisterQueryTypeAndGetQueryTypes
()
{
}
public
function
testRegisterAndGetPlugin
()
{
}
public
function
testRemoveAndGetPlugins
()
{
}
public
function
testCreateRequest
()
{
}
public
function
testCreateRequestInvalidQueryType
()
{
}
public
function
testCreateRequestWithOverridingPlugin
()
{
}
public
function
testCreateRequestPostPlugin
()
{
}
public
function
testCreateResult
()
{
}
public
function
testCreateResultInvalidQueryType
()
{
}
public
function
testCreateResultWithOverridingPlugin
()
{
}
public
function
testCreateResultPostPlugin
()
{
}
public
function
testPing
()
{
}
public
function
testSelect
()
{
}
public
function
testUpdate
()
{
}
}
class
MyAdapter
extends
Solarium_Client_Adapter_Http
{
...
...
tests/Solarium/ConfigurableTest.php
View file @
c040d36a
...
...
@@ -98,7 +98,28 @@ class Solarium_ConfigurableTest extends PHPUnit_Framework_TestCase
$this
->
setExpectedException
(
'Solarium_Exception'
);
new
ConfigTestInit
;
}
public
function
testSetOptions
()
{
$configTest
=
new
ConfigTest
();
$configTest
->
setOptions
(
array
(
'option2'
=>
2
,
'option3'
=>
3
));
$this
->
assertEquals
(
array
(
'option1'
=>
1
,
'option2'
=>
2
,
'option3'
=>
3
),
$configTest
->
getOptions
()
);
}
public
function
testSetOptionsWithOverride
()
{
$configTest
=
new
ConfigTest
();
$configTest
->
setOptions
(
array
(
'option2'
=>
2
,
'option3'
=>
3
),
true
);
$this
->
assertEquals
(
array
(
'option2'
=>
2
,
'option3'
=>
3
),
$configTest
->
getOptions
()
);
}
}
class
ConfigTest
extends
Solarium_Configurable
...
...
tests/Solarium/Plugin/AbstractTest.php
0 → 100644
View file @
c040d36a
<?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_Plugin_AbstractTest
extends
PHPUnit_Framework_TestCase
{
public
function
testConstructor
()
{
$client
=
'dummy'
;
$options
=
array
(
'option1'
=>
1
);
$plugin
=
new
MyPlugin
(
$client
,
$options
);
$this
->
assertEquals
(
$client
,
$plugin
->
getClient
()
);
$this
->
assertEquals
(
$options
,
$plugin
->
getOptions
()
);
}
}
class
MyPlugin
extends
Solarium_Plugin_Abstract
{
public
function
getClient
()
{
return
$this
->
_client
;
}
}
\ No newline at end of file
tests/Solarium/Query/PingTest.php
0 → 100644
View file @
c040d36a
<?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_PingTest
extends
PHPUnit_Framework_TestCase
{
protected
$_query
;
public
function
setUp
()
{
$this
->
_query
=
new
Solarium_Query_Ping
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Client
::
QUERYTYPE_PING
,
$this
->
_query
->
getType
());
}
}
\ No newline at end of file
tests/Solarium/Query/SelectTest.php
View file @
c040d36a
...
...
@@ -39,6 +39,11 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$this
->
_query
=
new
Solarium_Query_Select
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Client
::
QUERYTYPE_SELECT
,
$this
->
_query
->
getType
());
}
public
function
testSetAndGetStart
()
{
$this
->
_query
->
setStart
(
234
);
...
...
@@ -479,6 +484,16 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
);
}
public
function
testGetHighlighting
()
{
$dismax
=
$this
->
_query
->
getHighlighting
();
$this
->
assertEquals
(
'Solarium_Query_Select_Component_Highlighting'
,
get_class
(
$dismax
)
);
}
public
function
testGetHelper
()
{
$helper
=
$this
->
_query
->
getHelper
();
...
...
@@ -488,4 +503,21 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
get_class
(
$helper
)
);
}
public
function
testRegisterComponentType
()
{
$components
=
$this
->
_query
->
getComponentTypes
();
$components
[
'mykey'
]
=
array
(
'component'
=>
'mycomponent'
,
'requestbuilder'
=>
'mybuilder'
,
'responseparser'
=>
'myparser'
,
);
$this
->
_query
->
registerComponentType
(
'mykey'
,
'mycomponent'
,
'mybuilder'
,
'myparser'
);
$this
->
assertEquals
(
$components
,
$this
->
_query
->
getComponentTypes
()
);
}
}
\ No newline at end of file
tests/Solarium/Query/UpdateTest.php
View file @
c040d36a
...
...
@@ -39,6 +39,11 @@ class Solarium_Query_UpdateTest extends PHPUnit_Framework_TestCase
$this
->
_query
=
new
Solarium_Query_Update
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Client
::
QUERYTYPE_UPDATE
,
$this
->
_query
->
getType
());
}
public
function
testAddWithoutKey
()
{
$command
=
new
Solarium_Query_Update_Command_Rollback
;
...
...
tests/Solarium/ResultTest.php
0 → 100644
View file @
c040d36a
<?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_ResultTest
extends
PHPUnit_Framework_TestCase
{
protected
$_client
,
$_query
,
$_response
,
$_result
;
public
function
setUp
()
{
$this
->
_client
=
new
Solarium_Client
();
$this
->
_query
=
new
Solarium_Query_Select
();
$headers
=
array
(
'HTTP/1.0 304 Not Modified'
);
$data
=
'{"responseHeader":{"status":0,"QTime":1,"params":{"wt":"json","q":"xyz"}},"response":{"numFound":0,"start":0,"docs":[]}}'
;
$this
->
_response
=
new
Solarium_Client_Response
(
$data
,
$headers
);
$this
->
_result
=
new
Solarium_Result
(
$this
->
_client
,
$this
->
_query
,
$this
->
_response
);
}
public
function
testResultWithErrorResponse
()
{
$headers
=
array
(
'HTTP/1.0 404 Not Found'
);
$response
=
new
Solarium_Client_Response
(
''
,
$headers
);
$this
->
setExpectedException
(
'Solarium_Exception'
);
new
Solarium_Result
(
$this
->
_client
,
$this
->
_query
,
$response
);
}
public
function
testGetResponse
()
{
$this
->
assertEquals
(
$this
->
_response
,
$this
->
_result
->
getResponse
());
}
public
function
testGetQuery
()
{
$this
->
assertEquals
(
$this
->
_query
,
$this
->
_result
->
getQuery
());
}
public
function
testGetData
()
{
$data
=
array
(
'responseHeader'
=>
array
(
'status'
=>
0
,
'QTime'
=>
1
,
'params'
=>
array
(
'wt'
=>
'json'
,
'q'
=>
'xyz'
)),
'response'
=>
array
(
'numFound'
=>
0
,
'start'
=>
0
,
'docs'
=>
array
())
);
$this
->
assertEquals
(
$data
,
$this
->
_result
->
getData
());
}
}
\ No newline at end of file
tests/bootstrap.php
View file @
c040d36a
...
...
@@ -42,5 +42,11 @@ set_include_path(implode(PATH_SEPARATOR, array(
get_include_path
(),
)));
function
solariumUnittestAutoload
(
$class
)
{
@
include
(
str_replace
(
"_"
,
DIRECTORY_SEPARATOR
,
$class
)
.
".php"
);
}
// set up an autoload for Zend / Pear style class loading
spl_autoload_register
(
create_function
(
'$class'
,
'@include(str_replace("_", DIRECTORY_SEPARATOR, $class) . ".php");'
));
\ No newline at end of file
spl_autoload_register
(
'solariumUnittestAutoload'
);
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