80%+ test coverage
[m6w6/ext-http] / phpunit / RequestTest.php
index 56053ee148d5a487db4ee7d091a5a1f20874ac88..a327f6dff2440eb49a26a118dadeb6a9ae649e5d 100644 (file)
@@ -35,6 +35,18 @@ class RequestTest extends PHPUnit_Framework_TestCase
                 "timeout"           => 300,
             )
         );
+        $this->r->setOptions(
+               array(
+                       "timeout" => 600
+               )
+        );
+        $this->assertEquals(
+               array(
+                       "connecttimeout" => 30,
+                       "timeout" => 600,
+               ),
+               $this->r->getOptions()
+        );
     }
 
     function testClone() {
@@ -43,10 +55,10 @@ class RequestTest extends PHPUnit_Framework_TestCase
     }
 
     function testObserver() {
-        $this->r->attach(new ProgressObserver1);
-        $this->r->attach(new ProgressObserver2);
+        $this->r->attach($o1 = new ProgressObserver1);
+        $this->r->attach($o2 = new ProgressObserver2);
         $this->r->attach(
-            new CallbackObserver(
+            $o3 = new CallbackObserver(
                 function ($r) {
                     $p = (array) $r->getProgress();
                     $this->assertArrayHasKey("started", $p);
@@ -62,6 +74,12 @@ class RequestTest extends PHPUnit_Framework_TestCase
         $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/"))->send(null);
         $this->assertRegexp("/(\.-)+/", $this->r->pi);
         $this->assertCount(3, $this->r->getObservers());
+        $this->r->detach($o1);
+        $this->assertCount(2, $this->r->getObservers());
+        $this->r->detach($o2);
+        $this->assertCount(1, $this->r->getObservers());
+        $this->r->detach($o3);
+        $this->assertCount(0, $this->r->getObservers());
     }
 
     function testCookies() {
@@ -92,6 +110,23 @@ class RequestTest extends PHPUnit_Framework_TestCase
         $this->r->send(null);
         $this->assertNotEquals($c, array_map($f, $this->r->getResponseMessage()->getCookies()));
     }
+    
+    function testSsl() {
+       $this->r->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
+       $this->r->setSslOptions(array("verify_peer" => true));
+       $this->r->addSslOptions(array("verify_host" => 2));
+       $this->assertEquals(
+               array(
+                       "verify_peer" => true,
+                       "verify_host" => 2,
+               ),
+               $this->r->getSslOptions()
+       );
+       $this->r->send();
+       $ti = $this->r->getTransferInfo();
+       $this->assertArrayHasKey("ssl_engines", $ti);
+       $this->assertGreaterThan(0, count($ti["ssl_engines"])); 
+    }
 
     function testHistory() {
         $body = new http\Message\Body;