Opens a curl connection and initializes the internal resource handle.
public open ( array $options = [] ) : mixed | ||
$options | array | update the config settings if $options['options'] exists, will be passed to $this->set() |
리턴 | mixed | Returns `false` if the socket configuration does not contain the `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a resource stream. |
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()); }
public function testCurlAdapter() { $socket = new Curl($this->_testConfig); $this->assertTrue($socket->open()); $response = $socket->send(); $this->assertTrue($response instanceof \lithium\net\http\Response); $expected = 'www.google.com'; $result = $response->host; $this->assertEqual($expected, $result); $result = $response->body(); $this->assertPattern("/<title[^>]*>Google<\\/title>/im", (string) $result); }
public function testCurlAdapter() { $message = 'Your PHP installation was not compiled with curl support.'; $this->skipIf(!function_exists('curl_init'), $message); $socket = new Curl($this->_testConfig); $this->assertTrue($socket->open()); $response = $socket->send(); $this->assertTrue($response instanceof Response); $expected = 'google.com'; $result = $response->host; $this->assertEqual($expected, $result); $result = $response->body(); $this->assertPattern("/<title[^>]*>.*<\\/title>/im", (string) $result); }
public function testSendWithObject() { $stream = new Curl($this->_testConfig); $this->assertTrue(is_resource($stream->open())); $result = $stream->send(new Request($this->_testConfig), array('response' => 'lithium\\net\\http\\Response')); $this->assertTrue($result instanceof \lithium\net\http\Response); $this->assertPattern("/^HTTP/", (string) $result); }
public function testCurlAdapter() { $socket = new Curl($this->_testConfig); $this->assertNotEmpty($socket->open()); $response = $socket->send(); $this->assertInstanceOf('lithium\\net\\http\\Response', $response); $expected = 'example.org'; $result = $response->host; $this->assertEqual($expected, $result); $result = $response->body(); $this->assertPattern("/<title[^>]*>Example Domain<\\/title>/im", (string) $result); }
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()); }