Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/PHPUnit/Controller/AbstractControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,19 @@ public function url($url, $method = HttpRequest::METHOD_GET, $params = array())

if ($method == HttpRequest::METHOD_POST) {
$post = $params;
}

if ($method == HttpRequest::METHOD_GET) {
} 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);
} elseif ($params) {
trigger_error(
'Additional params is only supported by GET, POST and PUT HTTP method',
E_USER_NOTICE
);
}

$request->setMethod($method);
Expand Down
10 changes: 10 additions & 0 deletions test/PHPUnit/Controller/AbstractHttpControllerTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,22 @@ public function testAssertQueryWithDynamicPostParams()
public function testAssertQueryWithDynamicPostParamsInDispatchMethod()
{
$this->dispatch('/tests', 'POST', array('num_post' => 5));
$request = $this->getRequest();
$this->assertEquals($request->getMethod(), 'POST');
$this->assertQueryCount('div.post', 5);
$this->assertXpathQueryCount('//div[@class="post"]', 5);
$this->assertQueryCount('div.get', 0);
$this->assertXpathQueryCount('//div[@class="get"]', 0);
}

public function testAssertQueryWithDynamicPutParamsInDispatchMethod()
{
$this->dispatch('/tests', 'PUT', array('num_post' => 5, 'foo' => 'bar'));
$request = $this->getRequest();
$this->assertEquals($request->getMethod(), 'PUT');
$this->assertEquals('num_post=5&foo=bar', $request->getContent());
}
/*
public function testAssertUriWithHostname()
{
$this->dispatch('http://my.domain.tld:443');
Expand Down

0 comments on commit c22bfe9

Please sign in to comment.