Permalink
Browse files

Merge pull request #649 from ppadron/dev

Services::patch() method + Content-Type fix in net\http\Request for PATCH
  • Loading branch information...
2 parents b5e4c87 + c49de93 commit d35f656f15c14637c55f50543580e66c964ea38b @nateabele nateabele committed Sep 18, 2012
Showing with 35 additions and 7 deletions.
  1. +1 −1 net/http/Request.php
  2. +12 −0 net/http/Service.php
  3. +22 −6 tests/cases/net/http/ServiceTest.php
@@ -230,7 +230,7 @@ public function to($format, array $options = array()) {
$data = $auth::encode($options['username'], $options['password'], $data);
$this->headers('Authorization', $auth::header($data));
}
- if (in_array($options['method'], array('POST', 'PUT'))) {
+ if (in_array($options['method'], array('POST', 'PUT', 'PATCH'))) {
$media = $this->_classes['media'];
if ($type = $media::type($this->_type)) {
$this->headers('Content-Type', $type['content'][0]);
View
@@ -165,6 +165,18 @@ public function put($path = null, $data = array(), array $options = array()) {
}
/**
+ * Send PATCH request.
+ *
+ * @param string $path
+ * @param array $data
+ * @param array $options
+ * @return string
+ */
+ public function patch($path = null, $data = array(), array $options = array()) {
+ return $this->send(__FUNCTION__, $path, $data, $options);
+ }
+
+ /**
* Send DELETE request.
*
* @param string $path
@@ -248,13 +248,8 @@ public function testSendConfiguringConnection() {
$this->assertEqual('someValue', $config['someKey']);
}
- public function testMagicMethod() {
+ public function testPatchMethod() {
$http = new Service($this->_testConfig);
- $response = $http->patch('some-path/stuff');
- $expected = "http://localhost:80/some-path/stuff";
- $result = $http->last->request->to('url');
- $this->assertEqual($expected, $result);
-
$response = $http->patch(
'some-path/stuff',
array('someData' => 'someValue'),
@@ -266,6 +261,27 @@ public function testMagicMethod() {
$this->assertEqual('someData=someValue', $result->body());
}
+ public function testPatchWithJson() {
+ $http = new Service($this->_testConfig);
+ $response = $http->patch(
+ 'some-path/stuff',
+ array('someData' => 'someValue'),
+ array('return' => 'response', 'type' => 'json')
+ );
+ $result = $http->last->request;
+ $this->assertEqual('{"someData":"someValue"}', $result->body());
+ $this->assertEqual('application/json', $result->headers['Content-Type']);
+ }
+
+ public function testMagicMethod() {
+ $http = new Service($this->_testConfig);
+ $response = $http->magic('some-path/stuff');
+ $expected = "http://localhost:80/some-path/stuff";
+ $result = $http->last->request;
+ $this->assertEqual($expected, $result->to('url'));
+ $this->assertEqual('MAGIC', $result->method);
+ }
+
public function testDigestAuth() {
$this->_testConfig += array('auth' => 'digest', 'username' => 'gwoo', 'password' => 'li3');
$http = new Service($this->_testConfig);

0 comments on commit d35f656

Please sign in to comment.