Пример #1
0
 public function testRedirectsRequests()
 {
     $mock = new Mock();
     $history = new History();
     $mock->addMultiple(["HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect2\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"]);
     $client = new Client(['base_url' => 'http://test.com']);
     $client->getEmitter()->attach($history);
     $client->getEmitter()->attach($mock);
     $request = $client->createRequest('GET', '/foo');
     // Ensure "end" is called only once
     $called = 0;
     $request->getEmitter()->on('end', function () use(&$called) {
         $called++;
     });
     $response = $client->send($request);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertContains('/redirect2', $response->getEffectiveUrl());
     // Ensure that two requests were sent
     $requests = $history->getRequests(true);
     $this->assertEquals('/foo', $requests[0]->getPath());
     $this->assertEquals('GET', $requests[0]->getMethod());
     $this->assertEquals('/redirect1', $requests[1]->getPath());
     $this->assertEquals('GET', $requests[1]->getMethod());
     $this->assertEquals('/redirect2', $requests[2]->getPath());
     $this->assertEquals('GET', $requests[2]->getMethod());
     $this->assertEquals(1, $called);
 }
Пример #2
0
 /**
  * @expectedException \OutOfBoundsException
  */
 public function testUpdateThrowsExceptionWhenEmpty()
 {
     $p = new Mock();
     $ev = new BeforeEvent(new Transaction(new Client(), new Request('GET', '/')));
     $p->onBefore($ev);
 }