Exemplo n.º 1
0
 public function testCreatesRingRequests()
 {
     $stream = Stream::factory('test');
     $request = new Request('GET', 'http://httpbin.org/get?a=b', ['test' => 'hello'], $stream);
     $request->getConfig()->set('foo', 'bar');
     $trans = new Transaction(new Client(), $request);
     $factory = new MessageFactory();
     $fsm = new RequestFsm(function () {
     }, new MessageFactory());
     $r = RingBridge::prepareRingRequest($trans, $factory, $fsm);
     $this->assertEquals('http', $r['scheme']);
     $this->assertEquals('1.1', $r['version']);
     $this->assertEquals('GET', $r['http_method']);
     $this->assertEquals('http://httpbin.org/get?a=b', $r['url']);
     $this->assertEquals('/get', $r['uri']);
     $this->assertEquals('a=b', $r['query_string']);
     $this->assertEquals(['Host' => ['httpbin.org'], 'test' => ['hello']], $r['headers']);
     $this->assertSame($stream, $r['body']);
     $this->assertEquals(['foo' => 'bar'], $r['client']);
     $this->assertFalse($r['future']);
 }
 public function testSetsIntegersAndFloatsAsHeaders()
 {
     $h = new Request('GET', 'http://foo.com');
     $h->setHeader('foo', 10);
     $h->setHeader('bar', 10.5);
     $h->addHeader('foo', 10);
     $h->addHeader('bar', 10.5);
     $this->assertSame('10, 10', $h->getHeader('foo'));
     $this->assertSame('10.5, 10.5', $h->getHeader('bar'));
 }
Exemplo n.º 3
0
 public function testCanChangePort()
 {
     $r = new Request('GET', 'http://www.foo.com:222');
     $this->assertSame(222, $r->getPort());
     $this->assertEquals('www.foo.com', $r->getHost());
     $this->assertEquals('www.foo.com:222', $r->getHeader('host'));
     $r->setPort(80);
     $this->assertSame(80, $r->getPort());
     $this->assertEquals('www.foo.com', $r->getHost());
     $this->assertEquals('www.foo.com', $r->getHeader('host'));
 }
Exemplo n.º 4
0
 public function testSetsTransferEncodingChunkedIfNeeded()
 {
     $r = new Request('PUT', '/');
     $s = $this->getMockBuilder('GuzzleHttp5Legacy\\Stream\\StreamInterface')->setMethods(['getSize'])->getMockForAbstractClass();
     $s->expects($this->exactly(2))->method('getSize')->will($this->returnValue(null));
     $r->setBody($s);
     $t = $this->getTrans($r);
     $s = new Prepare();
     $s->onBefore(new BeforeEvent($t));
     $this->assertEquals('chunked', $r->getHeader('Transfer-Encoding'));
 }