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
e5700ef2
Commit
e5700ef2
authored
May 14, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- unittest improvements
parent
36440380
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
10 deletions
+75
-10
library/Solarium/Client.php
library/Solarium/Client.php
+13
-7
tests/Solarium/ClientTest.php
tests/Solarium/ClientTest.php
+62
-3
No files found.
library/Solarium/Client.php
View file @
e5700ef2
<?php
<?php
/**
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
* Copyright 2011 Bas de Nooijer. All rights reserved.
...
@@ -196,8 +197,8 @@ class Solarium_Client extends Solarium_Configurable
...
@@ -196,8 +197,8 @@ class Solarium_Client extends Solarium_Configurable
* You can also use this method to override any existing querytype with a new mapping
* You can also use this method to override any existing querytype with a new mapping
*
*
* @param string $type
* @param string $type
* @param string $requestBuilder
* @param string
|object
$requestBuilder
* @param string $responseParser
* @param string
|object
$responseParser
* @return Solarium_Client Provides fluent interface
* @return Solarium_Client Provides fluent interface
*/
*/
public
function
registerQueryType
(
$type
,
$requestBuilder
,
$responseParser
)
public
function
registerQueryType
(
$type
,
$requestBuilder
,
$responseParser
)
...
@@ -224,13 +225,16 @@ class Solarium_Client extends Solarium_Configurable
...
@@ -224,13 +225,16 @@ class Solarium_Client extends Solarium_Configurable
* Register a plugin
* Register a plugin
*
*
* @param string $key
* @param string $key
* @param string
$class
* @param string
|object $plugin
* @param array $options
* @param array $options
* @return Solarium_Client Provides fluent interface
* @return Solarium_Client Provides fluent interface
*/
*/
public
function
registerPlugin
(
$key
,
$
class
,
$options
=
array
())
public
function
registerPlugin
(
$key
,
$
plugin
,
$options
=
array
())
{
{
$plugin
=
new
$class
(
$this
,
$options
);
if
(
is_string
(
$plugin
))
{
$plugin
=
new
$plugin
(
$this
,
$options
);
}
if
(
!
(
$plugin
instanceof
Solarium_Plugin_Abstract
))
{
if
(
!
(
$plugin
instanceof
Solarium_Plugin_Abstract
))
{
throw
new
Solarium_Exception
(
'All plugins must extend Solarium_Plugin_Abstract'
);
throw
new
Solarium_Exception
(
'All plugins must extend Solarium_Plugin_Abstract'
);
}
}
...
@@ -316,8 +320,10 @@ class Solarium_Client extends Solarium_Configurable
...
@@ -316,8 +320,10 @@ class Solarium_Client extends Solarium_Configurable
throw
new
Solarium_Exception
(
'No requestbuilder registered for querytype: '
.
$queryType
);
throw
new
Solarium_Exception
(
'No requestbuilder registered for querytype: '
.
$queryType
);
}
}
$requestBuilderClass
=
$this
->
_queryTypes
[
$queryType
][
'requestbuilder'
];
$requestBuilder
=
$this
->
_queryTypes
[
$queryType
][
'requestbuilder'
];
$requestBuilder
=
new
$requestBuilderClass
;
if
(
is_string
(
$requestBuilder
))
{
$requestBuilder
=
new
$requestBuilder
;
}
$request
=
$requestBuilder
->
build
(
$query
);
$request
=
$requestBuilder
->
build
(
$query
);
$this
->
_callPlugins
(
'postCreateRequest'
,
array
(
$query
,
$request
));
$this
->
_callPlugins
(
'postCreateRequest'
,
array
(
$query
,
$request
));
...
...
tests/Solarium/ClientTest.php
View file @
e5700ef2
...
@@ -137,22 +137,76 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
...
@@ -137,22 +137,76 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
public
function
testCreateRequest
()
public
function
testCreateRequest
()
{
{
$queryStub
=
$this
->
getMock
(
'Solarium_Query_Select'
);
$queryStub
->
expects
(
$this
->
any
())
->
method
(
'getType'
)
->
will
(
$this
->
returnValue
(
'testquerytype'
));
$observer
=
$this
->
getMock
(
'Solarium_Client_RequestBuilder'
,
array
(
'build'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'build'
)
->
with
(
$this
->
equalTo
(
$queryStub
));
$this
->
_client
->
registerQueryType
(
'testquerytype'
,
$observer
,
''
);
$this
->
_client
->
createRequest
(
$queryStub
);
}
}
public
function
testCreateRequestInvalidQueryType
()
public
function
testCreateRequestInvalidQueryType
()
{
{
$queryStub
=
$this
->
getMock
(
'Solarium_Query_Select'
);
$queryStub
->
expects
(
$this
->
any
())
->
method
(
'getType'
)
->
will
(
$this
->
returnValue
(
'testquerytype'
));
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_client
->
createRequest
(
$queryStub
);
}
public
function
testCreateRequestPrePlugin
()
{
$query
=
new
Solarium_Query_Select
();
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'preCreateRequest'
)
->
with
(
$this
->
equalTo
(
$query
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$this
->
_client
->
createRequest
(
$query
);
}
}
public
function
testCreateRequestPlugin
()
public
function
testCreateRequestP
ostP
lugin
()
{
{
$query
=
new
Solarium_Query_Select
();
$request
=
$this
->
_client
->
createRequest
(
$query
);
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'postCreateRequest'
)
->
with
(
$this
->
equalTo
(
$query
),
$this
->
equalTo
(
$request
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$this
->
_client
->
createRequest
(
$query
);
}
}
public
function
testCreateRequestWithOverridingPlugin
()
public
function
testCreateRequestWithOverridingPlugin
()
{
{
$overrideValue
=
'dummyvalue'
;
$query
=
new
Solarium_Query_Select
();
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'preCreateRequest'
)
->
with
(
$this
->
equalTo
(
$query
))
->
will
(
$this
->
returnValue
(
$overrideValue
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$request
=
$this
->
_client
->
createRequest
(
$query
);
$this
->
assertEquals
(
$overrideValue
,
$request
);
}
}
public
function
testCreateResult
()
public
function
testCreateResult
()
...
@@ -165,7 +219,12 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
...
@@ -165,7 +219,12 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
}
}
public
function
testCreateResultPlugin
()
public
function
testCreateResultPrePlugin
()
{
}
public
function
testCreateResultPostPlugin
()
{
{
}
}
...
...
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