write() public method

Writes data to curl options
public write ( array | Message $data = null ) : boolean
$data array | lithium\net\Message
return boolean
Beispiel #1
0
 public function testWriteAndRead()
 {
     $stream = new Curl($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue(is_resource($stream->resource()));
     $this->assertEqual(1, $stream->write());
     $this->assertPattern("/^HTTP/", (string) $stream->read());
 }
Beispiel #2
0
 public function testWriteAndRead()
 {
     $stream = new Curl($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue(is_resource($stream->resource()));
     $stream->set(CURLOPT_URL, $this->_testUrl);
     $this->assertTrue($stream->write(null));
     $this->assertTrue($stream->read());
     $response = $stream->send(new Request(), array('response' => 'lithium\\net\\http\\Response'));
     $this->assertEqual(trim(file_get_contents($this->_testUrl)), trim($response->body()));
     $this->assertNull($stream->eof());
 }
Beispiel #3
0
 public function testSendDeleteThenGet()
 {
     $postConfig = array('method' => 'DELETE', 'body' => '');
     $stream = new Curl($this->_testConfig);
     $this->assertInternalType('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], 'DELETE');
     $this->assertTrue(isset($stream->options[CURLOPT_POSTFIELDS]));
     $this->assertEqual($stream->options[CURLOPT_POSTFIELDS], $postConfig['body']);
     $this->assertTrue($stream->close());
     $this->assertInternalType('resource', $stream->open());
     $this->assertTrue($stream->write(new Request($this->_testConfig)));
     $this->assertFalse(isset($stream->options[CURLOPT_CUSTOMREQUEST]));
     $this->assertTrue($stream->close());
 }
Beispiel #4
0
 public function testSendPostThenGet()
 {
     $postConfig = array('method' => 'POST', '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_POST]));
     $this->assertTrue($stream->close());
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue($stream->write(new Request($this->_testConfig)));
     $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());
 }