X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=phpunit%2FRequestTest.php;h=56053ee148d5a487db4ee7d091a5a1f20874ac88;hb=c0d96fe2c0d156412bcb22bf5b9f5e9ed0046c9c;hp=1126328e8b7f33bb7cf960e58c98160da4b539f8;hpb=a84a30daa74ea8ff52a671769528ccf06580be4e;p=m6w6%2Fext-http diff --git a/phpunit/RequestTest.php b/phpunit/RequestTest.php index 1126328..56053ee 100644 --- a/phpunit/RequestTest.php +++ b/phpunit/RequestTest.php @@ -28,7 +28,7 @@ class RequestTest extends PHPUnit_Framework_TestCase protected $r; function setUp() { - $this->r = (new http\Request\Factory)->createRequest(); + $this->r = (new http\Client\Factory)->createClient(); $this->r->setOptions( array( "connecttimeout" => 30, @@ -38,10 +38,8 @@ class RequestTest extends PHPUnit_Framework_TestCase } function testClone() { - $this->r->setUrl("http://dev.iworks.at/ext-http/.print_request.php"); $c = clone $this->r; - $c->setUrl("http://dev.iworks.at/ext-http/.print_headers.php"); - $this->assertNotEquals($this->r->send(), $c->send()); + $this->assertNotSame($this->r, $c); } function testObserver() { @@ -61,51 +59,52 @@ class RequestTest extends PHPUnit_Framework_TestCase } ) ); - $this->r->setUrl("http://dev.iworks.at/ext-http/")->send(); + $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()); } function testCookies() { - $this->r->setUrl("http://dev.iworks.at/ext-http/.cookie.php")->send(); + $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie.php"))->send(null); $this->assertNotContains("Cookie", (string) $this->r->getRequestMessage()); - $this->r->send(); + $this->r->send(null); $this->assertNotContains("Cookie", (string) $this->r->getRequestMessage()); - $this->r->enableCookies()->send(); + $this->r->enableCookies()->send(null); $this->assertNotContains("Cookie", (string) $this->r->getRequestMessage()); - $this->r->send(); + $this->r->send(null); $this->assertContains("Cookie", (string) $this->r->getRequestMessage()); - $this->assertCount(2, $this->r->getResponseCookies()); + $this->assertCount(2, $this->r->getResponseMessage()->getCookies()); } function testResetCookies() { - $this->r->setUrl("http://dev.iworks.at/ext-http/.cookie.php"); + $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie.php")); $this->r->enableCookies(); - $this->r->send(); + $this->r->send(null); $f = function ($a) { return $a->getCookies(); }; - $c = array_map($f, $this->r->getResponseCookies()); + $c = array_map($f, $this->r->getResponseMessage()->getCookies()); - $this->r->send(); - $this->assertEquals($c, array_map($f, $this->r->getResponseCookies())); + $this->r->send(null); + $this->assertEquals($c, array_map($f, $this->r->getResponseMessage()->getCookies())); $this->r->resetCookies(); - $this->r->send(); - $this->assertNotEquals($c, array_map($f, $this->r->getResponseCookies())); + $this->r->send(null); + $this->assertNotEquals($c, array_map($f, $this->r->getResponseMessage()->getCookies())); } function testHistory() { $body = new http\Message\Body; $body->append("foobar"); - $this->r->setBody($body); - $this->r->recordHistory = true; + $request = new http\Client\Request; + $request->setBody($body); + $request->setRequestMethod("POST"); + $request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php"); - $this->r->setMethod(http\Request\Method::POST); - $this->r->setUrl("http://dev.iworks.at/ext-http/.print_request.php"); + $this->r->recordHistory = true; + $this->r->send($request); - $this->r->send(); $this->assertStringMatchesFormat(<<r->getHistory()->toString(true)) ); - $this->r->send(); + + $this->r->send($request); + $this->assertStringMatchesFormat(<<