Permalink
Browse files

added support for PUT to add body in Curl with tests

  • Loading branch information...
1 parent 06fc157 commit afb3e15be3db5965021df1ddaf0252ae4dc3fe23 Dan Fellars committed with nateabele Sep 25, 2012
Showing with 20 additions and 0 deletions.
  1. +3 −0 net/socket/Curl.php
  2. +17 −0 tests/cases/net/socket/CurlTest.php
View
@@ -153,6 +153,9 @@ public function write($data = null) {
if (isset($data->method) && $data->method == 'POST') {
$this->set(array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data->body()));
}
+ if (isset($data->method) && $data->method == 'PUT') {
+ $this->set(array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $data->body()));
+ }
}
return (boolean) curl_setopt_array($this->_resource, $this->options);
}
@@ -166,6 +166,23 @@ public function testSendPostThenGet() {
$this->assertFalse(isset($stream->options[CURLOPT_POST]));
$this->assertTrue($stream->close());
}
+
+ public function testSendPutThenGet() {
+ $postConfig = array('method' => 'PUT', 'body' => '{"body"}');
+ $stream = new Curl($this->_testConfig);
+ $this->assertTrue(is_resource($stream->open()));
+ $this->assertTrue($stream->write(new Request($postConfig + $this->_testConfig)));
+ $this->assertTrue(isset($stream->options[CURLOPT_CUSTOMREQUEST]));
+ $this->assertEqual($stream->options[CURLOPT_CUSTOMREQUEST],'PUT');
+ $this->assertTrue(isset($stream->options[CURLOPT_POSTFIELDS]));
+ $this->assertEqual($stream->options[CURLOPT_POSTFIELDS],$postConfig['body']);
+ $this->assertTrue($stream->close());
+
+ $this->assertTrue(is_resource($stream->open()));
+ $this->assertTrue($stream->write(new Request($this->_testConfig)));
+ $this->assertFalse(isset($stream->options[CURLOPT_CUSTOMREQUEST]));
+ $this->assertTrue($stream->close());
+ }
}
?>

0 comments on commit afb3e15

Please sign in to comment.