示例#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
 /**
  * @testdox Calling resolveUri anonymously returns correct resolved target uri.
  * @medium
  * @group integration
  */
 public function testResolveUriAnonymous()
 {
     $playlistId = getenv('playlist_id') ?: '1';
     $playlistUri = getenv('playlist_uri') ?: 'https://soundcloud.com/myUsername/sets/myPlaylist';
     $location = 'http://soundcloud.com/resolved/' . $playlistId;
     $location .= '?client_id=' . $this->soundcloud->getAuthSubscriber()->getClientId();
     if (isset($this->mock)) {
         $this->mock->addMultiple([new Response(302, ['Location' => $location]), new Response(200)]);
     }
     $result = $this->soundcloud->resolveUri($playlistUri);
     $this->assertEquals(1, preg_match('/(\\d+)/', $result, $matches));
     $this->assertEquals($playlistId, $matches[1]);
     if (isset($this->mock)) {
         $this->assertEquals($location, $result);
     }
 }