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
bb517cea
Commit
bb517cea
authored
Jul 27, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved client adapter unittests to 100% coverage, including some fixes
parent
892eb74c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
24 deletions
+83
-24
library/Solarium/Core/Client/Adapter/ZendHttp.php
library/Solarium/Core/Client/Adapter/ZendHttp.php
+4
-23
tests/Solarium/Tests/Core/Client/Adapter/HttpTest.php
tests/Solarium/Tests/Core/Client/Adapter/HttpTest.php
+20
-0
tests/Solarium/Tests/Core/Client/Adapter/PeclHttpTest.php
tests/Solarium/Tests/Core/Client/Adapter/PeclHttpTest.php
+22
-0
tests/Solarium/Tests/Core/Client/Adapter/ZendHttpTest.php
tests/Solarium/Tests/Core/Client/Adapter/ZendHttpTest.php
+35
-0
tests/Solarium/Tests/Core/Client/RequestTest.php
tests/Solarium/Tests/Core/Client/RequestTest.php
+2
-1
No files found.
library/Solarium/Core/Client/Adapter/ZendHttp.php
View file @
bb517cea
...
...
@@ -201,26 +201,12 @@ class ZendHttp extends Configurable implements AdapterInterface
$response
=
$client
->
request
();
// throw an exception in case of a HTTP error
if
(
$response
->
isError
())
{
throw
new
HttpException
(
$response
->
getMessage
(),
$response
->
getStatus
()
return
$this
->
prepareResponse
(
$request
,
$response
);
}
if
(
$request
->
getMethod
()
==
Request
::
METHOD_HEAD
)
{
$data
=
''
;
}
else
{
$data
=
$response
->
getBody
();
}
// this is used because getHeaders doesn't return the HTTP header...
$headers
=
explode
(
"
\n
"
,
$response
->
getHeadersAsString
());
return
new
Response
(
$data
,
$headers
);
}
/**
* Prepare a solarium response from the given request and client
* response
...
...
@@ -266,10 +252,5 @@ class ZendHttp extends Configurable implements AdapterInterface
file_get_contents
(
$filename
),
'application/octet-stream; charset=binary'
);
// set query params as "multipart/form-data" fields
foreach
(
$request
->
getParams
()
as
$name
=>
$value
)
{
$client
->
setFileUpload
(
null
,
$name
,
$value
,
'text/plain; charset=utf-8'
);
}
}
}
tests/Solarium/Tests/Core/Client/Adapter/HttpTest.php
View file @
bb517cea
...
...
@@ -162,6 +162,26 @@ class HttpTest extends \PHPUnit_Framework_TestCase
);
}
public
function
testCreateContextPostFileRequest
()
{
$timeout
=
13
;
$method
=
Request
::
METHOD_POST
;
$data
=
'test123'
;
$request
=
new
Request
();
$request
->
setMethod
(
$method
);
$request
->
setFileUpload
(
__FILE__
);
$endpoint
=
new
Endpoint
();
$endpoint
->
setTimeout
(
$timeout
);
$context
=
$this
->
adapter
->
createContext
(
$request
,
$endpoint
);
$this
->
assertEquals
(
array
(
'http'
=>
array
(
'method'
=>
$method
,
'timeout'
=>
$timeout
,
'content'
=>
file_get_contents
(
__FILE__
),
'header'
=>
'Content-Type: multipart/form-data'
)),
stream_context_get_options
(
$context
)
);
}
public
function
testCreateContextWithAuthorization
()
{
$timeout
=
13
;
...
...
tests/Solarium/Tests/Core/Client/Adapter/PeclHttpTest.php
View file @
bb517cea
...
...
@@ -133,6 +133,28 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase
),
$httpRequest
->
getOptions
());
}
public
function
testToHttpRequestWithFile
()
{
$request
=
new
Request
();
$request
->
setMethod
(
Request
::
METHOD_POST
);
$request
->
setFileUpload
(
__FILE__
);
$endpoint
=
new
Endpoint
();
$endpoint
->
setTimeout
(
10
);
$httpRequest
=
$this
->
adapter
->
toHttpRequest
(
$request
,
$endpoint
);
$this
->
assertEquals
(
array
(
array
(
'name'
=>
'content'
,
'type'
=>
'application/octet-stream; charset=binary'
,
'file'
=>
__FILE__
,
)
),
$httpRequest
->
getPostFiles
()
);
}
public
function
testToHttpRequestWithDefaultContentType
()
{
$request
=
new
Request
;
...
...
tests/Solarium/Tests/Core/Client/Adapter/ZendHttpTest.php
View file @
bb517cea
...
...
@@ -175,4 +175,39 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
);
}
public
function
testExecuteWithInvalidMethod
()
{
$request
=
new
Request
();
$request
->
setMethod
(
'invalid'
);
$endpoint
=
new
Endpoint
();
$this
->
setExpectedException
(
'Solarium\Exception\OutOfBoundsException'
);
$this
->
adapter
->
execute
(
$request
,
$endpoint
);
}
public
function
testExecuteWithFileUpload
()
{
$request
=
new
Request
();
$request
->
setMethod
(
Request
::
METHOD_POST
);
$request
->
setFileUpload
(
__FILE__
);
$endpoint
=
new
Endpoint
();
$response
=
new
\Zend_Http_Response
(
200
,
array
(
'status'
=>
'HTTP 1.1 200 OK'
),
'dummy'
);
$mock
=
$this
->
getMock
(
'Zend_Http_Client'
);
$mock
->
expects
(
$this
->
once
())
->
method
(
'setFileUpload'
)
->
with
(
$this
->
equalTo
(
'content'
),
$this
->
equalTo
(
'content'
),
$this
->
equalTo
(
file_get_contents
(
__FILE__
)),
$this
->
equalTo
(
'application/octet-stream; charset=binary'
)
);
$mock
->
expects
(
$this
->
once
())
->
method
(
'request'
)
->
will
(
$this
->
returnValue
(
$response
));
$this
->
adapter
->
setZendHttp
(
$mock
);
$this
->
adapter
->
execute
(
$request
,
$endpoint
);
}
}
tests/Solarium/Tests/Core/Client/RequestTest.php
View file @
bb517cea
...
...
@@ -475,6 +475,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
'username'
=>
'testuser'
,
'password'
=>
'testpass'
,
),
'file'
=>
__FILE__
,
);
$this
->
request
->
setOptions
(
$options
);
...
...
@@ -494,7 +495,7 @@ authentication: Array
resource: /myHandler?param1=1¶m2=test+content
resource urldecoded: /myHandler?param1=1¶m2=test content
raw data: post data
file upload:
file upload:
'
.
__FILE__
.
'
'
,
(
string
)
$this
->
request
);
...
...
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