Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'hotfix/4366'

Close #4366
Fixes #3945
  • Loading branch information...
commit 671940863dd39a26798fef652d85defc9fd072dc 2 parents 972f71f + fda2645
@weierophinney weierophinney authored
View
28 library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php
@@ -19,7 +19,6 @@
use Zend\Stdlib\Parameters;
use Zend\Stdlib\ResponseInterface;
use Zend\Uri\Http as HttpUri;
-use Zend\View\Helper\Placeholder;
abstract class AbstractControllerTestCase extends PHPUnit_Framework_TestCase
{
@@ -213,15 +212,19 @@ public function url($url, $method = HttpRequest::METHOD_GET, $params = array())
}
if ($method == HttpRequest::METHOD_POST) {
- $post = $params;
+ if (count($params) != 0){
+ $post = $params;
+ }
} elseif ($method == HttpRequest::METHOD_GET) {
$query = array_merge($query, $params);
} elseif ($method == HttpRequest::METHOD_PUT) {
- array_walk($params,
- function(&$item, $key) { $item = $key . '=' . $item; }
- );
- $content = implode('&', $params);
- $request->setContent($content);
+ if (count($params) != 0){
+ array_walk($params,
+ function(&$item, $key) { $item = $key . '=' . $item; }
+ );
+ $content = implode('&', $params);
+ $request->setContent($content);
+ }
} elseif ($params) {
trigger_error(
'Additional params is only supported by GET, POST and PUT HTTP method',
@@ -249,8 +252,17 @@ function(&$item, $key) { $item = $key . '=' . $item; }
* @param array|null $params
* @throws \Exception
*/
- public function dispatch($url, $method = HttpRequest::METHOD_GET, $params = array())
+ public function dispatch($url, $method = null, $params = array())
{
+ if ( !isset($method) &&
+ $this->getRequest() instanceof HttpRequest &&
+ $requestMethod = $this->getRequest()->getMethod()
+ ) {
+ $method = $requestMethod;
+ } elseif (!isset($method)) {
+ $method = HttpRequest::METHOD_GET;
+ }
+
$this->url($url, $method, $params);
$this->getApplication()->run();
View
41 tests/ZendTest/Test/PHPUnit/Controller/AbstractControllerTestCaseTest.php
@@ -264,4 +264,45 @@ public function testDispatchRequestUri()
$this->dispatch('/tests');
$this->assertEquals('/tests', $this->getApplication()->getRequest()->getRequestUri());
}
+
+ public function testDefaultDispatchMethod()
+ {
+ $this->dispatch('/tests');
+ $this->assertEquals('GET', $this->getRequest()->getMethod());
+ }
+
+ public function testDispatchMethodSetOnRequest()
+ {
+ $this->getRequest()->setMethod('POST');
+ $this->dispatch('/tests');
+ $this->assertEquals('POST', $this->getRequest()->getMethod());
+ }
+
+ public function testExplicitDispatchMethodOverrideRequestMethod()
+ {
+ $this->getRequest()->setMethod('POST');
+ $this->dispatch('/tests', 'GET');
+ $this->assertEquals('GET', $this->getRequest()->getMethod());
+ }
+
+ public function testPutRequestParams()
+ {
+ $this->dispatch('/tests', 'PUT', array('a' => 1));
+ $this->assertEquals('a=1', $this->getRequest()->getContent());
+ }
+
+ public function testPreserveContentOfPutRequest()
+ {
+ $this->getRequest()->setMethod('PUT');
+ $this->getRequest()->setContent('my content');
+ $this->dispatch('/tests');
+ $this->assertEquals('my content', $this->getRequest()->getContent());
+ }
+
+ public function testExplicityPutParamsOverrideRequestContent()
+ {
+ $this->getRequest()->setContent('my content');
+ $this->dispatch('/tests', 'PUT', array('a' => 1));
+ $this->assertEquals('a=1', $this->getRequest()->getContent());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.