Updating Goutte to work with Guzzle 2.6.0 #46

Merged
merged 1 commit into from May 15, 2012
View
19 Goutte/Client.php
@@ -17,11 +17,11 @@
use Symfony\Component\BrowserKit\Request;
use Symfony\Component\BrowserKit\Response;
-use Guzzle\Http\Curl\CurlException;
+use Guzzle\Http\Exception\CurlException;
use Guzzle\Http\Message\RequestInterface as GuzzleRequestInterface;
use Guzzle\Http\Message\Response as GuzzleResponse;
-use Guzzle\Service\ClientInterface as GuzzleClientInterface;
-use Guzzle\Service\Client as GuzzleClient;
+use Guzzle\Http\ClientInterface as GuzzleClientInterface;
+use Guzzle\Http\Client as GuzzleClient;
/**
* Client.
@@ -75,7 +75,7 @@ public function setAuth($user, $password = '', $type = GuzzleRequestInterface::A
protected function doRequest($request)
{
$guzzleRequest = $this->getClient()->createRequest(
- $request->getMethod(),
+ strtoupper($request->getMethod()),
@fabpot
fabpot May 15, 2012

the method is always upper-cased, that's why I removed this from the previous PR.

$request->getUri(),
$this->headers,
$request->getParameters()
@@ -94,16 +94,23 @@ protected function doRequest($request)
}
if ('POST' == $request->getMethod()) {
+ $postFiles = array();
foreach ($request->getFiles() as $name => $info) {
if (isset($info['tmp_name']) && '' !== $info['tmp_name']) {
- $guzzleRequest->addPostFiles(array($name => $info['tmp_name']));
+ $postFiles[$name] = $info['tmp_name'];
}
}
+ if (!empty($postFiles)) {
+ $guzzleRequest->addPostFiles($postFiles);
+ }
}
$guzzleRequest->setHeader('User-Agent', $this->server['HTTP_USER_AGENT']);
- $guzzleRequest->getCurlOptions()->merge(array(CURLOPT_MAXREDIRS => 0, CURLOPT_TIMEOUT => 30));
+ $guzzleRequest->getCurlOptions()
+ ->set(CURLOPT_FOLLOWLOCATION, false)
+ ->set(CURLOPT_MAXREDIRS, 0)
+ ->set(CURLOPT_TIMEOUT, 30);
// Let BrowserKit handle redirects
try {
View
51 Goutte/Tests/ClientTest.php
@@ -15,7 +15,7 @@
use Symfony\Component\BrowserKit\Cookie;
use Guzzle\Http\Message\Response as GuzzleResponse;
-use Guzzle\Service\Client as GuzzleClient;
+use Guzzle\Http\Client as GuzzleClient;
use Guzzle\Http\Plugin\MockPlugin;
use Guzzle\Http\Plugin\HistoryPlugin;
use Guzzle\Http\Message\Response;
@@ -28,23 +28,24 @@
class ClientTest extends \PHPUnit_Framework_TestCase
{
protected $history;
+ protected $mockPlugin;
protected function getGuzzle()
{
- $this->history = new HistoryPlugin();
- $mock = new MockPlugin();
- $mock->addResponse(new GuzzleResponse(200, null, '<html><body><p>Hi</p></body></html>'));
+ $this->historyPlugin = new HistoryPlugin();
+ $this->mockPlugin = new MockPlugin();
+ $this->mockPlugin->addResponse(new GuzzleResponse(200, null, '<html><body><p>Hi</p></body></html>'));
$guzzle = new GuzzleClient();
- $guzzle->getEventManager()->attach($mock);
- $guzzle->getEventManager()->attach($this->history);
+ $guzzle->getEventDispatcher()->addSubscriber($this->mockPlugin);
+ $guzzle->getEventDispatcher()->addSubscriber($this->historyPlugin);
return $guzzle;
}
public function testCreatesDefaultClient()
{
$client = new Client();
- $this->assertInstanceOf('Guzzle\\Service\\Client', $client->getClient());
+ $this->assertInstanceOf('Guzzle\\Http\\ClientInterface', $client->getClient());
}
public function testUsesCustomClient()
@@ -61,8 +62,8 @@ public function testUsesCustomHeaders()
$client = new Client();
$client->setClient($guzzle);
$client->setHeader('X-Test', 'test');
- $crawler = $client->request('GET', 'http://test.com/');
- $this->assertEquals('test', $this->history->getLastRequest()->getHeader('X-Test'));
+ $crawler = $client->request('GET', 'http://www.example.com/');
+ $this->assertEquals('test', $this->historyPlugin->getLastRequest()->getHeader('X-Test'));
}
public function testUsesAuth()
@@ -71,8 +72,8 @@ public function testUsesAuth()
$client = new Client();
$client->setClient($guzzle);
$client->setAuth('me', '**');
- $crawler = $client->request('GET', 'http://test.com/');
- $request = $this->history->getLastRequest();
+ $crawler = $client->request('GET', 'http://www.example.com/');
+ $request = $this->historyPlugin->getLastRequest();
$this->assertEquals('me', $request->getUsername());
$this->assertEquals('**', $request->getPassword());
}
@@ -83,8 +84,8 @@ public function testUsesCookies()
$client = new Client();
$client->setClient($guzzle);
$client->getCookieJar()->set(new Cookie('test', '123'));
- $crawler = $client->request('GET', 'http://test.com/');
- $request = $this->history->getLastRequest();
+ $crawler = $client->request('GET', 'http://www.example.com/');
+ $request = $this->historyPlugin->getLastRequest();
$this->assertEquals('123', $request->getCookie('test'));
}
@@ -100,8 +101,8 @@ public function testUsesPostFiles()
)
);
- $crawler = $client->request('POST', 'http://test.com/', array(), $files);
- $request = $this->history->getLastRequest();
+ $crawler = $client->request('POST', 'http://www.example.com/', array(), $files);
+ $request = $this->historyPlugin->getLastRequest();
$this->assertEquals(array(
'test' => __FILE__
@@ -113,8 +114,8 @@ public function testUsesCurlOptions()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
- $crawler = $client->request('GET', 'http://test.com/');
- $request = $this->history->getLastRequest();
+ $crawler = $client->request('GET', 'http://www.example.com/');
+ $request = $this->historyPlugin->getLastRequest();
$this->assertEquals(0, $request->getCurlOptions()->get(CURLOPT_MAXREDIRS));
$this->assertEquals(30, $request->getCurlOptions()->get(CURLOPT_TIMEOUT));
}
@@ -124,29 +125,27 @@ public function testCreatesResponse()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
- $crawler = $client->request('GET', 'http://test.com/');
+ $crawler = $client->request('GET', 'http://www.example.com/');
$this->assertEquals('Hi', $crawler->filter('p')->text());
}
public function testHandlesRedirectsCorrectly()
{
$guzzle = $this->getGuzzle();
- $plugins = $guzzle->getEventManager()->getAttached('Guzzle\\Service\\Plugin\\MockPlugin');
- $mock = $plugins[0];
- $mock->clearQueue();
- $mock->addResponse(new GuzzleResponse(301, array(
- 'Location' => 'http://www.test.com/'
+ $this->mockPlugin->clearQueue();
+ $this->mockPlugin->addResponse(new GuzzleResponse(301, array(
+ 'Location' => 'http://www.example.com/'
)));
- $mock->addResponse(new GuzzleResponse(200, null, '<html><body><p>Test</p></body></html>'));
+ $this->mockPlugin->addResponse(new GuzzleResponse(200, null, '<html><body><p>Test</p></body></html>'));
$client = new Client();
$client->setClient($guzzle);
- $crawler = $client->request('GET', 'http://test.com/');
+ $crawler = $client->request('GET', 'http://www.example.com/');
$this->assertEquals('Test', $crawler->filter('p')->text());
// Ensure that two requests were sent
- $this->assertEquals(2, count($this->history));
+ $this->assertEquals(2, count($this->historyPlugin));
}
}
View
2 composer.json
@@ -19,7 +19,7 @@
"symfony/dom-crawler": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/process": "2.1.*",
- "guzzle/guzzle": "v2.5.0"
+ "guzzle/guzzle": "2.6.*"
},
"autoload": {
"psr-0": { "Goutte": "." }
View
20 composer.lock
@@ -1,21 +1,21 @@
{
- "hash": "c9baae245e544c661fbe1d1b76903480",
+ "hash": "6c5c0a3c22af6f33635d8c901c56f7e5",
"packages": [
{
"package": "guzzle/guzzle",
- "version": "v2.5.0"
+ "version": "v2.6.0"
},
{
"package": "symfony/browser-kit",
"version": "dev-master",
- "source-reference": "2cebdd6803abf9c7240bb2a7a5c3aa8f45a9ef9f"
+ "source-reference": "2cebdd6803abf9c7240bb2a7a5c3aa8f45a9ef9f",
+ "alias-pretty-version": "2.1.x-dev",
+ "alias-version": "2.1.9999999.9999999-dev"
},
{
"package": "symfony/browser-kit",
"version": "dev-master",
- "source-reference": "2cebdd6803abf9c7240bb2a7a5c3aa8f45a9ef9f",
- "alias-pretty-version": "2.1.x-dev",
- "alias-version": "2.1.9999999.9999999-dev"
+ "source-reference": "2cebdd6803abf9c7240bb2a7a5c3aa8f45a9ef9f"
},
{
"package": "symfony/css-selector",
@@ -32,14 +32,14 @@
{
"package": "symfony/dom-crawler",
"version": "dev-master",
- "source-reference": "49d80fac919321c1e255757fe47b97910f667271",
- "alias-pretty-version": "2.1.x-dev",
- "alias-version": "2.1.9999999.9999999-dev"
+ "source-reference": "49d80fac919321c1e255757fe47b97910f667271"
},
{
"package": "symfony/dom-crawler",
"version": "dev-master",
- "source-reference": "49d80fac919321c1e255757fe47b97910f667271"
+ "source-reference": "49d80fac919321c1e255757fe47b97910f667271",
+ "alias-pretty-version": "2.1.x-dev",
+ "alias-version": "2.1.9999999.9999999-dev"
},
{
"package": "symfony/event-dispatcher",
View
BIN goutte.phar
Binary file not shown.