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
995bcabb
Commit
995bcabb
authored
May 14, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- unittest improvements
parent
e5700ef2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
241 additions
and
22 deletions
+241
-22
tests/Solarium/ClientTest.php
tests/Solarium/ClientTest.php
+241
-22
No files found.
tests/Solarium/ClientTest.php
View file @
995bcabb
...
@@ -102,7 +102,7 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
...
@@ -102,7 +102,7 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
public
function
testRegisterInvalidPlugin
()
public
function
testRegisterInvalidPlugin
()
{
{
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_client
->
registerPlugin
(
'testplugin'
,
'
MyInvalidClientPlugin
'
);
$this
->
_client
->
registerPlugin
(
'testplugin'
,
'
StdClass
'
);
}
}
public
function
testGetInvalidPlugin
()
public
function
testGetInvalidPlugin
()
...
@@ -211,74 +211,293 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
...
@@ -211,74 +211,293 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
public
function
testCreateResult
()
public
function
testCreateResult
()
{
{
$query
=
new
Solarium_Query_Select
();
$response
=
new
Solarium_Client_Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$result
=
$this
->
_client
->
createResult
(
$query
,
$response
);
$this
->
assertThat
(
$result
,
$this
->
isInstanceOf
(
$query
->
getResultClass
())
);
}
}
public
function
testCreateResult
InvalidQueryType
()
public
function
testCreateResult
PrePlugin
()
{
{
$query
=
new
Solarium_Query_Select
();
$response
=
new
Solarium_Client_Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'preCreateResult'
)
->
with
(
$this
->
equalTo
(
$query
),
$this
->
equalTo
(
$response
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$this
->
_client
->
createResult
(
$query
,
$response
);
}
}
public
function
testCreateResultP
re
Plugin
()
public
function
testCreateResultP
ost
Plugin
()
{
{
$query
=
new
Solarium_Query_Select
();
$response
=
new
Solarium_Client_Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$result
=
$this
->
_client
->
createResult
(
$query
,
$response
);
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'postCreateResult'
)
->
with
(
$this
->
equalTo
(
$query
),
$this
->
equalTo
(
$response
),
$this
->
equalTo
(
$result
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$this
->
_client
->
createResult
(
$query
,
$response
);
}
}
public
function
testCreateResult
Post
Plugin
()
public
function
testCreateResult
WithOverriding
Plugin
()
{
{
$overrideValue
=
'dummyvalue'
;
$query
=
new
Solarium_Query_Select
();
$response
=
new
Solarium_Client_Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'preCreateResult'
)
->
with
(
$this
->
equalTo
(
$query
),
$this
->
equalTo
(
$response
))
->
will
(
$this
->
returnValue
(
$overrideValue
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$result
=
$this
->
_client
->
createResult
(
$query
,
$response
);
$this
->
assertEquals
(
$overrideValue
,
$result
);
}
}
public
function
test
CreateResultWithOverridingPlugin
()
public
function
test
Execute
()
{
{
$query
=
new
Solarium_Query_Ping
();
$observer
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'createRequest'
,
'executeRequest'
,
'createResult'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'createRequest'
)
->
with
(
$this
->
equalTo
(
$query
))
->
will
(
$this
->
returnValue
(
'dummyrequest'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'executeRequest'
)
->
with
(
$this
->
equalTo
(
'dummyrequest'
))
->
will
(
$this
->
returnValue
(
'dummyresponse'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'createResult'
)
->
with
(
$this
->
equalTo
(
$query
),
$this
->
equalTo
(
'dummyresponse'
));
$observer
->
execute
(
$query
);
}
}
public
function
test
Ping
()
public
function
test
ExecutePrePlugin
()
{
{
$query
=
new
Solarium_Query_Ping
();
$mock
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'createRequest'
,
'executeRequest'
,
'createResult'
));
$mock
->
expects
(
$this
->
once
())
->
method
(
'createRequest'
)
->
will
(
$this
->
returnValue
(
'dummyrequest'
));
$mock
->
expects
(
$this
->
once
())
->
method
(
'executeRequest'
)
->
will
(
$this
->
returnValue
(
'dummyresponse'
));
$mock
->
expects
(
$this
->
once
())
->
method
(
'createResult'
)
->
will
(
$this
->
returnValue
(
'dummyresult'
));
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'preExecute'
)
->
with
(
$this
->
equalTo
(
$query
));
$mock
->
registerPlugin
(
'testplugin'
,
$observer
);
$mock
->
execute
(
$query
);
}
}
public
function
test
Select
()
public
function
test
ExecutePostPlugin
()
{
{
$query
=
new
Solarium_Query_Ping
();
$mock
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'createRequest'
,
'executeRequest'
,
'createResult'
));
$mock
->
expects
(
$this
->
once
())
->
method
(
'createRequest'
)
->
will
(
$this
->
returnValue
(
'dummyrequest'
));
$mock
->
expects
(
$this
->
once
())
->
method
(
'executeRequest'
)
->
will
(
$this
->
returnValue
(
'dummyresponse'
));
$mock
->
expects
(
$this
->
once
())
->
method
(
'createResult'
)
->
will
(
$this
->
returnValue
(
'dummyresult'
));
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'postExecute'
)
->
with
(
$this
->
equalTo
(
$query
),
$this
->
equalTo
(
'dummyresult'
));
$mock
->
registerPlugin
(
'testplugin'
,
$observer
);
$mock
->
execute
(
$query
);
}
}
public
function
test
Update
()
public
function
test
ExecuteWithOverridingPlugin
()
{
{
$query
=
new
Solarium_Query_Ping
();
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'preExecute'
)
->
with
(
$this
->
equalTo
(
$query
))
->
will
(
$this
->
returnValue
(
'dummyoverride'
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$result
=
$this
->
_client
->
execute
(
$query
);
$this
->
assertEquals
(
'dummyoverride'
,
$result
);
}
}
}
public
function
testExecuteRequest
()
{
$request
=
new
Solarium_Client_Request
();
$dummyResponse
=
'dummyresponse'
;
class
MyAdapter
extends
Solarium_Client_Adapter_Http
{
$observer
=
$this
->
getMock
(
'Solarium_Client_Adapter'
,
array
(
'execute'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$request
))
->
will
(
$this
->
returnValue
(
$dummyResponse
));
public
function
execute
(
$request
)
$this
->
_client
->
setAdapter
(
$observer
);
$response
=
$this
->
_client
->
executeRequest
(
$request
);
$this
->
assertEquals
(
$dummyResponse
,
$response
);
}
public
function
testExecuteRequestPrePlugin
()
{
{
$response
=
new
Solarium_Client_Response
(
'{}'
,
array
(
'HTTP/1.1 200 OK'
));
$request
=
new
Solarium_Client_Request
();
return
$response
;
$dummyResponse
=
'dummyresponse'
;
$mockAdapter
=
$this
->
getMock
(
'Solarium_Client_Adapter'
,
array
(
'execute'
));
$mockAdapter
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$request
))
->
will
(
$this
->
returnValue
(
$dummyResponse
));
$this
->
_client
->
setAdapter
(
$mockAdapter
);
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'preExecuteRequest'
)
->
with
(
$this
->
equalTo
(
$request
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$this
->
_client
->
executeRequest
(
$request
);
}
}
}
class
myConfig
{
public
function
testExecuteRequestPostPlugin
()
{
$request
=
new
Solarium_Client_Request
();
$dummyResponse
=
'dummyresponse'
;
$mockAdapter
=
$this
->
getMock
(
'Solarium_Client_Adapter'
,
array
(
'execute'
));
$mockAdapter
->
expects
(
$this
->
any
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$request
))
->
will
(
$this
->
returnValue
(
$dummyResponse
));
$this
->
_client
->
setAdapter
(
$mockAdapter
);
$response
=
$this
->
_client
->
executeRequest
(
$request
);
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'postExecuteRequest'
)
->
with
(
$this
->
equalTo
(
$request
),
$this
->
equalTo
(
$response
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$this
->
_client
->
executeRequest
(
$request
);
}
public
function
testExecuteRequestWithOverridingPlugin
()
{
$request
=
new
Solarium_Client_Request
();
$dummyOverride
=
'dummyoverride'
;
$observer
=
$this
->
getMock
(
'Solarium_Plugin_Abstract'
,
array
(),
array
(
$this
->
_client
,
array
()));
$observer
->
expects
(
$this
->
once
())
->
method
(
'preExecuteRequest'
)
->
with
(
$this
->
equalTo
(
$request
))
->
will
(
$this
->
returnValue
(
$dummyOverride
));
$this
->
_client
->
registerPlugin
(
'testplugin'
,
$observer
);
$response
=
$this
->
_client
->
executeRequest
(
$request
);
$this
->
assertEquals
(
$dummyOverride
,
$response
);
}
public
function
testPing
()
{
$query
=
new
Solarium_Query_Ping
();
protected
$_options
;
$observer
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'execute'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$query
));
$observer
->
ping
(
$query
);
}
public
function
__construct
(
$options
)
public
function
testSelect
(
)
{
{
$this
->
_options
=
$options
;
$query
=
new
Solarium_Query_Select
();
$observer
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'execute'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$query
));
$observer
->
select
(
$query
);
}
}
public
function
t
oArray
()
public
function
t
estUpdate
()
{
{
return
$this
->
_options
;
$query
=
new
Solarium_Query_Update
();
$observer
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'execute'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$query
));
$observer
->
update
(
$query
);
}
}
}
}
class
My
ClientPlugin
extends
Solarium_Plugin_Abstract
{
class
My
Adapter
extends
Solarium_Client_Adapter_Http
{
public
function
execute
(
$request
)
{
$response
=
new
Solarium_Client_Response
(
'{}'
,
array
(
'HTTP/1.1 200 OK'
));
return
$response
;
}
}
}
class
My
InvalidClientPlugin
{
class
My
ClientPlugin
extends
Solarium_Plugin_Abstract
{
}
}
\ 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