summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/tests/Guzzle/Tests/Http')
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/AbstractEntityBodyDecoratorTest.php34
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/CachingEntityBodyTest.php249
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/ClientTest.php601
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlHandleTest.php947
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlMultiProxyTest.php110
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlMultiTest.php455
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlVersionTest.php39
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/RequestMediatorTest.php67
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/EntityBodyTest.php182
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/CurlExceptionTest.php27
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/ExceptionTest.php66
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/MultiTransferExceptionTest.php51
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/IoEmittingEntityBodyTest.php47
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/AbstractMessageTest.php136
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/EntityEnclosingRequestTest.php434
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/Header/HeaderFactoryTest.php29
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/Header/LinkTest.php63
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderComparison.php135
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderComparisonTest.php115
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderTest.php162
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/PostFileTest.php88
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/RequestFactoryTest.php616
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/RequestTest.php639
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/ResponseTest.php677
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/MimetypesTest.php31
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/CommaAggregatorTest.php30
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/DuplicateAggregatorTest.php30
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/PhpAggregatorTest.php32
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryStringTest.php233
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/ReadLimitEntityBodyTest.php81
-rwxr-xr-xvendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php277
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Server.php191
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/StaticClientTest.php67
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/UrlTest.php303
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/server.js146
35 files changed, 7390 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/AbstractEntityBodyDecoratorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/AbstractEntityBodyDecoratorTest.php
new file mode 100644
index 0000000..20feaa8
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/AbstractEntityBodyDecoratorTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\EntityBody;
+
+/**
+ * @covers Guzzle\Http\AbstractEntityBodyDecorator
+ */
+class AbstractEntityBodyDecoratorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testDecoratesEntityBody()
+ {
+ $e = EntityBody::factory();
+ $mock = $this->getMockForAbstractClass('Guzzle\Http\AbstractEntityBodyDecorator', array($e));
+
+ $this->assertSame($e->getStream(), $mock->getStream());
+ $this->assertSame($e->getContentLength(), $mock->getContentLength());
+ $this->assertSame($e->getSize(), $mock->getSize());
+ $this->assertSame($e->getContentMd5(), $mock->getContentMd5());
+ $this->assertSame($e->getContentType(), $mock->getContentType());
+ $this->assertSame($e->__toString(), $mock->__toString());
+ $this->assertSame($e->getUri(), $mock->getUri());
+ $this->assertSame($e->getStreamType(), $mock->getStreamType());
+ $this->assertSame($e->getWrapper(), $mock->getWrapper());
+ $this->assertSame($e->getWrapperData(), $mock->getWrapperData());
+ $this->assertSame($e->isReadable(), $mock->isReadable());
+ $this->assertSame($e->isWritable(), $mock->isWritable());
+ $this->assertSame($e->isConsumed(), $mock->isConsumed());
+ $this->assertSame($e->isLocal(), $mock->isLocal());
+ $this->assertSame($e->isSeekable(), $mock->isSeekable());
+ $this->assertSame($e->getContentEncoding(), $mock->getContentEncoding());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/CachingEntityBodyTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/CachingEntityBodyTest.php
new file mode 100644
index 0000000..e6e6cdb
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/CachingEntityBodyTest.php
@@ -0,0 +1,249 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\CachingEntityBody;
+
+/**
+ * @covers Guzzle\Http\CachingEntityBody
+ */
+class CachingEntityBodyTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /** @var CachingEntityBody */
+ protected $body;
+
+ /** @var EntityBody */
+ protected $decorated;
+
+ public function setUp()
+ {
+ $this->decorated = EntityBody::factory('testing');
+ $this->body = new CachingEntityBody($this->decorated);
+ }
+
+ public function testUsesRemoteSizeIfPossible()
+ {
+ $body = EntityBody::factory('test');
+ $caching = new CachingEntityBody($body);
+ $this->assertEquals(4, $caching->getSize());
+ $this->assertEquals(4, $caching->getContentLength());
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\RuntimeException
+ * @expectedExceptionMessage does not support custom stream rewind
+ */
+ public function testDoesNotAllowRewindFunction()
+ {
+ $this->body->setRewindFunction(true);
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\RuntimeException
+ * @expectedExceptionMessage Cannot seek to byte 10
+ */
+ public function testCannotSeekPastWhatHasBeenRead()
+ {
+ $this->body->seek(10);
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\RuntimeException
+ * @expectedExceptionMessage supports only SEEK_SET and SEEK_CUR
+ */
+ public function testCannotUseSeekEnd()
+ {
+ $this->body->seek(2, SEEK_END);
+ }
+
+ public function testChangingUnderlyingStreamUpdatesSizeAndStream()
+ {
+ $size = filesize(__FILE__);
+ $s = fopen(__FILE__, 'r');
+ $this->body->setStream($s, $size);
+ $this->assertEquals($size, $this->body->getSize());
+ $this->assertEquals($size, $this->decorated->getSize());
+ $this->assertSame($s, $this->body->getStream());
+ $this->assertSame($s, $this->decorated->getStream());
+ }
+
+ public function testRewindUsesSeek()
+ {
+ $a = EntityBody::factory('foo');
+ $d = $this->getMockBuilder('Guzzle\Http\CachingEntityBody')
+ ->setMethods(array('seek'))
+ ->setConstructorArgs(array($a))
+ ->getMock();
+ $d->expects($this->once())
+ ->method('seek')
+ ->with(0)
+ ->will($this->returnValue(true));
+ $d->rewind();
+ }
+
+ public function testCanSeekToReadBytes()
+ {
+ $this->assertEquals('te', $this->body->read(2));
+ $this->body->seek(0);
+ $this->assertEquals('test', $this->body->read(4));
+ $this->assertEquals(4, $this->body->ftell());
+ $this->body->seek(2);
+ $this->assertEquals(2, $this->body->ftell());
+ $this->body->seek(2, SEEK_CUR);
+ $this->assertEquals(4, $this->body->ftell());
+ $this->assertEquals('ing', $this->body->read(3));
+ }
+
+ public function testWritesToBufferStream()
+ {
+ $this->body->read(2);
+ $this->body->write('hi');
+ $this->body->rewind();
+ $this->assertEquals('tehiing', (string) $this->body);
+ }
+
+ public function testReadLinesFromBothStreams()
+ {
+ $this->body->seek($this->body->ftell());
+ $this->body->write("test\n123\nhello\n1234567890\n");
+ $this->body->rewind();
+ $this->assertEquals("test\n", $this->body->readLine(7));
+ $this->assertEquals("123\n", $this->body->readLine(7));
+ $this->assertEquals("hello\n", $this->body->readLine(7));
+ $this->assertEquals("123456", $this->body->readLine(7));
+ $this->assertEquals("7890\n", $this->body->readLine(7));
+ // We overwrote the decorated stream, so no more data
+ $this->assertEquals('', $this->body->readLine(7));
+ }
+
+ public function testSkipsOverwrittenBytes()
+ {
+ $decorated = EntityBody::factory(
+ implode("\n", array_map(function ($n) {
+ return str_pad($n, 4, '0', STR_PAD_LEFT);
+ }, range(0, 25)))
+ );
+
+ $body = new CachingEntityBody($decorated);
+
+ $this->assertEquals("0000\n", $body->readLine());
+ $this->assertEquals("0001\n", $body->readLine());
+ // Write over part of the body yet to be read, so skip some bytes
+ $this->assertEquals(5, $body->write("TEST\n"));
+ $this->assertEquals(5, $this->readAttribute($body, 'skipReadBytes'));
+ // Read, which skips bytes, then reads
+ $this->assertEquals("0003\n", $body->readLine());
+ $this->assertEquals(0, $this->readAttribute($body, 'skipReadBytes'));
+ $this->assertEquals("0004\n", $body->readLine());
+ $this->assertEquals("0005\n", $body->readLine());
+
+ // Overwrite part of the cached body (so don't skip any bytes)
+ $body->seek(5);
+ $this->assertEquals(5, $body->write("ABCD\n"));
+ $this->assertEquals(0, $this->readAttribute($body, 'skipReadBytes'));
+ $this->assertEquals("TEST\n", $body->readLine());
+ $this->assertEquals("0003\n", $body->readLine());
+ $this->assertEquals("0004\n", $body->readLine());
+ $this->assertEquals("0005\n", $body->readLine());
+ $this->assertEquals("0006\n", $body->readLine());
+ $this->assertEquals(5, $body->write("1234\n"));
+ $this->assertEquals(5, $this->readAttribute($body, 'skipReadBytes'));
+
+ // Seek to 0 and ensure the overwritten bit is replaced
+ $body->rewind();
+ $this->assertEquals("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", $body->read(50));
+
+ // Ensure that casting it to a string does not include the bit that was overwritten
+ $this->assertContains("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", (string) $body);
+ }
+
+ public function testWrapsContentType()
+ {
+ $a = $this->getMockBuilder('Guzzle\Http\EntityBody')
+ ->setMethods(array('getContentType'))
+ ->setConstructorArgs(array(fopen(__FILE__, 'r')))
+ ->getMock();
+ $a->expects($this->once())
+ ->method('getContentType')
+ ->will($this->returnValue('foo'));
+ $d = new CachingEntityBody($a);
+ $this->assertEquals('foo', $d->getContentType());
+ }
+
+ public function testWrapsContentEncoding()
+ {
+ $a = $this->getMockBuilder('Guzzle\Http\EntityBody')
+ ->setMethods(array('getContentEncoding'))
+ ->setConstructorArgs(array(fopen(__FILE__, 'r')))
+ ->getMock();
+ $a->expects($this->once())
+ ->method('getContentEncoding')
+ ->will($this->returnValue('foo'));
+ $d = new CachingEntityBody($a);
+ $this->assertEquals('foo', $d->getContentEncoding());
+ }
+
+ public function testWrapsMetadata()
+ {
+ $a = $this->getMockBuilder('Guzzle\Http\EntityBody')
+ ->setMethods(array('getMetadata', 'getWrapper', 'getWrapperData', 'getStreamType', 'getUri'))
+ ->setConstructorArgs(array(fopen(__FILE__, 'r')))
+ ->getMock();
+
+ $a->expects($this->once())
+ ->method('getMetadata')
+ ->will($this->returnValue(array()));
+ // Called twice for getWrapper and getWrapperData
+ $a->expects($this->exactly(1))
+ ->method('getWrapper')
+ ->will($this->returnValue('wrapper'));
+ $a->expects($this->once())
+ ->method('getWrapperData')
+ ->will($this->returnValue(array()));
+ $a->expects($this->once())
+ ->method('getStreamType')
+ ->will($this->returnValue('baz'));
+ $a->expects($this->once())
+ ->method('getUri')
+ ->will($this->returnValue('path/to/foo'));
+
+ $d = new CachingEntityBody($a);
+ $this->assertEquals(array(), $d->getMetaData());
+ $this->assertEquals('wrapper', $d->getWrapper());
+ $this->assertEquals(array(), $d->getWrapperData());
+ $this->assertEquals('baz', $d->getStreamType());
+ $this->assertEquals('path/to/foo', $d->getUri());
+ }
+
+ public function testWrapsCustomData()
+ {
+ $a = $this->getMockBuilder('Guzzle\Http\EntityBody')
+ ->setMethods(array('getCustomData', 'setCustomData'))
+ ->setConstructorArgs(array(fopen(__FILE__, 'r')))
+ ->getMock();
+
+ $a->expects($this->exactly(1))
+ ->method('getCustomData')
+ ->with('foo')
+ ->will($this->returnValue('bar'));
+
+ $a->expects($this->exactly(1))
+ ->method('setCustomData')
+ ->with('foo', 'bar')
+ ->will($this->returnSelf());
+
+ $d = new CachingEntityBody($a);
+ $this->assertSame($d, $d->setCustomData('foo', 'bar'));
+ $this->assertEquals('bar', $d->getCustomData('foo'));
+ }
+
+ public function testClosesBothStreams()
+ {
+ $s = fopen('php://temp', 'r');
+ $a = EntityBody::factory($s);
+ $d = new CachingEntityBody($a);
+ $d->close();
+ $this->assertFalse(is_resource($s));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/ClientTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/ClientTest.php
new file mode 100644
index 0000000..4a91a18
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/ClientTest.php
@@ -0,0 +1,601 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Common\Collection;
+use Guzzle\Log\ClosureLogAdapter;
+use Guzzle\Parser\UriTemplate\UriTemplate;
+use Guzzle\Http\Message\Response;
+use Guzzle\Plugin\Log\LogPlugin;
+use Guzzle\Plugin\Mock\MockPlugin;
+use Guzzle\Http\Curl\CurlMulti;
+use Guzzle\Http\Client;
+use Guzzle\Common\Version;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\Client
+ */
+class ClientTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /**
+ * @return LogPlugin
+ */
+ private function getLogPlugin()
+ {
+ return new LogPlugin(new ClosureLogAdapter(
+ function($message, $priority, $extras = null) {
+ echo $message . ' ' . $priority . ' ' . implode(' - ', (array) $extras) . "\n";
+ }
+ ));
+ }
+
+ public function testAcceptsConfig()
+ {
+ $client = new Client('http://www.google.com/');
+ $this->assertEquals('http://www.google.com/', $client->getBaseUrl());
+ $this->assertSame($client, $client->setConfig(array(
+ 'test' => '123'
+ )));
+ $this->assertEquals(array('test' => '123'), $client->getConfig()->getAll());
+ $this->assertEquals('123', $client->getConfig('test'));
+ $this->assertSame($client, $client->setBaseUrl('http://www.test.com/{test}'));
+ $this->assertEquals('http://www.test.com/123', $client->getBaseUrl());
+ $this->assertEquals('http://www.test.com/{test}', $client->getBaseUrl(false));
+
+ try {
+ $client->setConfig(false);
+ } catch (\InvalidArgumentException $e) {
+ }
+ }
+
+ public function testDescribesEvents()
+ {
+ $this->assertEquals(array('client.create_request'), Client::getAllEvents());
+ }
+
+ public function testConstructorCanAcceptConfig()
+ {
+ $client = new Client('http://www.test.com/', array(
+ 'data' => '123'
+ ));
+ $this->assertEquals('123', $client->getConfig('data'));
+ }
+
+ public function testCanUseCollectionAsConfig()
+ {
+ $client = new Client('http://www.google.com/');
+ $client->setConfig(new Collection(array(
+ 'api' => 'v1',
+ 'key' => 'value',
+ 'base_url' => 'http://www.google.com/'
+ )));
+ $this->assertEquals('v1', $client->getConfig('api'));
+ }
+
+ public function testExpandsUriTemplatesUsingConfig()
+ {
+ $client = new Client('http://www.google.com/');
+ $client->setConfig(array('api' => 'v1', 'key' => 'value', 'foo' => 'bar'));
+ $ref = new \ReflectionMethod($client, 'expandTemplate');
+ $ref->setAccessible(true);
+ $this->assertEquals('Testing...api/v1/key/value', $ref->invoke($client, 'Testing...api/{api}/key/{key}'));
+ }
+
+ public function testClientAttachersObserversToRequests()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+
+ $client = new Client($this->getServer()->getUrl());
+ $logPlugin = $this->getLogPlugin();
+ $client->getEventDispatcher()->addSubscriber($logPlugin);
+
+ // Get a request from the client and ensure the the observer was
+ // attached to the new request
+ $request = $client->createRequest();
+ $this->assertTrue($this->hasSubscriber($request, $logPlugin));
+ }
+
+ public function testClientReturnsValidBaseUrls()
+ {
+ $client = new Client('http://www.{foo}.{data}/', array(
+ 'data' => '123',
+ 'foo' => 'bar'
+ ));
+ $this->assertEquals('http://www.bar.123/', $client->getBaseUrl());
+ $client->setBaseUrl('http://www.google.com/');
+ $this->assertEquals('http://www.google.com/', $client->getBaseUrl());
+ }
+
+ public function testClientAddsCurlOptionsToRequests()
+ {
+ $client = new Client('http://www.test.com/', array(
+ 'api' => 'v1',
+ // Adds the option using the curl values
+ 'curl.options' => array(
+ 'CURLOPT_HTTPAUTH' => 'CURLAUTH_DIGEST',
+ 'abc' => 'foo',
+ 'blacklist' => 'abc',
+ 'debug' => true
+ )
+ ));
+
+ $request = $client->createRequest();
+ $options = $request->getCurlOptions();
+ $this->assertEquals(CURLAUTH_DIGEST, $options->get(CURLOPT_HTTPAUTH));
+ $this->assertEquals('foo', $options->get('abc'));
+ $this->assertEquals('abc', $options->get('blacklist'));
+ }
+
+ public function testClientAllowsFineGrainedSslControlButIsSecureByDefault()
+ {
+ $client = new Client('https://www.secure.com/');
+
+ // secure by default
+ $request = $client->createRequest();
+ $options = $request->getCurlOptions();
+ $this->assertTrue($options->get(CURLOPT_SSL_VERIFYPEER));
+
+ // set a capath if you prefer
+ $client = new Client('https://www.secure.com/');
+ $client->setSslVerification(__DIR__);
+ $request = $client->createRequest();
+ $options = $request->getCurlOptions();
+ $this->assertSame(__DIR__, $options->get(CURLOPT_CAPATH));
+ }
+
+ public function testConfigSettingsControlSslConfiguration()
+ {
+ // Use the default ca certs on the system
+ $client = new Client('https://www.secure.com/', array('ssl.certificate_authority' => 'system'));
+ $this->assertNull($client->getConfig('curl.options'));
+ // Can set the cacert value as well
+ $client = new Client('https://www.secure.com/', array('ssl.certificate_authority' => false));
+ $options = $client->getConfig('curl.options');
+ $this->assertArrayNotHasKey(CURLOPT_CAINFO, $options);
+ $this->assertSame(false, $options[CURLOPT_SSL_VERIFYPEER]);
+ $this->assertSame(0, $options[CURLOPT_SSL_VERIFYHOST]);
+ }
+
+ public function testClientAllowsUnsafeOperationIfRequested()
+ {
+ // be really unsafe if you insist
+ $client = new Client('https://www.secure.com/', array(
+ 'api' => 'v1'
+ ));
+
+ $client->setSslVerification(false);
+ $request = $client->createRequest();
+ $options = $request->getCurlOptions();
+ $this->assertFalse($options->get(CURLOPT_SSL_VERIFYPEER));
+ $this->assertNull($options->get(CURLOPT_CAINFO));
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\RuntimeException
+ */
+ public function testThrowsExceptionForInvalidCertificate()
+ {
+ $client = new Client('https://www.secure.com/');
+ $client->setSslVerification('/path/to/missing/file');
+ }
+
+ public function testClientAllowsSettingSpecificSslCaInfo()
+ {
+ // set a file other than the provided cacert.pem
+ $client = new Client('https://www.secure.com/', array(
+ 'api' => 'v1'
+ ));
+
+ $client->setSslVerification(__FILE__);
+ $request = $client->createRequest();
+ $options = $request->getCurlOptions();
+ $this->assertSame(__FILE__, $options->get(CURLOPT_CAINFO));
+ }
+
+ /**
+ * @expectedException Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testClientPreventsInadvertentInsecureVerifyHostSetting()
+ {
+ // set a file other than the provided cacert.pem
+ $client = new Client('https://www.secure.com/', array(
+ 'api' => 'v1'
+ ));
+ $client->setSslVerification(__FILE__, true, true);
+ }
+
+ /**
+ * @expectedException Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testClientPreventsInvalidVerifyPeerSetting()
+ {
+ // set a file other than the provided cacert.pem
+ $client = new Client('https://www.secure.com/', array(
+ 'api' => 'v1'
+ ));
+ $client->setSslVerification(__FILE__, 'yes');
+ }
+
+ public function testClientAddsParamsToRequests()
+ {
+ Version::$emitWarnings = false;
+ $client = new Client('http://www.example.com', array(
+ 'api' => 'v1',
+ 'request.params' => array(
+ 'foo' => 'bar',
+ 'baz' => 'jar'
+ )
+ ));
+ $request = $client->createRequest();
+ $this->assertEquals('bar', $request->getParams()->get('foo'));
+ $this->assertEquals('jar', $request->getParams()->get('baz'));
+ Version::$emitWarnings = true;
+ }
+
+ public function urlProvider()
+ {
+ $u = $this->getServer()->getUrl() . 'base/';
+ $u2 = $this->getServer()->getUrl() . 'base?z=1';
+ return array(
+ array($u, '', $u),
+ array($u, 'relative/path/to/resource', $u . 'relative/path/to/resource'),
+ array($u, 'relative/path/to/resource?a=b&c=d', $u . 'relative/path/to/resource?a=b&c=d'),
+ array($u, '/absolute/path/to/resource', $this->getServer()->getUrl() . 'absolute/path/to/resource'),
+ array($u, '/absolute/path/to/resource?a=b&c=d', $this->getServer()->getUrl() . 'absolute/path/to/resource?a=b&c=d'),
+ array($u2, '/absolute/path/to/resource?a=b&c=d', $this->getServer()->getUrl() . 'absolute/path/to/resource?a=b&c=d&z=1'),
+ array($u2, 'relative/path/to/resource', $this->getServer()->getUrl() . 'base/relative/path/to/resource?z=1'),
+ array($u2, 'relative/path/to/resource?another=query', $this->getServer()->getUrl() . 'base/relative/path/to/resource?another=query&z=1')
+ );
+ }
+
+ /**
+ * @dataProvider urlProvider
+ */
+ public function testBuildsRelativeUrls($baseUrl, $url, $result)
+ {
+ $client = new Client($baseUrl);
+ $this->assertEquals($result, $client->get($url)->getUrl());
+ }
+
+ public function testAllowsConfigsToBeChangedAndInjectedInBaseUrl()
+ {
+ $client = new Client('http://{a}/{b}');
+ $this->assertEquals('http:///', $client->getBaseUrl());
+ $this->assertEquals('http://{a}/{b}', $client->getBaseUrl(false));
+ $client->setConfig(array(
+ 'a' => 'test.com',
+ 'b' => 'index.html'
+ ));
+ $this->assertEquals('http://test.com/index.html', $client->getBaseUrl());
+ }
+
+ public function testCreatesRequestsWithDefaultValues()
+ {
+ $client = new Client($this->getServer()->getUrl() . 'base');
+
+ // Create a GET request
+ $request = $client->createRequest();
+ $this->assertEquals('GET', $request->getMethod());
+ $this->assertEquals($client->getBaseUrl(), $request->getUrl());
+
+ // Create a DELETE request
+ $request = $client->createRequest('DELETE');
+ $this->assertEquals('DELETE', $request->getMethod());
+ $this->assertEquals($client->getBaseUrl(), $request->getUrl());
+
+ // Create a HEAD request with custom headers
+ $request = $client->createRequest('HEAD', 'http://www.test.com/');
+ $this->assertEquals('HEAD', $request->getMethod());
+ $this->assertEquals('http://www.test.com/', $request->getUrl());
+
+ // Create a PUT request
+ $request = $client->createRequest('PUT');
+ $this->assertEquals('PUT', $request->getMethod());
+
+ // Create a PUT request with injected config
+ $client->getConfig()->set('a', 1)->set('b', 2);
+ $request = $client->createRequest('PUT', '/path/{a}?q={b}');
+ $this->assertEquals($request->getUrl(), $this->getServer()->getUrl() . 'path/1?q=2');
+ }
+
+ public function testClientHasHelperMethodsForCreatingRequests()
+ {
+ $url = $this->getServer()->getUrl();
+ $client = new Client($url . 'base');
+ $this->assertEquals('GET', $client->get()->getMethod());
+ $this->assertEquals('PUT', $client->put()->getMethod());
+ $this->assertEquals('POST', $client->post()->getMethod());
+ $this->assertEquals('HEAD', $client->head()->getMethod());
+ $this->assertEquals('DELETE', $client->delete()->getMethod());
+ $this->assertEquals('OPTIONS', $client->options()->getMethod());
+ $this->assertEquals('PATCH', $client->patch()->getMethod());
+ $this->assertEquals($url . 'base/abc', $client->get('abc')->getUrl());
+ $this->assertEquals($url . 'zxy', $client->put('/zxy')->getUrl());
+ $this->assertEquals($url . 'zxy?a=b', $client->post('/zxy?a=b')->getUrl());
+ $this->assertEquals($url . 'base?a=b', $client->head('?a=b')->getUrl());
+ $this->assertEquals($url . 'base?a=b', $client->delete('/base?a=b')->getUrl());
+ }
+
+ public function testClientInjectsConfigsIntoUrls()
+ {
+ $client = new Client('http://www.test.com/api/v1', array(
+ 'test' => '123'
+ ));
+ $request = $client->get('relative/{test}');
+ $this->assertEquals('http://www.test.com/api/v1/relative/123', $request->getUrl());
+ }
+
+ public function testAllowsEmptyBaseUrl()
+ {
+ $client = new Client();
+ $request = $client->get('http://www.google.com/');
+ $this->assertEquals('http://www.google.com/', $request->getUrl());
+ $request->setResponse(new Response(200), true);
+ $request->send();
+ }
+
+ public function testAllowsCustomCurlMultiObjects()
+ {
+ $mock = $this->getMock('Guzzle\\Http\\Curl\\CurlMulti', array('add', 'send'));
+ $mock->expects($this->once())
+ ->method('add')
+ ->will($this->returnSelf());
+ $mock->expects($this->once())
+ ->method('send')
+ ->will($this->returnSelf());
+
+ $client = new Client();
+ $client->setCurlMulti($mock);
+
+ $request = $client->get();
+ $request->setResponse(new Response(200), true);
+ $client->send($request);
+ }
+
+ public function testClientSendsMultipleRequests()
+ {
+ $client = new Client($this->getServer()->getUrl());
+ $mock = new MockPlugin();
+
+ $responses = array(
+ new Response(200),
+ new Response(201),
+ new Response(202)
+ );
+
+ $mock->addResponse($responses[0]);
+ $mock->addResponse($responses[1]);
+ $mock->addResponse($responses[2]);
+
+ $client->getEventDispatcher()->addSubscriber($mock);
+
+ $requests = array(
+ $client->get(),
+ $client->head(),
+ $client->put('/', null, 'test')
+ );
+
+ $this->assertEquals(array(
+ $responses[0],
+ $responses[1],
+ $responses[2]
+ ), $client->send($requests));
+ }
+
+ public function testClientSendsSingleRequest()
+ {
+ $client = new Client($this->getServer()->getUrl());
+ $mock = new MockPlugin();
+ $response = new Response(200);
+ $mock->addResponse($response);
+ $client->getEventDispatcher()->addSubscriber($mock);
+ $this->assertEquals($response, $client->send($client->get()));
+ }
+
+ /**
+ * @expectedException \Guzzle\Http\Exception\BadResponseException
+ */
+ public function testClientThrowsExceptionForSingleRequest()
+ {
+ $client = new Client($this->getServer()->getUrl());
+ $mock = new MockPlugin();
+ $response = new Response(404);
+ $mock->addResponse($response);
+ $client->getEventDispatcher()->addSubscriber($mock);
+ $client->send($client->get());
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\ExceptionCollection
+ */
+ public function testClientThrowsExceptionForMultipleRequests()
+ {
+ $client = new Client($this->getServer()->getUrl());
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(200));
+ $mock->addResponse(new Response(404));
+ $client->getEventDispatcher()->addSubscriber($mock);
+ $client->send(array($client->get(), $client->head()));
+ }
+
+ public function testQueryStringsAreNotDoubleEncoded()
+ {
+ $client = new Client('http://test.com', array(
+ 'path' => array('foo', 'bar'),
+ 'query' => 'hi there',
+ 'data' => array(
+ 'test' => 'a&b'
+ )
+ ));
+
+ $request = $client->get('{/path*}{?query,data*}');
+ $this->assertEquals('http://test.com/foo/bar?query=hi%20there&test=a%26b', $request->getUrl());
+ $this->assertEquals('hi there', $request->getQuery()->get('query'));
+ $this->assertEquals('a&b', $request->getQuery()->get('test'));
+ }
+
+ public function testQueryStringsAreNotDoubleEncodedUsingAbsolutePaths()
+ {
+ $client = new Client('http://test.com', array(
+ 'path' => array('foo', 'bar'),
+ 'query' => 'hi there',
+ ));
+ $request = $client->get('http://test.com{?query}');
+ $this->assertEquals('http://test.com?query=hi%20there', $request->getUrl());
+ $this->assertEquals('hi there', $request->getQuery()->get('query'));
+ }
+
+ public function testAllowsUriTemplateInjection()
+ {
+ $client = new Client('http://test.com');
+ $ref = new \ReflectionMethod($client, 'getUriTemplate');
+ $ref->setAccessible(true);
+ $a = $ref->invoke($client);
+ $this->assertSame($a, $ref->invoke($client));
+ $client->setUriTemplate(new UriTemplate());
+ $this->assertNotSame($a, $ref->invoke($client));
+ }
+
+ public function testAllowsCustomVariablesWhenExpandingTemplates()
+ {
+ $client = new Client('http://test.com', array('test' => 'hi'));
+ $ref = new \ReflectionMethod($client, 'expandTemplate');
+ $ref->setAccessible(true);
+ $uri = $ref->invoke($client, 'http://{test}{?query*}', array('query' => array('han' => 'solo')));
+ $this->assertEquals('http://hi?han=solo', $uri);
+ }
+
+ public function testUriArrayAllowsCustomTemplateVariables()
+ {
+ $client = new Client();
+ $vars = array(
+ 'var' => 'hi'
+ );
+ $this->assertEquals('/hi', (string) $client->createRequest('GET', array('/{var}', $vars))->getUrl());
+ $this->assertEquals('/hi', (string) $client->get(array('/{var}', $vars))->getUrl());
+ $this->assertEquals('/hi', (string) $client->put(array('/{var}', $vars))->getUrl());
+ $this->assertEquals('/hi', (string) $client->post(array('/{var}', $vars))->getUrl());
+ $this->assertEquals('/hi', (string) $client->head(array('/{var}', $vars))->getUrl());
+ $this->assertEquals('/hi', (string) $client->options(array('/{var}', $vars))->getUrl());
+ }
+
+ public function testAllowsDefaultHeaders()
+ {
+ Version::$emitWarnings = false;
+ $default = array('X-Test' => 'Hi!');
+ $other = array('X-Other' => 'Foo');
+
+ $client = new Client();
+ $client->setDefaultHeaders($default);
+ $this->assertEquals($default, $client->getDefaultHeaders()->getAll());
+ $client->setDefaultHeaders(new Collection($default));
+ $this->assertEquals($default, $client->getDefaultHeaders()->getAll());
+
+ $request = $client->createRequest('GET', null, $other);
+ $this->assertEquals('Hi!', $request->getHeader('X-Test'));
+ $this->assertEquals('Foo', $request->getHeader('X-Other'));
+
+ $request = $client->createRequest('GET', null, new Collection($other));
+ $this->assertEquals('Hi!', $request->getHeader('X-Test'));
+ $this->assertEquals('Foo', $request->getHeader('X-Other'));
+
+ $request = $client->createRequest('GET');
+ $this->assertEquals('Hi!', $request->getHeader('X-Test'));
+ Version::$emitWarnings = true;
+ }
+
+ public function testDontReuseCurlMulti()
+ {
+ $client1 = new Client();
+ $client2 = new Client();
+ $this->assertNotSame($client1->getCurlMulti(), $client2->getCurlMulti());
+ }
+
+ public function testGetDefaultUserAgent()
+ {
+ $client = new Client();
+ $agent = $this->readAttribute($client, 'userAgent');
+ $version = curl_version();
+ $testAgent = sprintf('Guzzle/%s curl/%s PHP/%s', Version::VERSION, $version['version'], PHP_VERSION);
+ $this->assertEquals($agent, $testAgent);
+
+ $client->setUserAgent('foo');
+ $this->assertEquals('foo', $this->readAttribute($client, 'userAgent'));
+ }
+
+ public function testOverwritesUserAgent()
+ {
+ $client = new Client();
+ $request = $client->createRequest('GET', 'http://www.foo.com', array('User-agent' => 'foo'));
+ $this->assertEquals('foo', (string) $request->getHeader('User-Agent'));
+ }
+
+ public function testUsesDefaultUserAgent()
+ {
+ $client = new Client();
+ $request = $client->createRequest('GET', 'http://www.foo.com');
+ $this->assertContains('Guzzle/', (string) $request->getHeader('User-Agent'));
+ }
+
+ public function testCanSetDefaultRequestOptions()
+ {
+ $client = new Client();
+ $client->getConfig()->set('request.options', array(
+ 'query' => array('test' => '123', 'other' => 'abc'),
+ 'headers' => array('Foo' => 'Bar', 'Baz' => 'Bam')
+ ));
+ $request = $client->createRequest('GET', 'http://www.foo.com?test=hello', array('Foo' => 'Test'));
+ // Explicit options on a request should overrule default options
+ $this->assertEquals('Test', (string) $request->getHeader('Foo'));
+ $this->assertEquals('hello', $request->getQuery()->get('test'));
+ // Default options should still be set
+ $this->assertEquals('abc', $request->getQuery()->get('other'));
+ $this->assertEquals('Bam', (string) $request->getHeader('Baz'));
+ }
+
+ public function testCanSetSetOptionsOnRequests()
+ {
+ $client = new Client();
+ $request = $client->createRequest('GET', 'http://www.foo.com?test=hello', array('Foo' => 'Test'), null, array(
+ 'cookies' => array('michael' => 'test')
+ ));
+ $this->assertEquals('test', $request->getCookie('michael'));
+ }
+
+ public function testHasDefaultOptionsHelperMethods()
+ {
+ $client = new Client();
+ // With path
+ $client->setDefaultOption('headers/foo', 'bar');
+ $this->assertEquals('bar', $client->getDefaultOption('headers/foo'));
+ // With simple key
+ $client->setDefaultOption('allow_redirects', false);
+ $this->assertFalse($client->getDefaultOption('allow_redirects'));
+
+ $this->assertEquals(array(
+ 'headers' => array('foo' => 'bar'),
+ 'allow_redirects' => false
+ ), $client->getConfig('request.options'));
+
+ $request = $client->get('/');
+ $this->assertEquals('bar', $request->getHeader('foo'));
+ }
+
+ public function testHeadCanUseOptions()
+ {
+ $client = new Client();
+ $head = $client->head('http://www.foo.com', array(), array('query' => array('foo' => 'bar')));
+ $this->assertEquals('bar', $head->getQuery()->get('foo'));
+ }
+
+ public function testCanSetRelativeUrlStartingWithHttp()
+ {
+ $client = new Client('http://www.foo.com');
+ $this->assertEquals(
+ 'http://www.foo.com/httpfoo',
+ $client->createRequest('GET', 'httpfoo')->getUrl()
+ );
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlHandleTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlHandleTest.php
new file mode 100644
index 0000000..5bf28de
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlHandleTest.php
@@ -0,0 +1,947 @@
+<?php
+
+namespace Guzzle\Tests\Http\Curl;
+
+use Guzzle\Common\Collection;
+use Guzzle\Common\Event;
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\QueryString;
+use Guzzle\Http\Client;
+use Guzzle\Http\Message\RequestFactory;
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Http\Curl\CurlHandle;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\Curl\CurlHandle
+ */
+class CurlHandleTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public $requestHandle;
+
+ protected function updateForHandle(RequestInterface $request)
+ {
+ $that = $this;
+ $request->getEventDispatcher()->addListener('request.sent', function (Event $e) use ($that) {
+ $that->requestHandle = $e['handle'];
+ });
+
+ return $request;
+ }
+
+ public function setUp()
+ {
+ $this->requestHandle = null;
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testConstructorExpectsCurlResource()
+ {
+ $h = new CurlHandle(false, array());
+ }
+
+ public function testConstructorExpectsProperOptions()
+ {
+ $h = curl_init($this->getServer()->getUrl());
+ try {
+ $ha = new CurlHandle($h, false);
+ $this->fail('Expected InvalidArgumentException');
+ } catch (\InvalidArgumentException $e) {
+ }
+
+ $ha = new CurlHandle($h, array(
+ CURLOPT_URL => $this->getServer()->getUrl()
+ ));
+ $this->assertEquals($this->getServer()->getUrl(), $ha->getOptions()->get(CURLOPT_URL));
+
+ $ha = new CurlHandle($h, new Collection(array(
+ CURLOPT_URL => $this->getServer()->getUrl()
+ )));
+ $this->assertEquals($this->getServer()->getUrl(), $ha->getOptions()->get(CURLOPT_URL));
+ }
+
+ public function testConstructorInitializesObject()
+ {
+ $handle = curl_init($this->getServer()->getUrl());
+ $h = new CurlHandle($handle, array(
+ CURLOPT_URL => $this->getServer()->getUrl()
+ ));
+ $this->assertSame($handle, $h->getHandle());
+ $this->assertInstanceOf('Guzzle\\Http\\Url', $h->getUrl());
+ $this->assertEquals($this->getServer()->getUrl(), (string) $h->getUrl());
+ $this->assertEquals($this->getServer()->getUrl(), $h->getOptions()->get(CURLOPT_URL));
+ }
+
+ public function testStoresStdErr()
+ {
+ $request = RequestFactory::getInstance()->create('GET', 'http://test.com');
+ $request->getCurlOptions()->set('debug', true);
+ $h = CurlHandle::factory($request);
+ $this->assertEquals($h->getStderr(true), $h->getOptions()->get(CURLOPT_STDERR));
+ $this->assertInternalType('resource', $h->getStderr(true));
+ $this->assertInternalType('string', $h->getStderr(false));
+ $r = $h->getStderr(true);
+ fwrite($r, 'test');
+ $this->assertEquals('test', $h->getStderr(false));
+ }
+
+ public function testStoresCurlErrorNumber()
+ {
+ $h = new CurlHandle(curl_init('http://test.com'), array(CURLOPT_URL => 'http://test.com'));
+ $this->assertEquals(CURLE_OK, $h->getErrorNo());
+ $h->setErrorNo(CURLE_OPERATION_TIMEOUTED);
+ $this->assertEquals(CURLE_OPERATION_TIMEOUTED, $h->getErrorNo());
+ }
+
+ public function testAccountsForMissingStdErr()
+ {
+ $handle = curl_init('http://www.test.com/');
+ $h = new CurlHandle($handle, array(
+ CURLOPT_URL => 'http://www.test.com/'
+ ));
+ $this->assertNull($h->getStderr(false));
+ }
+
+ public function testDeterminesIfResourceIsAvailable()
+ {
+ $handle = curl_init($this->getServer()->getUrl());
+ $h = new CurlHandle($handle, array());
+ $this->assertTrue($h->isAvailable());
+
+ // Mess it up by closing the handle
+ curl_close($handle);
+ $this->assertFalse($h->isAvailable());
+
+ // Mess it up by unsetting the handle
+ $handle = null;
+ $this->assertFalse($h->isAvailable());
+ }
+
+ public function testWrapsErrorsAndInfo()
+ {
+ if (!defined('CURLOPT_TIMEOUT_MS')) {
+ $this->markTestSkipped('Update curl');
+ }
+
+ $settings = array(
+ CURLOPT_PORT => 123,
+ CURLOPT_CONNECTTIMEOUT_MS => 1,
+ CURLOPT_TIMEOUT_MS => 1
+ );
+
+ $handle = curl_init($this->getServer()->getUrl());
+ curl_setopt_array($handle, $settings);
+ $h = new CurlHandle($handle, $settings);
+ @curl_exec($handle);
+
+ $errors = array(
+ "couldn't connect to host",
+ 'timeout was reached',
+ 'connection time-out',
+ 'connect() timed out!',
+ 'failed connect to 127.0.0.1:123; connection refused',
+ 'failed to connect to 127.0.0.1 port 123: connection refused'
+ );
+ $this->assertTrue(in_array(strtolower($h->getError()), $errors), $h->getError() . ' was not the error');
+
+ $this->assertTrue($h->getErrorNo() > 0);
+
+ $this->assertEquals($this->getServer()->getUrl(), $h->getInfo(CURLINFO_EFFECTIVE_URL));
+ $this->assertInternalType('array', $h->getInfo());
+
+ curl_close($handle);
+ $this->assertEquals(null, $h->getInfo('url'));
+ }
+
+ public function testGetInfoWithoutDebugMode()
+ {
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get($this->getServer()->getUrl());
+ $response = $request->send();
+
+ $info = $response->getInfo();
+ $this->assertFalse(empty($info));
+ $this->assertEquals($this->getServer()->getUrl(), $info['url']);
+ }
+
+ public function testWrapsCurlOptions()
+ {
+ $handle = curl_init($this->getServer()->getUrl());
+ $h = new CurlHandle($handle, array(
+ CURLOPT_AUTOREFERER => true,
+ CURLOPT_BUFFERSIZE => 1024
+ ));
+
+ $this->assertEquals(true, $h->getOptions()->get(CURLOPT_AUTOREFERER));
+ $this->assertEquals(1024, $h->getOptions()->get(CURLOPT_BUFFERSIZE));
+ }
+
+ /**
+ * Data provider for factory tests
+ *
+ * @return array
+ */
+ public function dataProvider()
+ {
+ $testFile = __DIR__ . '/../../../../../phpunit.xml.dist';
+
+ $postBody = new QueryString(array('file' => '@' . $testFile));
+ $qs = new QueryString(array(
+ 'x' => 'y',
+ 'z' => 'a'
+ ));
+
+ $client = new Client();
+ $userAgent = $client->getDefaultUserAgent();
+ $auth = base64_encode('michael:123');
+ $testFileSize = filesize($testFile);
+
+ $tests = array(
+ // Send a regular GET
+ array('GET', 'http://www.google.com/', null, null, array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_HTTPHEADER => array('Accept:', 'Host: www.google.com', 'User-Agent: ' . $userAgent),
+ )),
+ // Test that custom request methods can be used
+ array('TRACE', 'http://www.google.com/', null, null, array(
+ CURLOPT_CUSTOMREQUEST => 'TRACE'
+ )),
+ // Send a GET using a port
+ array('GET', 'http://127.0.0.1:8080', null, null, array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_PORT => 8080,
+ CURLOPT_HTTPHEADER => array('Accept:', 'Host: 127.0.0.1:8080', 'User-Agent: ' . $userAgent),
+ )),
+ // Send a HEAD request
+ array('HEAD', 'http://www.google.com/', null, null, array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_HTTPHEADER => array('Accept:', 'Host: www.google.com', 'User-Agent: ' . $userAgent),
+ CURLOPT_NOBODY => 1
+ )),
+ // Send a GET using basic auth
+ array('GET', 'https://michael:123@127.0.0.1/index.html?q=2', null, null, array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_HTTPHEADER => array(
+ 'Accept:',
+ 'Host: 127.0.0.1',
+ 'Authorization: Basic ' . $auth,
+ 'User-Agent: ' . $userAgent
+ ),
+ CURLOPT_PORT => 443
+ )),
+ // Send a GET request with custom headers
+ array('GET', 'http://127.0.0.1:8124/', array(
+ 'x-test-data' => 'Guzzle'
+ ), null, array(
+ CURLOPT_PORT => 8124,
+ CURLOPT_HTTPHEADER => array(
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'x-test-data: Guzzle',
+ 'User-Agent: ' . $userAgent
+ )
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'x-test-data' => 'Guzzle'
+ )),
+ // Send a POST using a query string
+ array('POST', 'http://127.0.0.1:8124/post.php', null, $qs, array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_POSTFIELDS => 'x=y&z=a',
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
+ 'User-Agent: ' . $userAgent
+ )
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'Content-Length' => '7',
+ '!Expect' => null,
+ 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
+ '!Transfer-Encoding' => null
+ )),
+ // Send a PUT using raw data
+ array('PUT', 'http://127.0.0.1:8124/put.php', null, EntityBody::factory(fopen($testFile, 'r+')), array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_READFUNCTION => 'callback',
+ CURLOPT_INFILESIZE => filesize($testFile),
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'User-Agent: ' . $userAgent
+ )
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ '!Expect' => null,
+ 'Content-Length' => $testFileSize,
+ '!Transfer-Encoding' => null
+ )),
+ // Send a POST request using an array of fields
+ array('POST', 'http://127.0.0.1:8124/post.php', null, array(
+ 'x' => 'y',
+ 'a' => 'b'
+ ), array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_POST => 1,
+ CURLOPT_POSTFIELDS => 'x=y&a=b',
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
+ 'User-Agent: ' . $userAgent
+ )
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'Content-Length' => '7',
+ '!Expect' => null,
+ 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
+ '!Transfer-Encoding' => null
+ )),
+ // Send a POST request with raw POST data and a custom content-type
+ array('POST', 'http://127.0.0.1:8124/post.php', array(
+ 'Content-Type' => 'application/json'
+ ), '{"hi":"there"}', array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_UPLOAD => true,
+ CURLOPT_INFILESIZE => 14,
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'Content-Type: application/json',
+ 'User-Agent: ' . $userAgent
+ ),
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'Content-Type' => 'application/json',
+ '!Expect' => null,
+ 'Content-Length' => '14',
+ '!Transfer-Encoding' => null
+ )),
+ // Send a POST request with raw POST data, a custom content-type, and use chunked encoding
+ array('POST', 'http://127.0.0.1:8124/post.php', array(
+ 'Content-Type' => 'application/json',
+ 'Transfer-Encoding' => 'chunked'
+ ), '{"hi":"there"}', array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_UPLOAD => true,
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'Transfer-Encoding: chunked',
+ 'Content-Type: application/json',
+ 'User-Agent: ' . $userAgent
+ ),
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'Content-Type' => 'application/json',
+ '!Expect' => null,
+ 'Transfer-Encoding' => 'chunked',
+ '!Content-Length' => ''
+ )),
+ // Send a POST request with no body
+ array('POST', 'http://127.0.0.1:8124/post.php', null, '', array(
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'User-Agent: ' . $userAgent
+ )
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'Content-Length' => '0',
+ '!Transfer-Encoding' => null
+ )),
+ // Send a POST request with empty post fields
+ array('POST', 'http://127.0.0.1:8124/post.php', null, array(), array(
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'User-Agent: ' . $userAgent
+ )
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'Content-Length' => '0',
+ '!Transfer-Encoding' => null
+ )),
+ // Send a PATCH request
+ array('PATCH', 'http://127.0.0.1:8124/patch.php', null, 'body', array(
+ CURLOPT_INFILESIZE => 4,
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'User-Agent: ' . $userAgent
+ )
+ )),
+ // Send a DELETE request with a body
+ array('DELETE', 'http://127.0.0.1:8124/delete.php', null, 'body', array(
+ CURLOPT_CUSTOMREQUEST => 'DELETE',
+ CURLOPT_INFILESIZE => 4,
+ CURLOPT_HTTPHEADER => array (
+ 'Expect:',
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'User-Agent: ' . $userAgent
+ )
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'Content-Length' => '4',
+ '!Expect' => null,
+ '!Transfer-Encoding' => null
+ )),
+
+ /**
+ * Send a request with empty path and a fragment - the fragment must be
+ * stripped out before sending it to curl
+ *
+ * @issue 453
+ * @link https://github.com/guzzle/guzzle/issues/453
+ */
+ array('GET', 'http://www.google.com#head', null, null, array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_HTTPHEADER => array('Accept:', 'Host: www.google.com', 'User-Agent: ' . $userAgent),
+ )),
+ );
+
+ $postTest = array('POST', 'http://127.0.0.1:8124/post.php', null, $postBody, array(
+ CURLOPT_RETURNTRANSFER => 0,
+ CURLOPT_HEADER => 0,
+ CURLOPT_CONNECTTIMEOUT => 150,
+ CURLOPT_WRITEFUNCTION => 'callback',
+ CURLOPT_HEADERFUNCTION => 'callback',
+ CURLOPT_POST => 1,
+ CURLOPT_POSTFIELDS => array(
+ 'file' => '@' . $testFile . ';filename=phpunit.xml.dist;type=application/octet-stream'
+ ),
+ CURLOPT_HTTPHEADER => array (
+ 'Accept:',
+ 'Host: 127.0.0.1:8124',
+ 'Content-Type: multipart/form-data',
+ 'Expect: 100-Continue',
+ 'User-Agent: ' . $userAgent
+ )
+ ), array(
+ 'Host' => '*',
+ 'User-Agent' => '*',
+ 'Content-Length' => '*',
+ 'Expect' => '100-Continue',
+ 'Content-Type' => 'multipart/form-data; boundary=*',
+ '!Transfer-Encoding' => null
+ ));
+
+ if (version_compare(phpversion(), '5.5.0', '>=')) {
+ $postTest[4][CURLOPT_POSTFIELDS] = array(
+ 'file' => new \CurlFile($testFile, 'application/octet-stream', 'phpunit.xml.dist')
+ );
+ }
+
+ $tests[] = $postTest;
+
+ return $tests;
+ }
+
+ /**
+ * @dataProvider dataProvider
+ */
+ public function testFactoryCreatesCurlBasedOnRequest($method, $url, $headers, $body, $options, $expectedHeaders = null)
+ {
+ $client = new Client();
+ $request = $client->createRequest($method, $url, $headers, $body);
+ $request->getCurlOptions()->set('debug', true);
+
+ $originalRequest = clone $request;
+ $curlTest = clone $request;
+ $handle = CurlHandle::factory($curlTest);
+
+ $this->assertInstanceOf('Guzzle\\Http\\Curl\\CurlHandle', $handle);
+ $o = $handle->getOptions()->getAll();
+
+ // Headers are case-insensitive
+ if (isset($o[CURLOPT_HTTPHEADER])) {
+ $o[CURLOPT_HTTPHEADER] = array_map('strtolower', $o[CURLOPT_HTTPHEADER]);
+ }
+ if (isset($options[CURLOPT_HTTPHEADER])) {
+ $options[CURLOPT_HTTPHEADER] = array_map('strtolower', $options[CURLOPT_HTTPHEADER]);
+ }
+
+ $check = 0;
+ foreach ($options as $key => $value) {
+ $check++;
+ $this->assertArrayHasKey($key, $o, '-> Check number ' . $check);
+ if ($key != CURLOPT_HTTPHEADER && $key != CURLOPT_POSTFIELDS && (is_array($o[$key])) || $o[$key] instanceof \Closure) {
+ $this->assertEquals('callback', $value, '-> Check number ' . $check);
+ } else {
+ $this->assertTrue($value == $o[$key], '-> Check number ' . $check . ' - ' . var_export($value, true) . ' != ' . var_export($o[$key], true));
+ }
+ }
+
+ // If we are testing the actual sent headers
+ if ($expectedHeaders) {
+
+ // Send the request to the test server
+ $client = new Client($this->getServer()->getUrl());
+ $request->setClient($client);
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request->send();
+
+ // Get the request that was sent and create a request that we expected
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals($method, $requests[0]->getMethod());
+
+ $test = $this->compareHeaders($expectedHeaders, $requests[0]->getHeaders());
+ $this->assertFalse($test, $test . "\nSent: \n" . $request . "\n\n" . $requests[0]);
+
+ // Ensure only one Content-Length header is sent
+ if ($request->getHeader('Content-Length')) {
+ $this->assertEquals((string) $request->getHeader('Content-Length'), (string) $requests[0]->getHeader('Content-Length'));
+ }
+ }
+ }
+
+ public function testFactoryUsesSpecifiedProtocol()
+ {
+ $request = RequestFactory::getInstance()->create('GET', 'http://127.0.0.1:8124/');
+ $request->setProtocolVersion('1.1');
+ $handle = CurlHandle::factory($request);
+ $options = $handle->getOptions();
+ $this->assertEquals(CURL_HTTP_VERSION_1_1, $options[CURLOPT_HTTP_VERSION]);
+ }
+
+ public function testUploadsPutData()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put('/');
+ $request->getCurlOptions()->set('debug', true);
+ $request->setBody(EntityBody::factory('test'), 'text/plain', false);
+ $request->getCurlOptions()->set('progress', true);
+
+ $o = $this->getWildcardObserver($request);
+ $request->send();
+
+ // Make sure that the events were dispatched
+ $this->assertTrue($o->has('curl.callback.progress'));
+
+ // Ensure that the request was received exactly as intended
+ $r = $this->getServer()->getReceivedRequests(true);
+ $this->assertFalse($r[0]->hasHeader('Transfer-Encoding'));
+ $this->assertEquals(4, (string) $r[0]->getHeader('Content-Length'));
+ $sent = strtolower($r[0]);
+ $this->assertContains('put / http/1.1', $sent);
+ $this->assertContains('host: 127.0.0.1', $sent);
+ $this->assertContains('user-agent:', $sent);
+ $this->assertContains('content-type: text/plain', $sent);
+ }
+
+ public function testUploadsPutDataUsingChunkedEncodingWhenLengthCannotBeDetermined()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi"
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put('/');
+ $request->setBody(EntityBody::factory(fopen($this->getServer()->getUrl(), 'r')), 'text/plain');
+ $request->send();
+
+ $r = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('chunked', $r[1]->getHeader('Transfer-Encoding'));
+ $this->assertFalse($r[1]->hasHeader('Content-Length'));
+ }
+
+ public function testUploadsPutDataUsingChunkedEncodingWhenForced()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put('/', array('Transfer-Encoding' => 'chunked'), 'hi!');
+ $request->send();
+
+ $r = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('chunked', $r[0]->getHeader('Transfer-Encoding'));
+ $this->assertFalse($r[0]->hasHeader('Content-Length'));
+ $this->assertEquals('hi!', $r[0]->getBody(true));
+ }
+
+ public function testSendsPostRequestsWithFields()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
+
+ $request = RequestFactory::getInstance()->create('POST', $this->getServer()->getUrl());
+ $request->getCurlOptions()->set('debug', true);
+ $request->setClient(new Client());
+ $request->addPostFields(array(
+ 'a' => 'b',
+ 'c' => 'ay! ~This is a test, isn\'t it?'
+ ));
+ $request->send();
+
+ // Make sure that the request was sent correctly
+ $r = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('a=b&c=ay%21%20~This%20is%20a%20test%2C%20isn%27t%20it%3F', (string) $r[0]->getBody());
+ $this->assertFalse($r[0]->hasHeader('Transfer-Encoding'));
+ $this->assertEquals(56, (string) $r[0]->getHeader('Content-Length'));
+ $sent = strtolower($r[0]);
+ $this->assertContains('post / http/1.1', $sent);
+ $this->assertContains('content-type: application/x-www-form-urlencoded; charset=utf-8', $sent);
+ }
+
+ public function testSendsPostRequestsWithFiles()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
+
+ $request = RequestFactory::getInstance()->create('POST', $this->getServer()->getUrl());
+ $request->getCurlOptions()->set('debug', true);
+ $request->setClient(new Client());
+ $request->addPostFiles(array(
+ 'foo' => __FILE__,
+ ));
+ $request->addPostFields(array(
+ 'bar' => 'baz',
+ 'arr' => array('a' => 1, 'b' => 2),
+ ));
+ $this->updateForHandle($request);
+ $request->send();
+
+ // Ensure the CURLOPT_POSTFIELDS option was set properly
+ $options = $this->requestHandle->getOptions()->getAll();
+ if (version_compare(phpversion(), '5.5.0', '<')) {
+ $this->assertContains('@' . __FILE__ . ';filename=CurlHandleTest.php;type=text/x-', $options[CURLOPT_POSTFIELDS]['foo']);
+ } else{
+ $this->assertInstanceOf('CURLFile', $options[CURLOPT_POSTFIELDS]['foo']);
+ }
+ $this->assertEquals('baz', $options[CURLOPT_POSTFIELDS]['bar']);
+ $this->assertEquals('1', $options[CURLOPT_POSTFIELDS]['arr[a]']);
+ $this->assertEquals('2', $options[CURLOPT_POSTFIELDS]['arr[b]']);
+ // Ensure that a Content-Length header was sent by cURL
+ $this->assertTrue($request->hasHeader('Content-Length'));
+ }
+
+ public function testCurlConfigurationOptionsAreSet()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', $this->getServer()->getUrl());
+ $request->setClient(new Client('http://www.example.com'));
+ $request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT, 99);
+ $request->getCurlOptions()->set('curl.fake_opt', 99);
+ $request->getCurlOptions()->set(CURLOPT_PORT, 8181);
+ $handle = CurlHandle::factory($request);
+ $this->assertEquals(99, $handle->getOptions()->get(CURLOPT_CONNECTTIMEOUT));
+ $this->assertEquals(8181, $handle->getOptions()->get(CURLOPT_PORT));
+ $this->assertNull($handle->getOptions()->get('curl.fake_opt'));
+ $this->assertNull($handle->getOptions()->get('fake_opt'));
+ }
+
+ public function testEnsuresRequestsHaveResponsesWhenUpdatingFromTransfer()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', $this->getServer()->getUrl());
+ $handle = CurlHandle::factory($request);
+ $handle->updateRequestFromTransfer($request);
+ }
+
+ public function testCanSendBodyAsString()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put('/', null, 'foo');
+ $request->getCurlOptions()->set('body_as_string', true);
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(false);
+ $this->assertContains('PUT /', $requests[0]);
+ $this->assertContains("\nfoo", $requests[0]);
+ $this->assertContains('content-length: 3', $requests[0]);
+ $this->assertNotContains('content-type', $requests[0]);
+ }
+
+ public function testCanSendPostBodyAsString()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->post('/', null, 'foo');
+ $request->getCurlOptions()->set('body_as_string', true);
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(false);
+ $this->assertContains('POST /', $requests[0]);
+ $this->assertContains("\nfoo", $requests[0]);
+ $this->assertContains('content-length: 3', $requests[0]);
+ $this->assertNotContains('content-type', $requests[0]);
+ }
+
+ public function testAllowsWireTransferInfoToBeEnabled()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', $this->getServer()->getUrl());
+ $request->getCurlOptions()->set('debug', true);
+ $handle = CurlHandle::factory($request);
+ $this->assertNotNull($handle->getOptions()->get(CURLOPT_STDERR));
+ $this->assertNotNull($handle->getOptions()->get(CURLOPT_VERBOSE));
+ }
+
+ public function testAddsCustomCurlOptions()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', $this->getServer()->getUrl());
+ $request->getCurlOptions()->set(CURLOPT_TIMEOUT, 200);
+ $handle = CurlHandle::factory($request);
+ $this->assertEquals(200, $handle->getOptions()->get(CURLOPT_TIMEOUT));
+ }
+
+ public function testSendsPostUploadsWithContentDispositionHeaders()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n");
+
+ $fileToUpload = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'TestData' . DIRECTORY_SEPARATOR . 'test_service.json';
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->post();
+ $request->addPostFile('foo', $fileToUpload, 'application/json');
+ $request->addPostFile('foo', __FILE__);
+
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $body = (string) $requests[0]->getBody();
+
+ $this->assertContains('Content-Disposition: form-data; name="foo[0]"; filename="', $body);
+ $this->assertContains('Content-Type: application/json', $body);
+ $this->assertContains('Content-Type: text/x-', $body);
+ $this->assertContains('Content-Disposition: form-data; name="foo[1]"; filename="', $body);
+ }
+
+ public function requestMethodProvider()
+ {
+ return array(array('POST'), array('PUT'), array('PATCH'));
+ }
+
+ /**
+ * @dataProvider requestMethodProvider
+ */
+ public function testSendsRequestsWithNoBodyUsingContentLengthZero($method)
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $client = new Client($this->getServer()->getUrl());
+ $client->createRequest($method)->send();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertFalse($requests[0]->hasHeader('Transfer-Encoding'));
+ $this->assertTrue($requests[0]->hasHeader('Content-Length'));
+ $this->assertEquals('0', (string) $requests[0]->getHeader('Content-Length'));
+ }
+
+ /**
+ * @dataProvider provideCurlConfig
+ */
+ public function testParseCurlConfigConvertsStringKeysToConstantKeys($options, $expected)
+ {
+ $actual = CurlHandle::parseCurlConfig($options);
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * Data provider for curl configurations
+ *
+ * @return array
+ */
+ public function provideCurlConfig()
+ {
+ return array(
+ // Conversion of option name to constant value
+ array(
+ array(
+ 'CURLOPT_PORT' => 10,
+ 'CURLOPT_TIMEOUT' => 99
+ ),
+ array(
+ CURLOPT_PORT => 10,
+ CURLOPT_TIMEOUT => 99
+ )
+ ),
+ // Keeps non constant options
+ array(
+ array('debug' => true),
+ array('debug' => true)
+ ),
+ // Conversion of constant names to constant values
+ array(
+ array('debug' => 'CURLPROXY_HTTP'),
+ array('debug' => CURLPROXY_HTTP)
+ )
+ );
+ }
+
+ public function testSeeksToBeginningOfStreamWhenSending()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
+ ));
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put('/', null, 'test');
+ $request->send();
+ $request->send();
+
+ $received = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals(2, count($received));
+ $this->assertEquals('test', (string) $received[0]->getBody());
+ $this->assertEquals('test', (string) $received[1]->getBody());
+ }
+
+ public function testAllowsCurloptEncodingToBeSet()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get('/', null);
+ $request->getCurlOptions()->set(CURLOPT_ENCODING, '');
+ $this->updateForHandle($request);
+ $request->send();
+ $options = $this->requestHandle->getOptions()->getAll();
+ $this->assertSame('', $options[CURLOPT_ENCODING]);
+ $received = $this->getServer()->getReceivedRequests(false);
+ $this->assertContainsIns('accept: */*', $received[0]);
+ $this->assertContainsIns('accept-encoding: ', $received[0]);
+ }
+
+ public function testSendsExpectHeaderWhenSizeIsGreaterThanCutoff()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put('/', null, 'test');
+ // Start sending the expect header to 2 bytes
+ $this->updateForHandle($request);
+ $request->setExpectHeaderCutoff(2)->send();
+ $options = $this->requestHandle->getOptions()->getAll();
+ $this->assertContains('Expect: 100-Continue', $options[CURLOPT_HTTPHEADER]);
+ $received = $this->getServer()->getReceivedRequests(false);
+ $this->assertContainsIns('expect: 100-continue', $received[0]);
+ }
+
+ public function testSetsCurloptEncodingWhenAcceptEncodingHeaderIsSet()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ndata");
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get('/', array(
+ 'Accept' => 'application/json',
+ 'Accept-Encoding' => 'gzip, deflate',
+ ));
+ $this->updateForHandle($request);
+ $request->send();
+ $options = $this->requestHandle->getOptions()->getAll();
+ $this->assertSame('gzip, deflate', $options[CURLOPT_ENCODING]);
+ $received = $this->getServer()->getReceivedRequests(false);
+ $this->assertContainsIns('accept: application/json', $received[0]);
+ $this->assertContainsIns('accept-encoding: gzip, deflate', $received[0]);
+ }
+
+ public function testSendsPostFieldsForNonPostRequests()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n");
+
+ $client = new Client();
+ $request = $client->put($this->getServer()->getUrl(), null, array(
+ 'foo' => 'baz',
+ 'baz' => 'bar'
+ ));
+
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('PUT', $requests[0]->getMethod());
+ $this->assertEquals(
+ 'application/x-www-form-urlencoded; charset=utf-8',
+ (string) $requests[0]->getHeader('Content-Type')
+ );
+ $this->assertEquals(15, (string) $requests[0]->getHeader('Content-Length'));
+ $this->assertEquals('foo=baz&baz=bar', (string) $requests[0]->getBody());
+ }
+
+ public function testSendsPostFilesForNonPostRequests()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n");
+
+ $client = new Client();
+ $request = $client->put($this->getServer()->getUrl(), null, array(
+ 'foo' => '@' . __FILE__
+ ));
+
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('PUT', $requests[0]->getMethod());
+ $this->assertContains('multipart/form-data', (string) $requests[0]->getHeader('Content-Type'));
+ $this->assertContains('testSendsPostFilesForNonPostRequests', (string) $requests[0]->getBody());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlMultiProxyTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlMultiProxyTest.php
new file mode 100644
index 0000000..e04141c
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlMultiProxyTest.php
@@ -0,0 +1,110 @@
+<?php
+
+namespace Guzzle\Tests\Http\Curl;
+
+use Guzzle\Http\Client;
+use Guzzle\Http\Message\Request;
+use Guzzle\Http\Curl\CurlMultiProxy;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\Curl\CurlMultiProxy
+ */
+class CurlMultiProxyTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ const SELECT_TIMEOUT = 23.1;
+
+ const MAX_HANDLES = 2;
+
+ /** @var \Guzzle\Http\Curl\CurlMultiProxy */
+ private $multi;
+
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->multi = new CurlMultiProxy(self::MAX_HANDLES, self::SELECT_TIMEOUT);
+ }
+
+ public function tearDown()
+ {
+ unset($this->multi);
+ }
+
+ public function testConstructorSetsMaxHandles()
+ {
+ $m = new CurlMultiProxy(self::MAX_HANDLES, self::SELECT_TIMEOUT);
+ $this->assertEquals(self::MAX_HANDLES, $this->readAttribute($m, 'maxHandles'));
+ }
+
+ public function testConstructorSetsSelectTimeout()
+ {
+ $m = new CurlMultiProxy(self::MAX_HANDLES, self::SELECT_TIMEOUT);
+ $this->assertEquals(self::SELECT_TIMEOUT, $this->readAttribute($m, 'selectTimeout'));
+ }
+
+ public function testAddingRequestsAddsToQueue()
+ {
+ $r = new Request('GET', 'http://www.foo.com');
+ $this->assertSame($this->multi, $this->multi->add($r));
+ $this->assertEquals(1, count($this->multi));
+ $this->assertEquals(array($r), $this->multi->all());
+
+ $this->assertTrue($this->multi->remove($r));
+ $this->assertFalse($this->multi->remove($r));
+ $this->assertEquals(0, count($this->multi));
+ }
+
+ public function testResetClearsState()
+ {
+ $r = new Request('GET', 'http://www.foo.com');
+ $this->multi->add($r);
+ $this->multi->reset();
+ $this->assertEquals(0, count($this->multi));
+ }
+
+ public function testSendWillSendQueuedRequestsFirst()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $events = array();
+ $client->getCurlMulti()->getEventDispatcher()->addListener(
+ CurlMultiProxy::ADD_REQUEST,
+ function ($e) use (&$events) {
+ $events[] = $e;
+ }
+ );
+ $request = $client->get();
+ $request->getEventDispatcher()->addListener('request.complete', function () use ($client) {
+ $client->get('/foo')->send();
+ });
+ $request->send();
+ $received = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals(2, count($received));
+ $this->assertEquals($this->getServer()->getUrl(), $received[0]->getUrl());
+ $this->assertEquals($this->getServer()->getUrl() . 'foo', $received[1]->getUrl());
+ $this->assertEquals(2, count($events));
+ }
+
+ public function testTrimsDownMaxHandleCount()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 307 OK\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 307 OK\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 307 OK\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 307 OK\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $client->setCurlMulti(new CurlMultiProxy(self::MAX_HANDLES, self::SELECT_TIMEOUT));
+ $request = $client->get();
+ $request->send();
+ $this->assertEquals(200, $request->getResponse()->getStatusCode());
+ $handles = $this->readAttribute($client->getCurlMulti(), 'handles');
+ $this->assertEquals(2, count($handles));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlMultiTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlMultiTest.php
new file mode 100644
index 0000000..1272281
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlMultiTest.php
@@ -0,0 +1,455 @@
+<?php
+
+namespace Guzzle\Tests\Http\Curl;
+
+use Guzzle\Common\Event;
+use Guzzle\Http\Exception\BadResponseException;
+use Guzzle\Http\Exception\MultiTransferException;
+use Guzzle\Http\Client;
+use Guzzle\Http\Message\Request;
+use Guzzle\Http\Message\Response;
+use Guzzle\Http\Message\RequestFactory;
+use Guzzle\Http\Curl\CurlMulti;
+use Guzzle\Http\Exception\CurlException;
+use Guzzle\Tests\Mock\MockMulti;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\Curl\CurlMulti
+ */
+class CurlMultiTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /** @var \Guzzle\Http\Curl\CurlMulti */
+ private $multi;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->multi = new MockMulti();
+ }
+
+ public function tearDown()
+ {
+ unset($this->multi);
+ }
+
+ public function testConstructorCreateMultiHandle()
+ {
+ $this->assertInternalType('resource', $this->multi->getHandle());
+ $this->assertEquals('curl_multi', get_resource_type($this->multi->getHandle()));
+ }
+
+ public function testDestructorClosesMultiHandle()
+ {
+ $handle = $this->multi->getHandle();
+ $this->multi->__destruct();
+ $this->assertFalse(is_resource($handle));
+ }
+
+ public function testRequestsCanBeAddedAndCounted()
+ {
+ $multi = new CurlMulti();
+ $request1 = new Request('GET', 'http://www.google.com/');
+ $multi->add($request1);
+ $this->assertEquals(array($request1), $multi->all());
+ $request2 = new Request('POST', 'http://www.google.com/');
+ $multi->add($request2);
+ $this->assertEquals(array($request1, $request2), $multi->all());
+ $this->assertEquals(2, count($multi));
+ }
+
+ public function testRequestsCanBeRemoved()
+ {
+ $request1 = new Request('GET', 'http://www.google.com/');
+ $this->multi->add($request1);
+ $request2 = new Request('PUT', 'http://www.google.com/');
+ $this->multi->add($request2);
+ $this->assertEquals(array($request1, $request2), $this->multi->all());
+ $this->assertTrue($this->multi->remove($request1));
+ $this->assertFalse($this->multi->remove($request1));
+ $this->assertEquals(array($request2), $this->multi->all());
+ }
+
+ public function testsResetRemovesRequestsAndResetsState()
+ {
+ $this->multi->add(new Request('GET', 'http://www.google.com/'));
+ $this->multi->reset();
+ $this->assertEquals(array(), $this->multi->all());
+ }
+
+ public function testSendsRequestsThroughCurl()
+ {
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 204 No content\r\n" .
+ "Content-Length: 0\r\n" .
+ "Server: Jetty(6.1.3)\r\n\r\n",
+ "HTTP/1.1 200 OK\r\n" .
+ "Content-Type: text/html; charset=utf-8\r\n" .
+ "Content-Length: 4\r\n" .
+ "Server: Jetty(6.1.3)\r\n\r\n" .
+ "data"
+ ));
+
+ $request1 = new Request('GET', $this->getServer()->getUrl());
+ $request2 = new Request('GET', $this->getServer()->getUrl());
+ $this->multi->add($request1);
+ $this->multi->add($request2);
+ $this->multi->send();
+
+ $response1 = $request1->getResponse();
+ $response2 = $request2->getResponse();
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $response1);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $response2);
+
+ $this->assertTrue($response1->getBody(true) == 'data' || $response2->getBody(true) == 'data');
+ $this->assertTrue($response1->getBody(true) == '' || $response2->getBody(true) == '');
+ $this->assertTrue($response1->getStatusCode() == '204' || $response2->getStatusCode() == '204');
+ $this->assertNotEquals((string) $response1, (string) $response2);
+ }
+
+ public function testSendsThroughCurlAndAggregatesRequestExceptions()
+ {
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\n" .
+ "Content-Type: text/html; charset=utf-8\r\n" .
+ "Content-Length: 4\r\n" .
+ "Server: Jetty(6.1.3)\r\n" .
+ "\r\n" .
+ "data",
+ "HTTP/1.1 204 No content\r\n" .
+ "Content-Length: 0\r\n" .
+ "Server: Jetty(6.1.3)\r\n" .
+ "\r\n",
+ "HTTP/1.1 404 Not Found\r\n" .
+ "Content-Length: 0\r\n" .
+ "\r\n"
+ ));
+
+ $request1 = new Request('GET', $this->getServer()->getUrl());
+ $request2 = new Request('HEAD', $this->getServer()->getUrl());
+ $request3 = new Request('GET', $this->getServer()->getUrl());
+ $this->multi->add($request1);
+ $this->multi->add($request2);
+ $this->multi->add($request3);
+
+ try {
+ $this->multi->send();
+ $this->fail('MultiTransferException not thrown when aggregating request exceptions');
+ } catch (MultiTransferException $e) {
+
+ $this->assertTrue($e->containsRequest($request1));
+ $this->assertTrue($e->containsRequest($request2));
+ $this->assertTrue($e->containsRequest($request3));
+ $this->assertInstanceOf('ArrayIterator', $e->getIterator());
+ $this->assertEquals(1, count($e));
+ $exceptions = $e->getIterator();
+
+ $response1 = $request1->getResponse();
+ $response2 = $request2->getResponse();
+ $response3 = $request3->getResponse();
+
+ $this->assertNotEquals((string) $response1, (string) $response2);
+ $this->assertNotEquals((string) $response3, (string) $response1);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $response1);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $response2);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $response3);
+
+ $failed = $exceptions[0]->getResponse();
+ $this->assertEquals(404, $failed->getStatusCode());
+ $this->assertEquals(1, count($e));
+
+ // Test the IteratorAggregate functionality
+ foreach ($e as $except) {
+ $this->assertEquals($failed, $except->getResponse());
+ }
+
+ $this->assertEquals(1, count($e->getFailedRequests()));
+ $this->assertEquals(2, count($e->getSuccessfulRequests()));
+ $this->assertEquals(3, count($e->getAllRequests()));
+ }
+ }
+
+ public function testCurlErrorsAreCaught()
+ {
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ try {
+ $request = RequestFactory::getInstance()->create('GET', 'http://127.0.0.1:9876/');
+ $request->setClient(new Client());
+ $request->getCurlOptions()->set(CURLOPT_FRESH_CONNECT, true);
+ $request->getCurlOptions()->set(CURLOPT_FORBID_REUSE, true);
+ $request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT_MS, 5);
+ $request->send();
+ $this->fail('CurlException not thrown');
+ } catch (CurlException $e) {
+ $m = $e->getMessage();
+ $this->assertContains('[curl] ', $m);
+ $this->assertContains('[url] http://127.0.0.1:9876/', $m);
+ $this->assertInternalType('array', $e->getCurlInfo());
+ }
+ }
+
+ public function testRemovesQueuedRequests()
+ {
+ $request = RequestFactory::getInstance()->create('GET', 'http://127.0.0.1:9876/');
+ $r = new Response(200);
+ $request->setClient(new Client());
+ $request->setResponse($r, true);
+ $this->multi->add($request);
+ $this->multi->send();
+ $this->assertSame($r, $request->getResponse());
+ }
+
+ public function testRemovesQueuedRequestsAddedInTransit()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
+ $client = new Client($this->getServer()->getUrl());
+ $r = $client->get();
+ $r->getEventDispatcher()->addListener('request.receive.status_line', function (Event $event) use ($client) {
+ // Create a request using a queued response
+ $request = $client->get()->setResponse(new Response(200), true);
+ $request->send();
+ });
+ $r->send();
+ $this->assertEquals(1, count($this->getServer()->getReceivedRequests(false)));
+ }
+
+ public function testCatchesExceptionsBeforeSendingSingleRequest()
+ {
+ $client = new Client($this->getServer()->getUrl());
+ $multi = new CurlMulti();
+ $client->setCurlMulti($multi);
+ $request = $client->get();
+ $request->getEventDispatcher()->addListener('request.before_send', function() {
+ throw new \RuntimeException('Testing!');
+ });
+ try {
+ $request->send();
+ $this->fail('Did not throw');
+ } catch (\RuntimeException $e) {
+ // Ensure it was removed
+ $this->assertEquals(0, count($multi));
+ }
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\ExceptionCollection
+ * @expectedExceptionMessage Thrown before sending!
+ */
+ public function testCatchesExceptionsBeforeSendingMultipleRequests()
+ {
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get();
+ $request->getEventDispatcher()->addListener('request.before_send', function() {
+ throw new \RuntimeException('Thrown before sending!');
+ });
+ $client->send(array($request));
+ }
+
+ public function testCatchesExceptionsWhenRemovingQueuedRequests()
+ {
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $client = new Client($this->getServer()->getUrl());
+ $r = $client->get();
+ $r->getEventDispatcher()->addListener('request.sent', function() use ($client) {
+ // Create a request using a queued response
+ $client->get()->setResponse(new Response(404), true)->send();
+ });
+ try {
+ $r->send();
+ $this->fail('Did not throw');
+ } catch (BadResponseException $e) {
+ $this->assertCount(0, $client->getCurlMulti());
+ }
+ }
+
+ public function testCatchesExceptionsWhenRemovingQueuedRequestsBeforeSending()
+ {
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $client = new Client($this->getServer()->getUrl());
+ $r = $client->get();
+ $r->getEventDispatcher()->addListener('request.before_send', function() use ($client) {
+ // Create a request using a queued response
+ $client->get()->setResponse(new Response(404), true)->send();
+ });
+ try {
+ $r->send();
+ $this->fail('Did not throw');
+ } catch (BadResponseException $e) {
+ $this->assertCount(0, $client->getCurlMulti());
+ }
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ * @expectedExceptionMessage test
+ */
+ public function testDoesNotCatchRandomExceptionsThrownDuringPerform()
+ {
+ $client = new Client($this->getServer()->getUrl());
+ $multi = $this->getMock('Guzzle\\Http\\Curl\\CurlMulti', array('perform'));
+ $multi->expects($this->once())
+ ->method('perform')
+ ->will($this->throwException(new \RuntimeException('test')));
+ $multi->add($client->get());
+ $multi->send();
+ }
+
+ public function testDoesNotSendRequestsDecliningToBeSent()
+ {
+ if (!defined('CURLOPT_TIMEOUT_MS')) {
+ $this->markTestSkipped('Update curl');
+ }
+
+ // Create a client that is bound to fail connecting
+ $client = new Client('http://127.0.0.1:123', array(
+ 'curl.CURLOPT_PORT' => 123,
+ 'curl.CURLOPT_CONNECTTIMEOUT_MS' => 1,
+ ));
+
+ $request = $client->get();
+ $multi = new CurlMulti();
+ $multi->add($request);
+
+ // Listen for request exceptions, and when they occur, first change the
+ // state of the request back to transferring, and then just allow it to
+ // exception out
+ $request->getEventDispatcher()->addListener('request.exception', function(Event $event) use ($multi) {
+ $retries = $event['request']->getParams()->get('retries');
+ // Allow the first failure to retry
+ if ($retries == 0) {
+ $event['request']->setState('transfer');
+ $event['request']->getParams()->set('retries', 1);
+ // Remove the request to try again
+ $multi->remove($event['request']);
+ $multi->add($event['request']);
+ }
+ });
+
+ try {
+ $multi->send();
+ $this->fail('Did not throw an exception at all!?!');
+ } catch (\Exception $e) {
+ $this->assertEquals(1, $request->getParams()->get('retries'));
+ }
+ }
+
+ public function testDoesNotThrowExceptionsWhenRequestsRecoverWithRetry()
+ {
+ $this->getServer()->flush();
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get();
+ $request->getEventDispatcher()->addListener('request.before_send', function(Event $event) {
+ $event['request']->setResponse(new Response(200));
+ });
+
+ $multi = new CurlMulti();
+ $multi->add($request);
+ $multi->send();
+ $this->assertEquals(0, count($this->getServer()->getReceivedRequests(false)));
+ }
+
+ public function testDoesNotThrowExceptionsWhenRequestsRecoverWithSuccess()
+ {
+ // Attempt a port that 99.9% is not listening
+ $client = new Client('http://127.0.0.1:123');
+ $request = $client->get();
+ // Ensure it times out quickly if needed
+ $request->getCurlOptions()->set(CURLOPT_TIMEOUT_MS, 1)->set(CURLOPT_CONNECTTIMEOUT_MS, 1);
+
+ $request->getEventDispatcher()->addListener('request.exception', function(Event $event) use (&$count) {
+ $event['request']->setResponse(new Response(200));
+ });
+
+ $multi = new CurlMulti();
+ $multi->add($request);
+ $multi->send();
+
+ // Ensure that the exception was caught, and the response was set manually
+ $this->assertEquals(200, $request->getResponse()->getStatusCode());
+ }
+
+ public function testHardResetReopensMultiHandle()
+ {
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
+ ));
+
+ $stream = fopen('php://temp', 'w+');
+ $client = new Client($this->getServer()->getUrl());
+ $client->getConfig()->set('curl.CURLOPT_VERBOSE', true)->set('curl.CURLOPT_STDERR', $stream);
+
+ $request = $client->get();
+ $multi = new CurlMulti();
+ $multi->add($request);
+ $multi->send();
+ $multi->reset(true);
+ $multi->add($request);
+ $multi->send();
+
+ rewind($stream);
+ $this->assertNotContains('Re-using existing connection', stream_get_contents($stream));
+ }
+
+ public function testThrowsMeaningfulExceptionsForCurlMultiErrors()
+ {
+ $multi = new CurlMulti();
+
+ // Set the state of the multi object to sending to trigger the exception
+ $reflector = new \ReflectionMethod('Guzzle\Http\Curl\CurlMulti', 'checkCurlResult');
+ $reflector->setAccessible(true);
+
+ // Successful
+ $reflector->invoke($multi, 0);
+
+ // Known error
+ try {
+ $reflector->invoke($multi, CURLM_BAD_HANDLE);
+ $this->fail('Expected an exception here');
+ } catch (CurlException $e) {
+ $this->assertContains('The passed-in handle is not a valid CURLM handle.', $e->getMessage());
+ $this->assertContains('CURLM_BAD_HANDLE', $e->getMessage());
+ $this->assertContains(strval(CURLM_BAD_HANDLE), $e->getMessage());
+ }
+
+ // Unknown error
+ try {
+ $reflector->invoke($multi, 255);
+ $this->fail('Expected an exception here');
+ } catch (CurlException $e) {
+ $this->assertEquals('Unexpected cURL error: 255', $e->getMessage());
+ }
+ }
+
+ public function testRequestBeforeSendIncludesContentLengthHeaderIfEmptyBody()
+ {
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request = new Request('PUT', $this->getServer()->getUrl());
+ $that = $this;
+ $request->getEventDispatcher()->addListener('request.before_send', function ($event) use ($that) {
+ $that->assertEquals(0, $event['request']->getHeader('Content-Length'));
+ });
+ $this->multi->add($request);
+ $this->multi->send();
+ }
+
+ public function testRemovesConflictingTransferEncodingHeader()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put('/', null, fopen($this->getServer()->getUrl(), 'r'));
+ $request->setHeader('Content-Length', 4);
+ $request->send();
+ $received = $this->getServer()->getReceivedRequests(true);
+ $this->assertFalse($received[1]->hasHeader('Transfer-Encoding'));
+ $this->assertEquals(4, (string) $received[1]->getHeader('Content-Length'));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlVersionTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlVersionTest.php
new file mode 100644
index 0000000..c7b5ee6
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/CurlVersionTest.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Guzzle\Tests\Http\Curl;
+
+use Guzzle\Http\Curl\CurlVersion;
+
+/**
+ * @covers Guzzle\Http\Curl\CurlVersion
+ */
+class CurlVersionTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testCachesCurlInfo()
+ {
+ $info = curl_version();
+ $instance = CurlVersion::getInstance();
+
+ // Clear out the info cache
+ $refObject = new \ReflectionObject($instance);
+ $refProperty = $refObject->getProperty('version');
+ $refProperty->setAccessible(true);
+ $refProperty->setValue($instance, array());
+
+ $this->assertEquals($info, $instance->getAll());
+ $this->assertEquals($info, $instance->getAll());
+
+ $this->assertEquals($info['version'], $instance->get('version'));
+ $this->assertFalse($instance->get('foo'));
+ }
+
+ public function testIsSingleton()
+ {
+ $refObject = new \ReflectionClass('Guzzle\Http\Curl\CurlVersion');
+ $refProperty = $refObject->getProperty('instance');
+ $refProperty->setAccessible(true);
+ $refProperty->setValue(null, null);
+
+ $this->assertInstanceOf('Guzzle\Http\Curl\CurlVersion', CurlVersion::getInstance());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/RequestMediatorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/RequestMediatorTest.php
new file mode 100644
index 0000000..c69e0c9
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Curl/RequestMediatorTest.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Guzzle\Tests\Http\Curl;
+
+use Guzzle\Http\Client;
+use Guzzle\Http\Message\EntityEnclosingRequest;
+use Guzzle\Http\Message\Response;
+use Guzzle\Http\Curl\RequestMediator;
+
+/**
+ * @covers Guzzle\Http\Curl\RequestMediator
+ */
+class RequestMediatorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public $events = array();
+
+ public function event($event)
+ {
+ $this->events[] = $event;
+ }
+
+ public function testEmitsEvents()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://www.example.com');
+ $request->setBody('foo');
+ $request->setResponse(new Response(200));
+
+ // Ensure that IO events are emitted
+ $request->getCurlOptions()->set('emit_io', true);
+
+ // Attach listeners for each event type
+ $request->getEventDispatcher()->addListener('curl.callback.progress', array($this, 'event'));
+ $request->getEventDispatcher()->addListener('curl.callback.read', array($this, 'event'));
+ $request->getEventDispatcher()->addListener('curl.callback.write', array($this, 'event'));
+
+ $mediator = new RequestMediator($request, true);
+
+ $mediator->progress('a', 'b', 'c', 'd');
+ $this->assertEquals(1, count($this->events));
+ $this->assertEquals('curl.callback.progress', $this->events[0]->getName());
+
+ $this->assertEquals(3, $mediator->writeResponseBody('foo', 'bar'));
+ $this->assertEquals(2, count($this->events));
+ $this->assertEquals('curl.callback.write', $this->events[1]->getName());
+ $this->assertEquals('bar', $this->events[1]['write']);
+ $this->assertSame($request, $this->events[1]['request']);
+
+ $this->assertEquals('foo', $mediator->readRequestBody('a', 'b', 3));
+ $this->assertEquals(3, count($this->events));
+ $this->assertEquals('curl.callback.read', $this->events[2]->getName());
+ $this->assertEquals('foo', $this->events[2]['read']);
+ $this->assertSame($request, $this->events[2]['request']);
+ }
+
+ public function testDoesNotUseRequestResponseBodyWhenNotCustom()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 307 Foo\r\nLocation: /foo\r\nContent-Length: 2\r\n\r\nHI",
+ "HTTP/1.1 301 Foo\r\nLocation: /foo\r\nContent-Length: 2\r\n\r\nFI",
+ "HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest",
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $response = $client->get()->send();
+ $this->assertEquals('test', $response->getBody(true));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/EntityBodyTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/EntityBodyTest.php
new file mode 100644
index 0000000..124a44d
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/EntityBodyTest.php
@@ -0,0 +1,182 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\QueryString;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\EntityBody
+ */
+class EntityBodyTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /**
+ * @expectedException \Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testFactoryThrowsException()
+ {
+ $body = EntityBody::factory(false);
+ }
+
+ public function testFactory()
+ {
+ $body = EntityBody::factory('data');
+ $this->assertEquals('data', (string) $body);
+ $this->assertEquals(4, $body->getContentLength());
+ $this->assertEquals('PHP', $body->getWrapper());
+ $this->assertEquals('TEMP', $body->getStreamType());
+
+ $handle = fopen(__DIR__ . '/../../../../phpunit.xml.dist', 'r');
+ if (!$handle) {
+ $this->fail('Could not open test file');
+ }
+ $body = EntityBody::factory($handle);
+ $this->assertEquals(__DIR__ . '/../../../../phpunit.xml.dist', $body->getUri());
+ $this->assertTrue($body->isLocal());
+ $this->assertEquals(__DIR__ . '/../../../../phpunit.xml.dist', $body->getUri());
+ $this->assertEquals(filesize(__DIR__ . '/../../../../phpunit.xml.dist'), $body->getContentLength());
+
+ // make sure that a body will return as the same object
+ $this->assertTrue($body === EntityBody::factory($body));
+ }
+
+ public function testFactoryCreatesTempStreamByDefault()
+ {
+ $body = EntityBody::factory('');
+ $this->assertEquals('PHP', $body->getWrapper());
+ $this->assertEquals('TEMP', $body->getStreamType());
+ $body = EntityBody::factory();
+ $this->assertEquals('PHP', $body->getWrapper());
+ $this->assertEquals('TEMP', $body->getStreamType());
+ }
+
+ public function testFactoryCanCreateFromObject()
+ {
+ $body = EntityBody::factory(new QueryString(array('foo' => 'bar')));
+ $this->assertEquals('foo=bar', (string) $body);
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testFactoryEnsuresObjectsHaveToStringMethod()
+ {
+ EntityBody::factory(new \stdClass('a'));
+ }
+
+ public function testHandlesCompression()
+ {
+ $body = EntityBody::factory('testing 123...testing 123');
+ $this->assertFalse($body->getContentEncoding(), '-> getContentEncoding() must initially return FALSE');
+ $size = $body->getContentLength();
+ $body->compress();
+ $this->assertEquals('gzip', $body->getContentEncoding(), '-> getContentEncoding() must return the correct encoding after compressing');
+ $this->assertEquals(gzdeflate('testing 123...testing 123'), (string) $body);
+ $this->assertTrue($body->getContentLength() < $size);
+ $this->assertTrue($body->uncompress());
+ $this->assertEquals('testing 123...testing 123', (string) $body);
+ $this->assertFalse($body->getContentEncoding(), '-> getContentEncoding() must reset to FALSE');
+
+ if (in_array('bzip2.*', stream_get_filters())) {
+ $this->assertTrue($body->compress('bzip2.compress'));
+ $this->assertEquals('compress', $body->getContentEncoding(), '-> compress() must set \'compress\' as the Content-Encoding');
+ }
+
+ $this->assertFalse($body->compress('non-existent'), '-> compress() must return false when a non-existent stream filter is used');
+
+ // Release the body
+ unset($body);
+
+ // Use gzip compression on the initial content. This will include a
+ // gzip header which will need to be stripped when deflating the stream
+ $body = EntityBody::factory(gzencode('test'));
+ $this->assertSame($body, $body->setStreamFilterContentEncoding('zlib.deflate'));
+ $this->assertTrue($body->uncompress('zlib.inflate'));
+ $this->assertEquals('test', (string) $body);
+ unset($body);
+
+ // Test using a very long string
+ $largeString = '';
+ for ($i = 0; $i < 25000; $i++) {
+ $largeString .= chr(rand(33, 126));
+ }
+ $body = EntityBody::factory($largeString);
+ $this->assertEquals($largeString, (string) $body);
+ $this->assertTrue($body->compress());
+ $this->assertNotEquals($largeString, (string) $body);
+ $compressed = (string) $body;
+ $this->assertTrue($body->uncompress());
+ $this->assertEquals($largeString, (string) $body);
+ $this->assertEquals($compressed, gzdeflate($largeString));
+
+ $body = EntityBody::factory(fopen(__DIR__ . '/../TestData/compress_test', 'w'));
+ $this->assertFalse($body->compress());
+ unset($body);
+
+ unlink(__DIR__ . '/../TestData/compress_test');
+ }
+
+ public function testDeterminesContentType()
+ {
+ // Test using a string/temp stream
+ $body = EntityBody::factory('testing 123...testing 123');
+ $this->assertNull($body->getContentType());
+
+ // Use a local file
+ $body = EntityBody::factory(fopen(__FILE__, 'r'));
+ $this->assertContains('text/x-', $body->getContentType());
+ }
+
+ public function testCreatesMd5Checksum()
+ {
+ $body = EntityBody::factory('testing 123...testing 123');
+ $this->assertEquals(md5('testing 123...testing 123'), $body->getContentMd5());
+
+ $server = $this->getServer()->enqueue(
+ "HTTP/1.1 200 OK" . "\r\n" .
+ "Content-Length: 3" . "\r\n\r\n" .
+ "abc"
+ );
+
+ $body = EntityBody::factory(fopen($this->getServer()->getUrl(), 'r'));
+ $this->assertFalse($body->getContentMd5());
+ }
+
+ public function testSeeksToOriginalPosAfterMd5()
+ {
+ $body = EntityBody::factory('testing 123');
+ $body->seek(4);
+ $this->assertEquals(md5('testing 123'), $body->getContentMd5());
+ $this->assertEquals(4, $body->ftell());
+ $this->assertEquals('ing 123', $body->read(1000));
+ }
+
+ public function testGetTypeFormBodyFactoring()
+ {
+ $body = EntityBody::factory(array('key1' => 'val1', 'key2' => 'val2'));
+ $this->assertEquals('key1=val1&key2=val2', (string) $body);
+ }
+
+ public function testAllowsCustomRewind()
+ {
+ $body = EntityBody::factory('foo');
+ $rewound = false;
+ $body->setRewindFunction(function ($body) use (&$rewound) {
+ $rewound = true;
+ return $body->seek(0);
+ });
+ $body->seek(2);
+ $this->assertTrue($body->rewind());
+ $this->assertTrue($rewound);
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testCustomRewindFunctionMustBeCallable()
+ {
+ $body = EntityBody::factory();
+ $body->setRewindFunction('foo');
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/CurlExceptionTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/CurlExceptionTest.php
new file mode 100644
index 0000000..df3e4b7
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/CurlExceptionTest.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Guzzle\Tests\Http\Exception;
+
+use Guzzle\Http\Exception\CurlException;
+use Guzzle\Http\Curl\CurlHandle;
+
+/**
+ * @covers Guzzle\Http\Exception\CurlException
+ */
+class CurlExceptionTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testStoresCurlError()
+ {
+ $e = new CurlException();
+ $this->assertNull($e->getError());
+ $this->assertNull($e->getErrorNo());
+ $this->assertSame($e, $e->setError('test', 12));
+ $this->assertEquals('test', $e->getError());
+ $this->assertEquals(12, $e->getErrorNo());
+
+ $handle = new CurlHandle(curl_init(), array());
+ $e->setCurlHandle($handle);
+ $this->assertSame($handle, $e->getCurlHandle());
+ $handle->close();
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/ExceptionTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/ExceptionTest.php
new file mode 100644
index 0000000..12cfd36
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/ExceptionTest.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Guzzle\Tests\Http\Exception;
+
+use Guzzle\Http\Message\Response;
+use Guzzle\Http\Message\Request;
+use Guzzle\Http\Exception\RequestException;
+use Guzzle\Http\Exception\BadResponseException;
+
+class ExceptionTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /**
+ * @covers Guzzle\Http\Exception\RequestException
+ */
+ public function testRequestException()
+ {
+ $e = new RequestException('Message');
+ $request = new Request('GET', 'http://www.guzzle-project.com/');
+ $e->setRequest($request);
+ $this->assertEquals($request, $e->getRequest());
+ }
+
+ /**
+ * @covers Guzzle\Http\Exception\BadResponseException
+ */
+ public function testBadResponseException()
+ {
+ $e = new BadResponseException('Message');
+ $response = new Response(200);
+ $e->setResponse($response);
+ $this->assertEquals($response, $e->getResponse());
+ }
+
+ /**
+ * @covers Guzzle\Http\Exception\BadResponseException::factory
+ */
+ public function testCreatesGenericErrorExceptionOnError()
+ {
+ $request = new Request('GET', 'http://www.example.com');
+ $response = new Response(307);
+ $e = BadResponseException::factory($request, $response);
+ $this->assertInstanceOf('Guzzle\Http\Exception\BadResponseException', $e);
+ }
+
+ /**
+ * @covers Guzzle\Http\Exception\BadResponseException::factory
+ */
+ public function testCreatesClientErrorExceptionOnClientError()
+ {
+ $request = new Request('GET', 'http://www.example.com');
+ $response = new Response(404);
+ $e = BadResponseException::factory($request, $response);
+ $this->assertInstanceOf('Guzzle\Http\Exception\ClientErrorResponseException', $e);
+ }
+
+ /**
+ * @covers Guzzle\Http\Exception\BadResponseException::factory
+ */
+ public function testCreatesServerErrorExceptionOnServerError()
+ {
+ $request = new Request('GET', 'http://www.example.com');
+ $response = new Response(503);
+ $e = BadResponseException::factory($request, $response);
+ $this->assertInstanceOf('Guzzle\Http\Exception\ServerErrorResponseException', $e);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/MultiTransferExceptionTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/MultiTransferExceptionTest.php
new file mode 100644
index 0000000..fa4ec26
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Exception/MultiTransferExceptionTest.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Guzzle\Tests\Http\Exception;
+
+use Guzzle\Http\Exception\MultiTransferException;
+use Guzzle\Http\Curl\CurlHandle;
+use Guzzle\Http\Message\Request;
+
+/**
+ * @covers Guzzle\Http\Exception\MultiTransferException
+ */
+class MultiTransferExceptionTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testHasRequests()
+ {
+ $r1 = new Request('GET', 'http://www.foo.com');
+ $r2 = new Request('GET', 'http://www.foo.com');
+ $e = new MultiTransferException();
+ $e->addSuccessfulRequest($r1);
+ $e->addFailedRequest($r2);
+ $this->assertEquals(array($r1), $e->getSuccessfulRequests());
+ $this->assertEquals(array($r2), $e->getSuccessfulRequests());
+ $this->assertEquals(array($r1, $r2), $e->getAllRequests());
+ $this->assertTrue($e->containsRequest($r1));
+ $this->assertTrue($e->containsRequest($r2));
+ $this->assertFalse($e->containsRequest(new Request('POST', '/foo')));
+ }
+
+ public function testCanSetRequests()
+ {
+ $s = array($r1 = new Request('GET', 'http://www.foo.com'));
+ $f = array($r2 = new Request('GET', 'http://www.foo.com'));
+ $e = new MultiTransferException();
+ $e->setSuccessfulRequests($s);
+ $e->setFailedRequests($f);
+ $this->assertEquals(array($r1), $e->getSuccessfulRequests());
+ $this->assertEquals(array($r2), $e->getSuccessfulRequests());
+ }
+
+ public function testAssociatesExceptionsWithRequests()
+ {
+ $r1 = new Request('GET', 'http://www.foo.com');
+ $re1 = new \Exception('foo');
+ $re2 = new \Exception('bar');
+ $e = new MultiTransferException();
+ $e->add($re2);
+ $e->addFailedRequestWithException($r1, $re1);
+ $this->assertSame($re1, $e->getExceptionForFailedRequest($r1));
+ $this->assertNull($e->getExceptionForFailedRequest(new Request('POST', '/foo')));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/IoEmittingEntityBodyTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/IoEmittingEntityBodyTest.php
new file mode 100644
index 0000000..cd6355f
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/IoEmittingEntityBodyTest.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\IoEmittingEntityBody;
+
+/**
+ * @covers Guzzle\Http\IoEmittingEntityBody
+ */
+class IoEmittingEntityBodyTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ protected $body;
+ protected $decorated;
+
+ public function setUp()
+ {
+ $this->decorated = EntityBody::factory('hello');
+ $this->body = new IoEmittingEntityBody($this->decorated);
+ }
+
+ public function testEmitsReadEvents()
+ {
+ $e = null;
+ $this->body->getEventDispatcher()->addListener('body.read', function ($event) use (&$e) {
+ $e = $event;
+ });
+ $this->assertEquals('hel', $this->body->read(3));
+ $this->assertEquals('hel', $e['read']);
+ $this->assertEquals(3, $e['length']);
+ $this->assertSame($this->body, $e['body']);
+ }
+
+ public function testEmitsWriteEvents()
+ {
+ $e = null;
+ $this->body->getEventDispatcher()->addListener('body.write', function ($event) use (&$e) {
+ $e = $event;
+ });
+ $this->body->seek(0, SEEK_END);
+ $this->assertEquals(5, $this->body->write('there'));
+ $this->assertEquals('there', $e['write']);
+ $this->assertEquals(5, $e['result']);
+ $this->assertSame($this->body, $e['body']);
+ $this->assertEquals('hellothere', (string) $this->body);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/AbstractMessageTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/AbstractMessageTest.php
new file mode 100644
index 0000000..9447d8c
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/AbstractMessageTest.php
@@ -0,0 +1,136 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message;
+
+use Guzzle\Http\Message\Header;
+use Guzzle\Http\Message\Request;
+use Guzzle\Common\Collection;
+
+/**
+ * @covers Guzzle\Http\Message\AbstractMessage
+ */
+class AbstractMessageTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /** @var Request Request object */
+ private $request;
+
+ /** @var AbstractMessage */
+ private $mock;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->mock = $this->getMockForAbstractClass('Guzzle\Http\Message\AbstractMessage');
+ }
+
+ public function tearDown()
+ {
+ $this->mock = $this->request = null;
+ }
+
+ public function testGetParams()
+ {
+ $request = new Request('GET', 'http://example.com');
+ $this->assertInstanceOf('Guzzle\\Common\\Collection', $request->getParams());
+ }
+
+ public function testAddHeaders()
+ {
+ $this->mock->setHeader('A', 'B');
+
+ $this->assertEquals($this->mock, $this->mock->addHeaders(array(
+ 'X-Data' => '123'
+ )));
+
+ $this->assertTrue($this->mock->hasHeader('X-Data') !== false);
+ $this->assertTrue($this->mock->hasHeader('A') !== false);
+ }
+
+ public function testAllowsHeaderToSetAsHeader()
+ {
+ $h = new Header('A', 'B');
+ $this->mock->setHeader('A', $h);
+ $this->assertSame($h, $this->mock->getHeader('A'));
+ }
+
+ public function testGetHeader()
+ {
+ $this->mock->setHeader('Test', '123');
+ $this->assertEquals('123', $this->mock->getHeader('Test'));
+ }
+
+ public function testGetHeaders()
+ {
+ $this->assertSame($this->mock, $this->mock->setHeaders(array('a' => 'b', 'c' => 'd')));
+ $h = $this->mock->getHeaders();
+ $this->assertArrayHasKey('a', $h->toArray());
+ $this->assertArrayHasKey('c', $h->toArray());
+ $this->assertInstanceOf('Guzzle\Http\Message\Header\HeaderInterface', $h->get('a'));
+ $this->assertInstanceOf('Guzzle\Http\Message\Header\HeaderInterface', $h->get('c'));
+ }
+
+ public function testGetHeaderLinesUsesGlue()
+ {
+ $this->mock->setHeaders(array('a' => 'b', 'c' => 'd'));
+ $this->mock->addHeader('a', 'e');
+ $this->mock->getHeader('a')->setGlue('!');
+ $this->assertEquals(array(
+ 'a: b! e',
+ 'c: d'
+ ), $this->mock->getHeaderLines());
+ }
+
+ public function testHasHeader()
+ {
+ $this->assertFalse($this->mock->hasHeader('Foo'));
+ $this->mock->setHeader('Foo', 'Bar');
+ $this->assertEquals(true, $this->mock->hasHeader('Foo'));
+ $this->mock->setHeader('foo', 'yoo');
+ $this->assertEquals(true, $this->mock->hasHeader('Foo'));
+ $this->assertEquals(true, $this->mock->hasHeader('foo'));
+ $this->assertEquals(false, $this->mock->hasHeader('bar'));
+ }
+
+ public function testRemoveHeader()
+ {
+ $this->mock->setHeader('Foo', 'Bar');
+ $this->assertEquals(true, $this->mock->hasHeader('Foo'));
+ $this->mock->removeHeader('Foo');
+ $this->assertFalse($this->mock->hasHeader('Foo'));
+ }
+
+ public function testReturnsNullWhenHeaderIsNotFound()
+ {
+ $this->assertNull($this->mock->getHeader('foo'));
+ }
+
+ public function testAddingHeadersPreservesOriginalHeaderCase()
+ {
+ $this->mock->addHeaders(array(
+ 'test' => '123',
+ 'Test' => 'abc'
+ ));
+ $this->mock->addHeader('test', '456');
+ $this->mock->addHeader('test', '789');
+
+ $header = $this->mock->getHeader('test');
+ $this->assertContains('123', $header->toArray());
+ $this->assertContains('456', $header->toArray());
+ $this->assertContains('789', $header->toArray());
+ $this->assertContains('abc', $header->toArray());
+ }
+
+ public function testCanStoreEmptyHeaders()
+ {
+ $this->mock->setHeader('Content-Length', 0);
+ $this->assertTrue($this->mock->hasHeader('Content-Length'));
+ $this->assertEquals(0, (string) $this->mock->getHeader('Content-Length'));
+ }
+
+ public function testCanSetCustomHeaderFactory()
+ {
+ $f = new Header\HeaderFactory();
+ $this->mock->setHeaderFactory($f);
+ $this->assertSame($f, $this->readAttribute($this->mock, 'headerFactory'));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/EntityEnclosingRequestTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/EntityEnclosingRequestTest.php
new file mode 100644
index 0000000..191b022
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/EntityEnclosingRequestTest.php
@@ -0,0 +1,434 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message;
+
+use Guzzle\Http\Client;
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\Message\Request;
+use Guzzle\Http\Message\RequestFactory;
+use Guzzle\Http\RedirectPlugin;
+use Guzzle\Http\Message\EntityEnclosingRequest;
+use Guzzle\Http\Message\PostFile;
+use Guzzle\Http\QueryString;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\Message\EntityEnclosingRequest
+ */
+class EntityEnclosingRequestTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ protected $client;
+
+ public function setUp()
+ {
+ $this->client = new Client();
+ }
+
+ public function tearDown()
+ {
+ $this->client = null;
+ }
+
+ public function testConstructorConfiguresRequest()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com', array(
+ 'X-Test' => '123'
+ ));
+ $request->setBody('Test');
+ $this->assertEquals('123', $request->getHeader('X-Test'));
+ $this->assertNull($request->getHeader('Expect'));
+ }
+
+ public function testCanSetBodyWithoutOverridingContentType()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com', array('Content-Type' => 'foooooo'));
+ $request->setBody('{"a":"b"}');
+ $this->assertEquals('foooooo', $request->getHeader('Content-Type'));
+ }
+
+ public function testRequestIncludesBodyInMessage()
+ {
+
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.guzzle-project.com/', null, 'data');
+ $this->assertEquals("PUT / HTTP/1.1\r\n"
+ . "Host: www.guzzle-project.com\r\n"
+ . "Content-Length: 4\r\n\r\n"
+ . "data", (string) $request);
+ }
+
+ public function testRequestIncludesPostBodyInMessageOnlyWhenNoPostFiles()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/', null, array(
+ 'foo' => 'bar'
+ ));
+ $this->assertEquals("POST / HTTP/1.1\r\n"
+ . "Host: www.guzzle-project.com\r\n"
+ . "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n\r\n"
+ . "foo=bar", (string) $request);
+
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/', null, array(
+ 'foo' => '@' . __FILE__
+ ));
+ $this->assertEquals("POST / HTTP/1.1\r\n"
+ . "Host: www.guzzle-project.com\r\n"
+ . "Content-Type: multipart/form-data\r\n"
+ . "Expect: 100-Continue\r\n\r\n", (string) $request);
+ }
+
+ public function testAddsPostFieldsAndSetsContentLength()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/', null, array(
+ 'data' => '123'
+ ));
+ $this->assertEquals("POST / HTTP/1.1\r\n"
+ . "Host: www.guzzle-project.com\r\n"
+ . "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n\r\n"
+ . "data=123", (string) $request);
+ }
+
+ public function testAddsPostFilesAndSetsContentType()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.test.com/')
+ ->addPostFiles(array(
+ 'file' => __FILE__
+ ))->addPostFields(array(
+ 'a' => 'b'
+ ));
+ $message = (string) $request;
+ $this->assertEquals('multipart/form-data', $request->getHeader('Content-Type'));
+ $this->assertEquals('100-Continue', $request->getHeader('Expect'));
+ }
+
+ public function testRequestBodyContainsPostFiles()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.test.com/');
+ $request->addPostFields(array(
+ 'test' => '123'
+ ));
+ $this->assertContains("\r\n\r\ntest=123", (string) $request);
+ }
+
+ public function testRequestBodyAddsContentLength()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.test.com/');
+ $request->setBody(EntityBody::factory('test'));
+ $this->assertEquals(4, (string) $request->getHeader('Content-Length'));
+ $this->assertFalse($request->hasHeader('Transfer-Encoding'));
+ }
+
+ public function testRequestBodyDoesNotUseContentLengthWhenChunked()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.test.com/', array(
+ 'Transfer-Encoding' => 'chunked'
+ ), 'test');
+ $this->assertNull($request->getHeader('Content-Length'));
+ $this->assertTrue($request->hasHeader('Transfer-Encoding'));
+ }
+
+ public function testRequestHasMutableBody()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.guzzle-project.com/', null, 'data');
+ $body = $request->getBody();
+ $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $body);
+ $this->assertSame($body, $request->getBody());
+
+ $newBody = EntityBody::factory('foobar');
+ $request->setBody($newBody);
+ $this->assertEquals('foobar', (string) $request->getBody());
+ $this->assertSame($newBody, $request->getBody());
+ }
+
+ public function testSetPostFields()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/');
+ $this->assertInstanceOf('Guzzle\\Http\\QueryString', $request->getPostFields());
+
+ $fields = new QueryString(array(
+ 'a' => 'b'
+ ));
+ $request->addPostFields($fields);
+ $this->assertEquals($fields->getAll(), $request->getPostFields()->getAll());
+ $this->assertEquals(array(), $request->getPostFiles());
+ }
+
+ public function testSetPostFiles()
+ {
+ $request = RequestFactory::getInstance()->create('POST', $this->getServer()->getUrl())
+ ->setClient(new Client())
+ ->addPostFiles(array(__FILE__))
+ ->addPostFields(array(
+ 'test' => 'abc'
+ ));
+
+ $request->getCurlOptions()->set('debug', true);
+
+ $this->assertEquals(array(
+ 'test' => 'abc'
+ ), $request->getPostFields()->getAll());
+
+ $files = $request->getPostFiles();
+ $post = $files['file'][0];
+ $this->assertEquals('file', $post->getFieldName());
+ $this->assertContains('text/x-', $post->getContentType());
+ $this->assertEquals(__FILE__, $post->getFilename());
+
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request->send();
+
+ $this->assertNotNull($request->getHeader('Content-Length'));
+ $this->assertContains('multipart/form-data; boundary=', (string) $request->getHeader('Content-Type'), '-> cURL must add the boundary');
+ }
+
+ /**
+ * @expectedException Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testSetPostFilesThrowsExceptionWhenFileIsNotFound()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/')
+ ->addPostFiles(array(
+ 'file' => 'filenotfound.ini'
+ ));
+ }
+
+ /**
+ * @expectedException Guzzle\Http\Exception\RequestException
+ */
+ public function testThrowsExceptionWhenNonStringsAreAddedToPost()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/')
+ ->addPostFile('foo', new \stdClass());
+ }
+
+ public function testAllowsContentTypeInPostUploads()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/')
+ ->addPostFile('foo', __FILE__, 'text/plain');
+
+ $this->assertEquals(array(
+ new PostFile('foo', __FILE__, 'text/plain')
+ ), $request->getPostFile('foo'));
+ }
+
+ public function testGuessesContentTypeOfPostUpload()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/')
+ ->addPostFile('foo', __FILE__);
+ $file = $request->getPostFile('foo');
+ $this->assertContains('text/x-', $file[0]->getContentType());
+ }
+
+ public function testAllowsContentDispositionFieldsInPostUploadsWhenSettingInBulk()
+ {
+ $postFile = new PostFile('foo', __FILE__, 'text/x-php');
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/')
+ ->addPostFiles(array('foo' => $postFile));
+
+ $this->assertEquals(array($postFile), $request->getPostFile('foo'));
+ }
+
+ public function testPostRequestsUseApplicationXwwwForUrlEncodedForArrays()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/');
+ $request->setPostField('a', 'b');
+ $this->assertContains("\r\n\r\na=b", (string) $request);
+ $this->assertEquals('application/x-www-form-urlencoded; charset=utf-8', $request->getHeader('Content-Type'));
+ }
+
+ public function testProcessMethodAddsContentType()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/');
+ $request->setPostField('a', 'b');
+ $this->assertEquals('application/x-www-form-urlencoded; charset=utf-8', $request->getHeader('Content-Type'));
+ }
+
+ public function testPostRequestsUseMultipartFormDataWithFiles()
+ {
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.guzzle-project.com/');
+ $request->addPostFiles(array('file' => __FILE__));
+ $this->assertEquals('multipart/form-data', $request->getHeader('Content-Type'));
+ }
+
+ public function testCanSendMultipleRequestsUsingASingleRequestObject()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 201 Created\r\nContent-Length: 0\r\n\r\n",
+ ));
+
+ // Send the first request
+ $request = RequestFactory::getInstance()->create('PUT', $this->getServer()->getUrl())
+ ->setBody('test')
+ ->setClient(new Client());
+ $request->send();
+ $this->assertEquals(200, $request->getResponse()->getStatusCode());
+
+ // Send the second request
+ $request->setBody('abcdefg', 'application/json', false);
+ $request->send();
+ $this->assertEquals(201, $request->getResponse()->getStatusCode());
+
+ // Ensure that the same request was sent twice with different bodies
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals(2, count($requests));
+ $this->assertEquals(4, (string) $requests[0]->getHeader('Content-Length'));
+ $this->assertEquals(7, (string) $requests[1]->getHeader('Content-Length'));
+ }
+
+ public function testRemovingPostFieldRebuildsPostFields()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://test.com');
+ $request->setPostField('test', 'value');
+ $request->removePostField('test');
+ $this->assertNull($request->getPostField('test'));
+ }
+
+ public function testUsesChunkedTransferWhenBodyLengthCannotBeDetermined()
+ {
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com/');
+ $request->setBody(fopen($this->getServer()->getUrl(), 'r'));
+ $this->assertEquals('chunked', $request->getHeader('Transfer-Encoding'));
+ $this->assertFalse($request->hasHeader('Content-Length'));
+ }
+
+ /**
+ * @expectedException \Guzzle\Http\Exception\RequestException
+ */
+ public function testThrowsExceptionWhenContentLengthCannotBeDeterminedAndUsingHttp1()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com/');
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request->setProtocolVersion('1.0');
+ $request->setBody(fopen($this->getServer()->getUrl(), 'r'));
+ }
+
+ public function testAllowsNestedPostData()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://test.com/');
+ $request->addPostFields(array(
+ 'a' => array('b', 'c')
+ ));
+ $this->assertEquals(array(
+ 'a' => array('b', 'c')
+ ), $request->getPostFields()->getAll());
+ }
+
+ public function testAllowsEmptyFields()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://test.com/');
+ $request->addPostFields(array(
+ 'a' => ''
+ ));
+ $this->assertEquals(array(
+ 'a' => ''
+ ), $request->getPostFields()->getAll());
+ }
+
+ /**
+ * @expectedException \Guzzle\Http\Exception\RequestException
+ */
+ public function testFailsOnInvalidFiles()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://test.com/');
+ $request->addPostFiles(array(
+ 'a' => new \stdClass()
+ ));
+ }
+
+ public function testHandlesEmptyStrings()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://test.com/');
+ $request->addPostFields(array(
+ 'a' => '',
+ 'b' => null,
+ 'c' => 'Foo'
+ ));
+ $this->assertEquals(array(
+ 'a' => '',
+ 'b' => null,
+ 'c' => 'Foo'
+ ), $request->getPostFields()->getAll());
+ }
+
+ public function testHoldsPostFiles()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://test.com/');
+ $request->addPostFile('foo', __FILE__);
+ $request->addPostFile(new PostFile('foo', __FILE__));
+
+ $this->assertArrayHasKey('foo', $request->getPostFiles());
+ $foo = $request->getPostFile('foo');
+ $this->assertEquals(2, count($foo));
+ $this->assertEquals(__FILE__, $foo[0]->getFilename());
+ $this->assertEquals(__FILE__, $foo[1]->getFilename());
+
+ $request->removePostFile('foo');
+ $this->assertEquals(array(), $request->getPostFiles());
+ }
+
+ public function testAllowsAtPrefixWhenAddingPostFiles()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://test.com/');
+ $request->addPostFiles(array(
+ 'foo' => '@' . __FILE__
+ ));
+ $foo = $request->getPostFile('foo');
+ $this->assertEquals(__FILE__, $foo[0]->getFilename());
+ }
+
+ public function testSetStateToTransferWithEmptyBodySetsContentLengthToZero()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://test.com/');
+ $request->setState($request::STATE_TRANSFER);
+ $this->assertEquals('0', (string) $request->getHeader('Content-Length'));
+ }
+
+ public function testSettingExpectHeaderCutoffChangesRequest()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com/');
+ $request->setHeader('Expect', '100-Continue');
+ $request->setExpectHeaderCutoff(false);
+ $this->assertNull($request->getHeader('Expect'));
+ // There is not body, so remove the expect header
+ $request->setHeader('Expect', '100-Continue');
+ $request->setExpectHeaderCutoff(10);
+ $this->assertNull($request->getHeader('Expect'));
+ // The size is less than the cutoff
+ $request->setBody('foo');
+ $this->assertNull($request->getHeader('Expect'));
+ // The size is greater than the cutoff
+ $request->setBody('foobazbarbamboo');
+ $this->assertNotNull($request->getHeader('Expect'));
+ }
+
+ public function testStrictRedirectsCanBeSpecifiedOnEntityEnclosingRequests()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com/');
+ $request->configureRedirects(true);
+ $this->assertTrue($request->getParams()->get(RedirectPlugin::STRICT_REDIRECTS));
+ }
+
+ public function testCanDisableRedirects()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com/');
+ $request->configureRedirects(false, false);
+ $this->assertTrue($request->getParams()->get(RedirectPlugin::DISABLE));
+ }
+
+ public function testSetsContentTypeWhenSettingBodyByGuessingFromEntityBody()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com/foo');
+ $request->setBody(EntityBody::factory(fopen(__FILE__, 'r')));
+ $this->assertEquals('text/x-php', (string) $request->getHeader('Content-Type'));
+ }
+
+ public function testDoesNotCloneBody()
+ {
+ $request = new EntityEnclosingRequest('PUT', 'http://test.com/foo');
+ $request->setBody('test');
+ $newRequest = clone $request;
+ $newRequest->setBody('foo');
+ $this->assertInternalType('string', (string) $request->getBody());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/Header/HeaderFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/Header/HeaderFactoryTest.php
new file mode 100644
index 0000000..62ca555
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/Header/HeaderFactoryTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message\Header;
+
+use Guzzle\Http\Message\Header\HeaderFactory;
+
+/**
+ * @covers Guzzle\Http\Message\Header\HeaderFactory
+ */
+class HeaderFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testCreatesBasicHeaders()
+ {
+ $f = new HeaderFactory();
+ $h = $f->createHeader('Foo', 'Bar');
+ $this->assertInstanceOf('Guzzle\Http\Message\Header', $h);
+ $this->assertEquals('Foo', $h->getName());
+ $this->assertEquals('Bar', (string) $h);
+ }
+
+ public function testCreatesSpecificHeaders()
+ {
+ $f = new HeaderFactory();
+ $h = $f->createHeader('Link', '<http>; rel="test"');
+ $this->assertInstanceOf('Guzzle\Http\Message\Header\Link', $h);
+ $this->assertEquals('Link', $h->getName());
+ $this->assertEquals('<http>; rel="test"', (string) $h);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/Header/LinkTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/Header/LinkTest.php
new file mode 100644
index 0000000..c834d10
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/Header/LinkTest.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message\Header;
+
+use Guzzle\Http\Message\Header\Link;
+use Guzzle\Tests\GuzzleTestCase;
+
+class LinkTest extends GuzzleTestCase
+{
+ public function testParsesLinks()
+ {
+ $link = new Link('Link', '<http:/.../front.jpeg>; rel=front; type="image/jpeg", <http://.../back.jpeg>; rel=back; type="image/jpeg", <http://.../side.jpeg?test=1>; rel=side; type="image/jpeg"');
+ $links = $link->getLinks();
+ $this->assertEquals(array(
+ array(
+ 'rel' => 'front',
+ 'type' => 'image/jpeg',
+ 'url' => 'http:/.../front.jpeg',
+ ),
+ array(
+ 'rel' => 'back',
+ 'type' => 'image/jpeg',
+ 'url' => 'http://.../back.jpeg',
+ ),
+ array(
+ 'rel' => 'side',
+ 'type' => 'image/jpeg',
+ 'url' => 'http://.../side.jpeg?test=1'
+ )
+ ), $links);
+
+ $this->assertEquals(array(
+ 'rel' => 'back',
+ 'type' => 'image/jpeg',
+ 'url' => 'http://.../back.jpeg',
+ ), $link->getLink('back'));
+
+ $this->assertTrue($link->hasLink('front'));
+ $this->assertFalse($link->hasLink('foo'));
+ }
+
+ public function testCanAddLink()
+ {
+ $link = new Link('Link', '<http://foo>; rel=a; type="image/jpeg"');
+ $link->addLink('http://test.com', 'test', array('foo' => 'bar'));
+ $this->assertEquals(
+ '<http://foo>; rel=a; type="image/jpeg", <http://test.com>; rel="test"; foo="bar"',
+ (string) $link
+ );
+ }
+
+ public function testCanParseLinksWithCommas()
+ {
+ $link = new Link('Link', '<http://example.com/TheBook/chapter1>; rel="previous"; title="start, index"');
+ $this->assertEquals(array(
+ array(
+ 'rel' => 'previous',
+ 'title' => 'start, index',
+ 'url' => 'http://example.com/TheBook/chapter1',
+ )
+ ), $link->getLinks());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderComparison.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderComparison.php
new file mode 100644
index 0000000..a3f511b
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderComparison.php
@@ -0,0 +1,135 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message;
+
+use Guzzle\Common\Collection;
+use Guzzle\Http\Message\Header\HeaderCollection;
+
+/**
+ * Class used to compare HTTP headers using a custom DSL
+ */
+class HeaderComparison
+{
+ /**
+ * Compare HTTP headers and use special markup to filter values
+ * A header prefixed with '!' means it must not exist
+ * A header prefixed with '_' means it must be ignored
+ * A header value of '*' means anything after the * will be ignored
+ *
+ * @param array $filteredHeaders Array of special headers
+ * @param array $actualHeaders Array of headers to check against
+ *
+ * @return array|bool Returns an array of the differences or FALSE if none
+ */
+ public function compare($filteredHeaders, $actualHeaders)
+ {
+ $expected = array();
+ $ignore = array();
+ $absent = array();
+
+ if ($actualHeaders instanceof HeaderCollection) {
+ $actualHeaders = $actualHeaders->toArray();
+ }
+
+ foreach ($filteredHeaders as $k => $v) {
+ if ($k[0] == '_') {
+ // This header should be ignored
+ $ignore[] = str_replace('_', '', $k);
+ } elseif ($k[0] == '!') {
+ // This header must not be present
+ $absent[] = str_replace('!', '', $k);
+ } else {
+ $expected[$k] = $v;
+ }
+ }
+
+ return $this->compareArray($expected, $actualHeaders, $ignore, $absent);
+ }
+
+ /**
+ * Check if an array of HTTP headers matches another array of HTTP headers while taking * into account as a wildcard
+ *
+ * @param array $expected Expected HTTP headers (allows wildcard values)
+ * @param array|Collection $actual Actual HTTP header array
+ * @param array $ignore Headers to ignore from the comparison
+ * @param array $absent Array of headers that must not be present
+ *
+ * @return array|bool Returns an array of the differences or FALSE if none
+ */
+ public function compareArray(array $expected, $actual, array $ignore = array(), array $absent = array())
+ {
+ $differences = array();
+
+ // Add information about headers that were present but weren't supposed to be
+ foreach ($absent as $header) {
+ if ($this->hasKey($header, $actual)) {
+ $differences["++ {$header}"] = $actual[$header];
+ unset($actual[$header]);
+ }
+ }
+
+ // Check if expected headers are missing
+ foreach ($expected as $header => $value) {
+ if (!$this->hasKey($header, $actual)) {
+ $differences["- {$header}"] = $value;
+ }
+ }
+
+ // Flip the ignore array so it works with the case insensitive helper
+ $ignore = array_flip($ignore);
+ // Allow case-insensitive comparisons in wildcards
+ $expected = array_change_key_case($expected);
+
+ // Compare the expected and actual HTTP headers in no particular order
+ foreach ($actual as $key => $value) {
+
+ // If this is to be ignored, the skip it
+ if ($this->hasKey($key, $ignore)) {
+ continue;
+ }
+
+ // If the header was not expected
+ if (!$this->hasKey($key, $expected)) {
+ $differences["+ {$key}"] = $value;
+ continue;
+ }
+
+ // Check values and take wildcards into account
+ $lkey = strtolower($key);
+ $pos = is_string($expected[$lkey]) ? strpos($expected[$lkey], '*') : false;
+
+ foreach ((array) $actual[$key] as $v) {
+ if (($pos === false && $v != $expected[$lkey]) || $pos > 0 && substr($v, 0, $pos) != substr($expected[$lkey], 0, $pos)) {
+ $differences[$key] = "{$value} != {$expected[$lkey]}";
+ }
+ }
+ }
+
+ return empty($differences) ? false : $differences;
+ }
+
+ /**
+ * Case insensitive check if an array have a key
+ *
+ * @param string $key Key to check
+ * @param array $array Array to check
+ *
+ * @return bool
+ */
+ protected function hasKey($key, $array)
+ {
+ if ($array instanceof Collection) {
+ $keys = $array->getKeys();
+ } else {
+ $keys = array_keys($array);
+ }
+
+ foreach ($keys as $k) {
+ if (!strcasecmp($k, $key)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderComparisonTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderComparisonTest.php
new file mode 100644
index 0000000..86c4fe8
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderComparisonTest.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace Guzzle\Tests\Message;
+
+use Guzzle\Common\Collection;
+use Guzzle\Tests\Http\Message\HeaderComparison;
+
+class HeaderComparisonTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function filterProvider()
+ {
+ return array(
+
+ // Headers match
+ array(array(
+ 'Content-Length' => 'Foo'
+ ), array(
+ 'Content-Length' => 'Foo'
+ ), false),
+
+ // Missing header
+ array(array(
+ 'X-Foo' => 'Bar'
+ ), array(), array(
+ '- X-Foo' => 'Bar'
+ )),
+
+ // Extra headers is present
+ array(array(
+ 'X-Foo' => 'Bar'
+ ), array(
+ 'X-Foo' => 'Bar',
+ 'X-Baz' => 'Jar'
+ ), array(
+ '+ X-Baz' => 'Jar'
+ )),
+
+ // Header is present but must be absent
+ array(array(
+ '!X-Foo' => '*'
+ ), array(
+ 'X-Foo' => 'Bar'
+ ), array(
+ '++ X-Foo' => 'Bar'
+ )),
+
+ // Different values
+ array(array(
+ 'X-Foo' => 'Bar'
+ ), array(
+ 'X-Foo' => 'Baz'
+ ), array(
+ 'X-Foo' => 'Baz != Bar'
+ )),
+
+ // Wildcard search passes
+ array(array(
+ 'X-Foo' => '*'
+ ), array(
+ 'X-Foo' => 'Bar'
+ ), false),
+
+ // Wildcard search fails
+ array(array(
+ 'X-Foo' => '*'
+ ), array(), array(
+ '- X-Foo' => '*'
+ )),
+
+ // Ignore extra header if present
+ array(array(
+ 'X-Foo' => '*',
+ '_X-Bar' => '*',
+ ), array(
+ 'X-Foo' => 'Baz',
+ 'X-Bar' => 'Jar'
+ ), false),
+
+ // Ignore extra header if present and is not
+ array(array(
+ 'X-Foo' => '*',
+ '_X-Bar' => '*',
+ ), array(
+ 'X-Foo' => 'Baz'
+ ), false),
+
+ // Case insensitive
+ array(array(
+ 'X-Foo' => '*',
+ '_X-Bar' => '*',
+ ), array(
+ 'x-foo' => 'Baz',
+ 'x-BAR' => 'baz'
+ ), false),
+
+ // Case insensitive with collection
+ array(array(
+ 'X-Foo' => '*',
+ '_X-Bar' => '*',
+ ), new Collection(array(
+ 'x-foo' => 'Baz',
+ 'x-BAR' => 'baz'
+ )), false),
+ );
+ }
+
+ /**
+ * @dataProvider filterProvider
+ */
+ public function testComparesHeaders($filters, $headers, $result)
+ {
+ $compare = new HeaderComparison();
+ $this->assertEquals($result, $compare->compare($filters, $headers));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderTest.php
new file mode 100644
index 0000000..c750234
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/HeaderTest.php
@@ -0,0 +1,162 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message;
+
+use Guzzle\Http\Message\Header;
+use Guzzle\Http\Message\Response;
+
+/**
+ * @covers Guzzle\Http\Message\Header
+ */
+class HeaderTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ protected $test = array(
+ 'zoo' => array('foo', 'Foo'),
+ 'Zoo' => 'bar',
+ );
+
+ public function testStoresHeaderName()
+ {
+ $i = new Header('Zoo', $this->test);
+ $this->assertEquals('Zoo', $i->getName());
+ }
+
+ public function testConvertsToString()
+ {
+ $i = new Header('Zoo', $this->test);
+ $this->assertEquals('foo, Foo, bar', (string) $i);
+ $i->setGlue(';');
+ $this->assertEquals('foo; Foo; bar', (string) $i);
+ }
+
+ public function testNormalizesGluedHeaders()
+ {
+ $h = new Header('Zoo', array('foo, Faz', 'bar'));
+ $result = $h->normalize(true)->toArray();
+ natsort($result);
+ $this->assertEquals(array('bar', 'foo', 'Faz'), $result);
+ }
+
+ public function testCanSearchForValues()
+ {
+ $h = new Header('Zoo', $this->test);
+ $this->assertTrue($h->hasValue('foo'));
+ $this->assertTrue($h->hasValue('Foo'));
+ $this->assertTrue($h->hasValue('bar'));
+ $this->assertFalse($h->hasValue('moo'));
+ $this->assertFalse($h->hasValue('FoO'));
+ }
+
+ public function testIsCountable()
+ {
+ $h = new Header('Zoo', $this->test);
+ $this->assertEquals(3, count($h));
+ }
+
+ public function testCanBeIterated()
+ {
+ $h = new Header('Zoo', $this->test);
+ $results = array();
+ foreach ($h as $key => $value) {
+ $results[$key] = $value;
+ }
+ $this->assertEquals(array(
+ 'foo', 'Foo', 'bar'
+ ), $results);
+ }
+
+ public function testAllowsFalseyValues()
+ {
+ // Allows 0
+ $h = new Header('Foo', 0, ';');
+ $this->assertEquals('0', (string) $h);
+ $this->assertEquals(1, count($h));
+ $this->assertEquals(';', $h->getGlue());
+
+ // Does not add a null header by default
+ $h = new Header('Foo');
+ $this->assertEquals('', (string) $h);
+ $this->assertEquals(0, count($h));
+
+ // Allows null array for a single null header
+ $h = new Header('Foo', array(null));
+ $this->assertEquals('', (string) $h);
+
+ // Allows empty string
+ $h = new Header('Foo', '');
+ $this->assertEquals('', (string) $h);
+ $this->assertEquals(1, count($h));
+ $this->assertEquals(1, count($h->normalize()->toArray()));
+ }
+
+ public function testCanRemoveValues()
+ {
+ $h = new Header('Foo', array('Foo', 'baz', 'bar'));
+ $h->removeValue('bar');
+ $this->assertTrue($h->hasValue('Foo'));
+ $this->assertFalse($h->hasValue('bar'));
+ $this->assertTrue($h->hasValue('baz'));
+ }
+
+ public function testAllowsArrayInConstructor()
+ {
+ $h = new Header('Foo', array('Testing', '123', 'Foo=baz'));
+ $this->assertEquals(array('Testing', '123', 'Foo=baz'), $h->toArray());
+ }
+
+ public function parseParamsProvider()
+ {
+ $res1 = array(
+ array(
+ '<http:/.../front.jpeg>' => '',
+ 'rel' => 'front',
+ 'type' => 'image/jpeg',
+ ),
+ array(
+ '<http://.../back.jpeg>' => '',
+ 'rel' => 'back',
+ 'type' => 'image/jpeg',
+ ),
+ );
+
+ return array(
+ array(
+ '<http:/.../front.jpeg>; rel="front"; type="image/jpeg", <http://.../back.jpeg>; rel=back; type="image/jpeg"',
+ $res1
+ ),
+ array(
+ '<http:/.../front.jpeg>; rel="front"; type="image/jpeg",<http://.../back.jpeg>; rel=back; type="image/jpeg"',
+ $res1
+ ),
+ array(
+ 'foo="baz"; bar=123, boo, test="123", foobar="foo;bar"',
+ array(
+ array('foo' => 'baz', 'bar' => '123'),
+ array('boo' => ''),
+ array('test' => '123'),
+ array('foobar' => 'foo;bar')
+ )
+ ),
+ array(
+ '<http://.../side.jpeg?test=1>; rel="side"; type="image/jpeg",<http://.../side.jpeg?test=2>; rel=side; type="image/jpeg"',
+ array(
+ array('<http://.../side.jpeg?test=1>' => '', 'rel' => 'side', 'type' => 'image/jpeg'),
+ array('<http://.../side.jpeg?test=2>' => '', 'rel' => 'side', 'type' => 'image/jpeg')
+ )
+ ),
+ array(
+ '',
+ array()
+ )
+ );
+ }
+
+ /**
+ * @dataProvider parseParamsProvider
+ */
+ public function testParseParams($header, $result)
+ {
+ $response = new Response(200, array('Link' => $header));
+ $this->assertEquals($result, $response->getHeader('Link')->parseParams());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/PostFileTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/PostFileTest.php
new file mode 100644
index 0000000..be048cb
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/PostFileTest.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message;
+
+use Guzzle\Http\Client;
+use Guzzle\Http\Message\PostFile;
+
+/**
+ * @covers Guzzle\Http\Message\PostFile
+ * @group server
+ */
+class PostFileTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testConstructorConfiguresPostFile()
+ {
+ $file = new PostFile('foo', __FILE__, 'x-foo', 'boo');
+ $this->assertEquals('foo', $file->getFieldName());
+ $this->assertEquals(__FILE__, $file->getFilename());
+ $this->assertEquals('boo', $file->getPostName());
+ $this->assertEquals('x-foo', $file->getContentType());
+ }
+
+ public function testRemovesLeadingAtSymbolFromPath()
+ {
+ $file = new PostFile('foo', '@' . __FILE__);
+ $this->assertEquals(__FILE__, $file->getFilename());
+ }
+
+ /**
+ * @expectedException Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testEnsuresFileIsReadable()
+ {
+ $file = new PostFile('foo', '/foo/baz/bar');
+ }
+
+ public function testCanChangeContentType()
+ {
+ $file = new PostFile('foo', '@' . __FILE__);
+ $file->setContentType('Boo');
+ $this->assertEquals('Boo', $file->getContentType());
+ }
+
+ public function testCanChangeFieldName()
+ {
+ $file = new PostFile('foo', '@' . __FILE__);
+ $file->setFieldName('Boo');
+ $this->assertEquals('Boo', $file->getFieldName());
+ }
+
+ public function testReturnsCurlValueString()
+ {
+ $file = new PostFile('foo', __FILE__);
+ if (version_compare(phpversion(), '5.5.0', '<')) {
+ $this->assertContains('@' . __FILE__ . ';filename=PostFileTest.php;type=text/x-', $file->getCurlValue());
+ } else {
+ $c = $file->getCurlValue();
+ $this->assertEquals(__FILE__, $c->getFilename());
+ $this->assertEquals('PostFileTest.php', $c->getPostFilename());
+ $this->assertContains('text/x-', $c->getMimeType());
+ }
+ }
+
+ public function testReturnsCurlValueStringAndPostname()
+ {
+ $file = new PostFile('foo', __FILE__, null, 'NewPostFileTest.php');
+ if (version_compare(phpversion(), '5.5.0', '<')) {
+ $this->assertContains('@' . __FILE__ . ';filename=NewPostFileTest.php;type=text/x-', $file->getCurlValue());
+ } else {
+ $c = $file->getCurlValue();
+ $this->assertEquals(__FILE__, $c->getFilename());
+ $this->assertEquals('NewPostFileTest.php', $c->getPostFilename());
+ $this->assertContains('text/x-', $c->getMimeType());
+ }
+ }
+
+ public function testContentDispositionFilePathIsStripped()
+ {
+ $this->getServer()->flush();
+ $client = new Client($this->getServer()->getUrl());
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request = $client->post()->addPostFile('file', __FILE__);
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(false);
+ $this->assertContains('POST / HTTP/1.1', $requests[0]);
+ $this->assertContains('Content-Disposition: form-data; name="file"; filename="PostFileTest.php"', $requests[0]);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/RequestFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/RequestFactoryTest.php
new file mode 100644
index 0000000..80b8d54
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/RequestFactoryTest.php
@@ -0,0 +1,616 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message;
+
+use Guzzle\Common\Collection;
+use Guzzle\Http\Client;
+use Guzzle\Http\Message\Response;
+use Guzzle\Http\Url;
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\Message\RequestFactory;
+use Guzzle\Http\Message\Request;
+use Guzzle\Http\QueryString;
+use Guzzle\Parser\Message\MessageParser;
+use Guzzle\Plugin\Log\LogPlugin;
+use Guzzle\Plugin\Mock\MockPlugin;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\Message\RequestFactory
+ */
+class HttpRequestFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testCachesSingletonInstance()
+ {
+ $factory = RequestFactory::getInstance();
+ $this->assertSame($factory, RequestFactory::getInstance());
+ }
+
+ public function testCreatesNewGetRequests()
+ {
+ $request = RequestFactory::getInstance()->create('GET', 'http://www.google.com/');
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\MessageInterface', $request);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\RequestInterface', $request);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\Request', $request);
+ $this->assertEquals('GET', $request->getMethod());
+ $this->assertEquals('http', $request->getScheme());
+ $this->assertEquals('http://www.google.com/', $request->getUrl());
+ $this->assertEquals('www.google.com', $request->getHost());
+ $this->assertEquals('/', $request->getPath());
+ $this->assertEquals('/', $request->getResource());
+
+ // Create a GET request with a custom receiving body
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $b = EntityBody::factory();
+ $request = RequestFactory::getInstance()->create('GET', $this->getServer()->getUrl(), null, $b);
+ $request->setClient(new Client());
+ $response = $request->send();
+ $this->assertSame($b, $response->getBody());
+ }
+
+ public function testCreatesPutRequests()
+ {
+ // Test using a string
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, 'Data');
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
+ $this->assertEquals('PUT', $request->getMethod());
+ $this->assertEquals('http', $request->getScheme());
+ $this->assertEquals('http://www.google.com/path?q=1&v=2', $request->getUrl());
+ $this->assertEquals('www.google.com', $request->getHost());
+ $this->assertEquals('/path', $request->getPath());
+ $this->assertEquals('/path?q=1&v=2', $request->getResource());
+ $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $request->getBody());
+ $this->assertEquals('Data', (string) $request->getBody());
+ unset($request);
+
+ // Test using an EntityBody
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, EntityBody::factory('Data'));
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
+ $this->assertEquals('Data', (string) $request->getBody());
+
+ // Test using a resource
+ $resource = fopen('php://temp', 'w+');
+ fwrite($resource, 'Data');
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, $resource);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
+ $this->assertEquals('Data', (string) $request->getBody());
+
+ // Test using an object that can be cast as a string
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, Url::factory('http://www.example.com/'));
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
+ $this->assertEquals('http://www.example.com/', (string) $request->getBody());
+ }
+
+ public function testCreatesHeadAndDeleteRequests()
+ {
+ $request = RequestFactory::getInstance()->create('DELETE', 'http://www.test.com/');
+ $this->assertEquals('DELETE', $request->getMethod());
+ $request = RequestFactory::getInstance()->create('HEAD', 'http://www.test.com/');
+ $this->assertEquals('HEAD', $request->getMethod());
+ }
+
+ public function testCreatesOptionsRequests()
+ {
+ $request = RequestFactory::getInstance()->create('OPTIONS', 'http://www.example.com/');
+ $this->assertEquals('OPTIONS', $request->getMethod());
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
+ }
+
+ public function testCreatesNewPutRequestWithBody()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, 'Data');
+ $this->assertEquals('Data', (string) $request->getBody());
+ }
+
+ public function testCreatesNewPostRequestWithFields()
+ {
+ // Use an array
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.google.com/path?q=1&v=2', null, array(
+ 'a' => 'b'
+ ));
+ $this->assertEquals(array('a' => 'b'), $request->getPostFields()->getAll());
+ unset($request);
+
+ // Use a collection
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.google.com/path?q=1&v=2', null, new Collection(array(
+ 'a' => 'b'
+ )));
+ $this->assertEquals(array('a' => 'b'), $request->getPostFields()->getAll());
+
+ // Use a QueryString
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.google.com/path?q=1&v=2', null, new QueryString(array(
+ 'a' => 'b'
+ )));
+ $this->assertEquals(array('a' => 'b'), $request->getPostFields()->getAll());
+
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.test.com/', null, array(
+ 'a' => 'b',
+ 'file' => '@' . __FILE__
+ ));
+
+ $this->assertEquals(array(
+ 'a' => 'b'
+ ), $request->getPostFields()->getAll());
+
+ $files = $request->getPostFiles();
+ $this->assertInstanceOf('Guzzle\Http\Message\PostFile', $files['file'][0]);
+ }
+
+ public function testCreatesFromParts()
+ {
+ $parts = parse_url('http://michael:123@www.google.com:8080/path?q=1&v=2');
+
+ $request = RequestFactory::getInstance()->fromParts('PUT', $parts, null, 'Data');
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
+ $this->assertEquals('PUT', $request->getMethod());
+ $this->assertEquals('http', $request->getScheme());
+ $this->assertEquals('http://www.google.com:8080/path?q=1&v=2', $request->getUrl());
+ $this->assertEquals('www.google.com', $request->getHost());
+ $this->assertEquals('www.google.com:8080', $request->getHeader('Host'));
+ $this->assertEquals('/path', $request->getPath());
+ $this->assertEquals('/path?q=1&v=2', $request->getResource());
+ $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $request->getBody());
+ $this->assertEquals('Data', (string) $request->getBody());
+ $this->assertEquals('michael', $request->getUsername());
+ $this->assertEquals('123', $request->getPassword());
+ $this->assertEquals('8080', $request->getPort());
+ $this->assertEquals(array(
+ 'scheme' => 'http',
+ 'host' => 'www.google.com',
+ 'port' => 8080,
+ 'path' => '/path',
+ 'query' => 'q=1&v=2',
+ ), parse_url($request->getUrl()));
+ }
+
+ public function testCreatesFromMessage()
+ {
+ $auth = base64_encode('michael:123');
+ $message = "PUT /path?q=1&v=2 HTTP/1.1\r\nHost: www.google.com:8080\r\nContent-Length: 4\r\nAuthorization: Basic {$auth}\r\n\r\nData";
+ $request = RequestFactory::getInstance()->fromMessage($message);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
+ $this->assertEquals('PUT', $request->getMethod());
+ $this->assertEquals('http', $request->getScheme());
+ $this->assertEquals('http://www.google.com:8080/path?q=1&v=2', $request->getUrl());
+ $this->assertEquals('www.google.com', $request->getHost());
+ $this->assertEquals('www.google.com:8080', $request->getHeader('Host'));
+ $this->assertEquals('/path', $request->getPath());
+ $this->assertEquals('/path?q=1&v=2', $request->getResource());
+ $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $request->getBody());
+ $this->assertEquals('Data', (string) $request->getBody());
+ $this->assertEquals("Basic {$auth}", (string) $request->getHeader('Authorization'));
+ $this->assertEquals('8080', $request->getPort());
+
+ // Test passing a blank message returns false
+ $this->assertFalse($request = RequestFactory::getInstance()->fromMessage(''));
+
+ // Test passing a url with no port
+ $message = "PUT /path?q=1&v=2 HTTP/1.1\r\nHost: www.google.com\r\nContent-Length: 4\r\nAuthorization: Basic {$auth}\r\n\r\nData";
+ $request = RequestFactory::getInstance()->fromMessage($message);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
+ $this->assertEquals('PUT', $request->getMethod());
+ $this->assertEquals('http', $request->getScheme());
+ $this->assertEquals('http://www.google.com/path?q=1&v=2', $request->getUrl());
+ $this->assertEquals('www.google.com', $request->getHost());
+ $this->assertEquals('/path', $request->getPath());
+ $this->assertEquals('/path?q=1&v=2', $request->getResource());
+ $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $request->getBody());
+ $this->assertEquals('Data', (string) $request->getBody());
+ $this->assertEquals("Basic {$auth}", (string) $request->getHeader('Authorization'));
+ $this->assertEquals(80, $request->getPort());
+ }
+
+ public function testCreatesNewTraceRequest()
+ {
+ $request = RequestFactory::getInstance()->create('TRACE', 'http://www.google.com/');
+ $this->assertFalse($request instanceof \Guzzle\Http\Message\EntityEnclosingRequest);
+ $this->assertEquals('TRACE', $request->getMethod());
+ }
+
+ public function testCreatesProperTransferEncodingRequests()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/', array(
+ 'Transfer-Encoding' => 'chunked'
+ ), 'hello');
+ $this->assertEquals('chunked', $request->getHeader('Transfer-Encoding'));
+ $this->assertFalse($request->hasHeader('Content-Length'));
+ }
+
+ public function testProperlyDealsWithDuplicateHeaders()
+ {
+ $parser = new MessageParser();
+
+ $message = "POST / http/1.1\r\n"
+ . "DATE:Mon, 09 Sep 2011 23:36:00 GMT\r\n"
+ . "host:host.foo.com\r\n"
+ . "ZOO:abc\r\n"
+ . "ZOO:123\r\n"
+ . "ZOO:HI\r\n"
+ . "zoo:456\r\n\r\n";
+
+ $parts = $parser->parseRequest($message);
+ $this->assertEquals(array (
+ 'DATE' => 'Mon, 09 Sep 2011 23:36:00 GMT',
+ 'host' => 'host.foo.com',
+ 'ZOO' => array('abc', '123', 'HI'),
+ 'zoo' => '456',
+ ), $parts['headers']);
+
+ $request = RequestFactory::getInstance()->fromMessage($message);
+
+ $this->assertEquals(array(
+ 'abc', '123', 'HI', '456'
+ ), $request->getHeader('zoo')->toArray());
+ }
+
+ public function testCreatesHttpMessagesWithBodiesAndNormalizesLineEndings()
+ {
+ $message = "POST / http/1.1\r\n"
+ . "Content-Type:application/x-www-form-urlencoded; charset=utf8\r\n"
+ . "Date:Mon, 09 Sep 2011 23:36:00 GMT\r\n"
+ . "Host:host.foo.com\r\n\r\n"
+ . "foo=bar";
+
+ $request = RequestFactory::getInstance()->fromMessage($message);
+ $this->assertEquals('application/x-www-form-urlencoded; charset=utf8', (string) $request->getHeader('Content-Type'));
+ $this->assertEquals('foo=bar', (string) $request->getBody());
+
+ $message = "POST / http/1.1\n"
+ . "Content-Type:application/x-www-form-urlencoded; charset=utf8\n"
+ . "Date:Mon, 09 Sep 2011 23:36:00 GMT\n"
+ . "Host:host.foo.com\n\n"
+ . "foo=bar";
+ $request = RequestFactory::getInstance()->fromMessage($message);
+ $this->assertEquals('foo=bar', (string) $request->getBody());
+
+ $message = "PUT / HTTP/1.1\r\nContent-Length: 0\r\n\r\n";
+ $request = RequestFactory::getInstance()->fromMessage($message);
+ $this->assertTrue($request->hasHeader('Content-Length'));
+ $this->assertEquals(0, (string) $request->getHeader('Content-Length'));
+ }
+
+ public function testBugPathIncorrectlyHandled()
+ {
+ $message = "POST /foo\r\n\r\nBODY";
+ $request = RequestFactory::getInstance()->fromMessage($message);
+ $this->assertSame('POST', $request->getMethod());
+ $this->assertSame('/foo', $request->getPath());
+ $this->assertSame('BODY', (string) $request->getBody());
+ }
+
+ public function testHandlesChunkedTransferEncoding()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.foo.com/', array(
+ 'Transfer-Encoding' => 'chunked'
+ ), 'Test');
+ $this->assertFalse($request->hasHeader('Content-Length'));
+ $this->assertEquals('chunked', $request->getHeader('Transfer-Encoding'));
+
+ $request = RequestFactory::getInstance()->create('POST', 'http://www.foo.com/', array(
+ 'transfer-encoding' => 'chunked'
+ ), array(
+ 'foo' => 'bar'
+ ));
+
+ $this->assertFalse($request->hasHeader('Content-Length'));
+ $this->assertEquals('chunked', $request->getHeader('Transfer-Encoding'));
+ }
+
+ public function testClonesRequestsWithMethodWithoutClient()
+ {
+ $f = RequestFactory::getInstance();
+ $request = $f->create('GET', 'http://www.test.com', array('X-Foo' => 'Bar'));
+ $request->getParams()->replace(array('test' => '123'));
+ $request->getCurlOptions()->set('foo', 'bar');
+ $cloned = $f->cloneRequestWithMethod($request, 'PUT');
+ $this->assertEquals('PUT', $cloned->getMethod());
+ $this->assertEquals('Bar', (string) $cloned->getHeader('X-Foo'));
+ $this->assertEquals('http://www.test.com', $cloned->getUrl());
+ // Ensure params are cloned and cleaned up
+ $this->assertEquals(1, count($cloned->getParams()->getAll()));
+ $this->assertEquals('123', $cloned->getParams()->get('test'));
+ // Ensure curl options are cloned
+ $this->assertEquals('bar', $cloned->getCurlOptions()->get('foo'));
+ // Ensure event dispatcher is cloned
+ $this->assertNotSame($request->getEventDispatcher(), $cloned->getEventDispatcher());
+ }
+
+ public function testClonesRequestsWithMethodWithClient()
+ {
+ $f = RequestFactory::getInstance();
+ $client = new Client();
+ $request = $client->put('http://www.test.com', array('Content-Length' => 4), 'test');
+ $cloned = $f->cloneRequestWithMethod($request, 'GET');
+ $this->assertEquals('GET', $cloned->getMethod());
+ $this->assertNull($cloned->getHeader('Content-Length'));
+ $this->assertEquals('http://www.test.com', $cloned->getUrl());
+ $this->assertSame($request->getClient(), $cloned->getClient());
+ }
+
+ public function testClonesRequestsWithMethodWithClientWithEntityEnclosingChange()
+ {
+ $f = RequestFactory::getInstance();
+ $client = new Client();
+ $request = $client->put('http://www.test.com', array('Content-Length' => 4), 'test');
+ $cloned = $f->cloneRequestWithMethod($request, 'POST');
+ $this->assertEquals('POST', $cloned->getMethod());
+ $this->assertEquals('test', (string) $cloned->getBody());
+ }
+
+ public function testCanDisableRedirects()
+ {
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 307\r\nLocation: " . $this->getServer()->getUrl() . "\r\nContent-Length: 0\r\n\r\n"
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $response = $client->get('/', array(), array('allow_redirects' => false))->send();
+ $this->assertEquals(307, $response->getStatusCode());
+ }
+
+ public function testCanAddCookies()
+ {
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get('/', array(), array('cookies' => array('Foo' => 'Bar')));
+ $this->assertEquals('Bar', $request->getCookie('Foo'));
+ }
+
+ public function testCanAddQueryString()
+ {
+ $request = RequestFactory::getInstance()->create('GET', 'http://foo.com', array(), null, array(
+ 'query' => array('Foo' => 'Bar')
+ ));
+ $this->assertEquals('Bar', $request->getQuery()->get('Foo'));
+ }
+
+ public function testCanSetDefaultQueryString()
+ {
+ $request = new Request('GET', 'http://www.foo.com?test=abc');
+ RequestFactory::getInstance()->applyOptions($request, array(
+ 'query' => array('test' => '123', 'other' => 't123')
+ ), RequestFactory::OPTIONS_AS_DEFAULTS);
+ $this->assertEquals('abc', $request->getQuery()->get('test'));
+ $this->assertEquals('t123', $request->getQuery()->get('other'));
+ }
+
+ public function testCanAddBasicAuth()
+ {
+ $request = RequestFactory::getInstance()->create('GET', 'http://foo.com', array(), null, array(
+ 'auth' => array('michael', 'test')
+ ));
+ $this->assertEquals('michael', $request->getUsername());
+ $this->assertEquals('test', $request->getPassword());
+ }
+
+ public function testCanAddDigestAuth()
+ {
+ $request = RequestFactory::getInstance()->create('GET', 'http://foo.com', array(), null, array(
+ 'auth' => array('michael', 'test', 'digest')
+ ));
+ $this->assertEquals(CURLAUTH_DIGEST, $request->getCurlOptions()->get(CURLOPT_HTTPAUTH));
+ $this->assertEquals('michael', $request->getUsername());
+ $this->assertEquals('test', $request->getPassword());
+ }
+
+ public function testCanAddEvents()
+ {
+ $foo = null;
+ $client = new Client();
+ $client->addSubscriber(new MockPlugin(array(new Response(200))));
+ $request = $client->get($this->getServer()->getUrl(), array(), array(
+ 'events' => array(
+ 'request.before_send' => function () use (&$foo) { $foo = true; }
+ )
+ ));
+ $request->send();
+ $this->assertTrue($foo);
+ }
+
+ public function testCanAddEventsWithPriority()
+ {
+ $foo = null;
+ $client = new Client();
+ $client->addSubscriber(new MockPlugin(array(new Response(200))));
+ $request = $client->get($this->getServer()->getUrl(), array(), array(
+ 'events' => array(
+ 'request.before_send' => array(function () use (&$foo) { $foo = true; }, 100)
+ )
+ ));
+ $request->send();
+ $this->assertTrue($foo);
+ }
+
+ public function testCanAddPlugins()
+ {
+ $mock = new MockPlugin(array(
+ new Response(200),
+ new Response(200)
+ ));
+ $client = new Client();
+ $client->addSubscriber($mock);
+ $request = $client->get('/', array(), array(
+ 'plugins' => array($mock)
+ ));
+ $request->send();
+ }
+
+ public function testCanDisableExceptions()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array(
+ 'plugins' => array(new MockPlugin(array(new Response(500)))),
+ 'exceptions' => false
+ ));
+ $this->assertEquals(500, $request->send()->getStatusCode());
+ }
+
+ public function testCanDisableExceptionsWithErrorListener()
+ {
+ $client = new Client();
+ $client->getEventDispatcher()->addListener('request.error', function () {});
+ $request = $client->get('/', array(), array(
+ 'plugins' => array(new MockPlugin(array(new Response(500)))),
+ 'exceptions' => false
+ ));
+ $this->assertEquals(500, $request->send()->getStatusCode());
+ }
+
+ public function testCanChangeSaveToLocation()
+ {
+ $r = EntityBody::factory();
+ $client = new Client();
+ $request = $client->get('/', array(), array(
+ 'plugins' => array(new MockPlugin(array(new Response(200, array(), 'testing')))),
+ 'save_to' => $r
+ ));
+ $request->send();
+ $this->assertEquals('testing', (string) $r);
+ }
+
+ public function testCanSetProxy()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('proxy' => '192.168.16.121'));
+ $this->assertEquals('192.168.16.121', $request->getCurlOptions()->get(CURLOPT_PROXY));
+ }
+
+ public function testCanSetHeadersOption()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('headers' => array('Foo' => 'Bar')));
+ $this->assertEquals('Bar', (string) $request->getHeader('Foo'));
+ }
+
+ public function testCanSetDefaultHeadersOptions()
+ {
+ $request = new Request('GET', 'http://www.foo.com', array('Foo' => 'Bar'));
+ RequestFactory::getInstance()->applyOptions($request, array(
+ 'headers' => array('Foo' => 'Baz', 'Bam' => 't123')
+ ), RequestFactory::OPTIONS_AS_DEFAULTS);
+ $this->assertEquals('Bar', (string) $request->getHeader('Foo'));
+ $this->assertEquals('t123', (string) $request->getHeader('Bam'));
+ }
+
+ public function testCanSetBodyOption()
+ {
+ $client = new Client();
+ $request = $client->put('/', array(), null, array('body' => 'test'));
+ $this->assertEquals('test', (string) $request->getBody());
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testValidatesBodyOption()
+ {
+ $client = new Client();
+ $client->get('/', array(), array('body' => 'test'));
+ }
+
+ public function testCanSetTimeoutOption()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('timeout' => 1.5));
+ $this->assertEquals(1500, $request->getCurlOptions()->get(CURLOPT_TIMEOUT_MS));
+ }
+
+ public function testCanSetConnectTimeoutOption()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('connect_timeout' => 1.5));
+ $this->assertEquals(1500, $request->getCurlOptions()->get(CURLOPT_CONNECTTIMEOUT_MS));
+ }
+
+ public function testCanSetDebug()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('debug' => true));
+ $this->assertTrue($request->getCurlOptions()->get(CURLOPT_VERBOSE));
+ }
+
+ public function testCanSetVerifyToOff()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('verify' => false));
+ $this->assertNull($request->getCurlOptions()->get(CURLOPT_CAINFO));
+ $this->assertSame(0, $request->getCurlOptions()->get(CURLOPT_SSL_VERIFYHOST));
+ $this->assertFalse($request->getCurlOptions()->get(CURLOPT_SSL_VERIFYPEER));
+ }
+
+ public function testCanSetVerifyToOn()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('verify' => true));
+ $this->assertNotNull($request->getCurlOptions()->get(CURLOPT_CAINFO));
+ $this->assertSame(2, $request->getCurlOptions()->get(CURLOPT_SSL_VERIFYHOST));
+ $this->assertTrue($request->getCurlOptions()->get(CURLOPT_SSL_VERIFYPEER));
+ }
+
+ public function testCanSetVerifyToPath()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('verify' => '/foo.pem'));
+ $this->assertEquals('/foo.pem', $request->getCurlOptions()->get(CURLOPT_CAINFO));
+ $this->assertSame(2, $request->getCurlOptions()->get(CURLOPT_SSL_VERIFYHOST));
+ $this->assertTrue($request->getCurlOptions()->get(CURLOPT_SSL_VERIFYPEER));
+ }
+
+ public function inputValidation()
+ {
+ return array_map(function ($option) { return array($option); }, array(
+ 'headers', 'query', 'cookies', 'auth', 'events', 'plugins', 'params'
+ ));
+ }
+
+ /**
+ * @dataProvider inputValidation
+ * @expectedException \Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testValidatesInput($option)
+ {
+ $client = new Client();
+ $client->get('/', array(), array($option => 'foo'));
+ }
+
+ public function testCanAddRequestParams()
+ {
+ $client = new Client();
+ $request = $client->put('/', array(), null, array('params' => array('foo' => 'test')));
+ $this->assertEquals('test', $request->getParams()->get('foo'));
+ }
+
+ public function testCanAddSslKey()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('ssl_key' => '/foo.pem'));
+ $this->assertEquals('/foo.pem', $request->getCurlOptions()->get(CURLOPT_SSLKEY));
+ }
+
+ public function testCanAddSslKeyPassword()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('ssl_key' => array('/foo.pem', 'bar')));
+ $this->assertEquals('/foo.pem', $request->getCurlOptions()->get(CURLOPT_SSLKEY));
+ $this->assertEquals('bar', $request->getCurlOptions()->get(CURLOPT_SSLKEYPASSWD));
+ }
+
+ public function testCanAddSslCert()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('cert' => '/foo.pem'));
+ $this->assertEquals('/foo.pem', $request->getCurlOptions()->get(CURLOPT_SSLCERT));
+ }
+
+ public function testCanAddSslCertPassword()
+ {
+ $client = new Client();
+ $request = $client->get('/', array(), array('cert' => array('/foo.pem', 'bar')));
+ $this->assertEquals('/foo.pem', $request->getCurlOptions()->get(CURLOPT_SSLCERT));
+ $this->assertEquals('bar', $request->getCurlOptions()->get(CURLOPT_SSLCERTPASSWD));
+ }
+
+ public function testCreatesBodyWithoutZeroString()
+ {
+ $request = RequestFactory::getInstance()->create('PUT', 'http://test.com', array(), '0');
+ $this->assertSame('0', (string) $request->getBody());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/RequestTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/RequestTest.php
new file mode 100644
index 0000000..5bf6248
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/RequestTest.php
@@ -0,0 +1,639 @@
+<?php
+
+namespace Guzzle\Tests\Http\Message;
+
+use Guzzle\Common\Collection;
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\Url;
+use Guzzle\Http\Client;
+use Guzzle\Plugin\Async\AsyncPlugin;
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Http\Message\Request;
+use Guzzle\Http\Message\Response;
+use Guzzle\Http\Message\RequestFactory;
+use Guzzle\Http\RedirectPlugin;
+use Guzzle\Http\Exception\BadResponseException;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\Message\Request
+ * @covers Guzzle\Http\Message\AbstractMessage
+ */
+class RequestTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /** @var Request */
+ protected $request;
+
+ /** @var Client */
+ protected $client;
+
+ protected function setUp()
+ {
+ $this->client = new Client($this->getServer()->getUrl());
+ $this->request = $this->client->get();
+ }
+
+ public function tearDown()
+ {
+ unset($this->request);
+ unset($this->client);
+ }
+
+ public function testConstructorBuildsRequestWithArrayHeaders()
+ {
+ // Test passing an array of headers
+ $request = new Request('GET', 'http://www.guzzle-project.com/', array(
+ 'foo' => 'bar'
+ ));
+
+ $this->assertEquals('GET', $request->getMethod());
+ $this->assertEquals('http://www.guzzle-project.com/', $request->getUrl());
+ $this->assertEquals('bar', $request->getHeader('foo'));
+ }
+
+ public function testDescribesEvents()
+ {
+ $this->assertInternalType('array', Request::getAllEvents());
+ }
+
+ public function testConstructorBuildsRequestWithCollectionHeaders()
+ {
+ $request = new Request('GET', 'http://www.guzzle-project.com/', new Collection(array(
+ 'foo' => 'bar'
+ )));
+ $this->assertEquals('bar', $request->getHeader('foo'));
+ }
+
+ public function testConstructorBuildsRequestWithNoHeaders()
+ {
+ $request = new Request('GET', 'http://www.guzzle-project.com/', null);
+ $this->assertFalse($request->hasHeader('foo'));
+ }
+
+ public function testConstructorHandlesNonBasicAuth()
+ {
+ $request = new Request('GET', 'http://www.guzzle-project.com/', array(
+ 'Authorization' => 'Foo bar'
+ ));
+ $this->assertNull($request->getUserName());
+ $this->assertNull($request->getPassword());
+ $this->assertEquals('Foo bar', (string) $request->getHeader('Authorization'));
+ }
+
+ public function testRequestsCanBeConvertedToRawMessageStrings()
+ {
+ $auth = base64_encode('michael:123');
+ $message = "PUT /path?q=1&v=2 HTTP/1.1\r\n"
+ . "Host: www.google.com\r\n"
+ . "Authorization: Basic {$auth}\r\n"
+ . "Content-Length: 4\r\n\r\nData";
+
+ $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', array(
+ 'Authorization' => 'Basic ' . $auth
+ ), 'Data');
+
+ $this->assertEquals($message, $request->__toString());
+ }
+
+ /**
+ * Add authorization after the fact and see that it was put in the message
+ */
+ public function testRequestStringsIncludeAuth()
+ {
+ $auth = base64_encode('michael:123');
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request = RequestFactory::getInstance()->create('PUT', $this->getServer()->getUrl(), null, 'Data')
+ ->setClient($this->client)
+ ->setAuth('michael', '123', CURLAUTH_BASIC);
+ $request->send();
+
+ $this->assertContains('Authorization: Basic ' . $auth, (string) $request);
+ }
+
+ public function testGetEventDispatcher()
+ {
+ $d = $this->request->getEventDispatcher();
+ $this->assertInstanceOf('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', $d);
+ $this->assertEquals($d, $this->request->getEventDispatcher());
+ }
+
+ public function testRequestsManageClients()
+ {
+ $request = new Request('GET', 'http://test.com');
+ $this->assertNull($request->getClient());
+ $request->setClient($this->client);
+ $this->assertSame($this->client, $request->getClient());
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ * @expectedExceptionMessage A client must be set on the request
+ */
+ public function testRequestsRequireClients()
+ {
+ $request = new Request('GET', 'http://test.com');
+ $request->send();
+ }
+
+ public function testSend()
+ {
+ $response = new Response(200, array(
+ 'Content-Length' => 3
+ ), 'abc');
+ $this->request->setResponse($response, true);
+ $r = $this->request->send();
+
+ $this->assertSame($response, $r);
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $this->request->getResponse());
+ $this->assertSame($r, $this->request->getResponse());
+ $this->assertEquals('complete', $this->request->getState());
+ }
+
+ public function testGetResponse()
+ {
+ $this->assertNull($this->request->getResponse());
+ $response = new Response(200, array('Content-Length' => 3), 'abc');
+
+ $this->request->setResponse($response);
+ $this->assertEquals($response, $this->request->getResponse());
+
+ $client = new Client('http://www.google.com');
+ $request = $client->get('http://www.google.com/');
+ $request->setResponse($response, true);
+ $request->send();
+ $requestResponse = $request->getResponse();
+ $this->assertSame($response, $requestResponse);
+
+ // Try again, making sure it's still the same response
+ $this->assertSame($requestResponse, $request->getResponse());
+
+ $response = new Response(204);
+ $request = $client->get();
+ $request->setResponse($response, true);
+ $request->send();
+ $requestResponse = $request->getResponse();
+ $this->assertSame($response, $requestResponse);
+ $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $response->getBody());
+ }
+
+ public function testRequestThrowsExceptionOnBadResponse()
+ {
+ try {
+ $this->request->setResponse(new Response(404, array('Content-Length' => 3), 'abc'), true);
+ $this->request->send();
+ $this->fail('Expected exception not thrown');
+ } catch (BadResponseException $e) {
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\RequestInterface', $e->getRequest());
+ $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $e->getResponse());
+ $this->assertContains('Client error response', $e->getMessage());
+ }
+ }
+
+ public function testManagesQuery()
+ {
+ $this->assertInstanceOf('Guzzle\\Http\\QueryString', $this->request->getQuery());
+ $this->request->getQuery()->set('test', '123');
+ $this->assertEquals('test=123', $this->request->getQuery(true));
+ }
+
+ public function testRequestHasMethod()
+ {
+ $this->assertEquals('GET', $this->request->getMethod());
+ }
+
+ public function testRequestHasScheme()
+ {
+ $this->assertEquals('http', $this->request->getScheme());
+ $this->assertEquals($this->request, $this->request->setScheme('https'));
+ $this->assertEquals('https', $this->request->getScheme());
+ }
+
+ public function testRequestHasHost()
+ {
+ $this->assertEquals('127.0.0.1', $this->request->getHost());
+ $this->assertEquals('127.0.0.1:8124', (string) $this->request->getHeader('Host'));
+
+ $this->assertSame($this->request, $this->request->setHost('www2.google.com'));
+ $this->assertEquals('www2.google.com', $this->request->getHost());
+ $this->assertEquals('www2.google.com:8124', (string) $this->request->getHeader('Host'));
+
+ $this->assertSame($this->request, $this->request->setHost('www.test.com:8081'));
+ $this->assertEquals('www.test.com', $this->request->getHost());
+ $this->assertEquals(8081, $this->request->getPort());
+ }
+
+ public function testRequestHasProtocol()
+ {
+ $this->assertEquals('1.1', $this->request->getProtocolVersion());
+ $this->assertEquals($this->request, $this->request->setProtocolVersion('1.1'));
+ $this->assertEquals('1.1', $this->request->getProtocolVersion());
+ $this->assertEquals($this->request, $this->request->setProtocolVersion('1.0'));
+ $this->assertEquals('1.0', $this->request->getProtocolVersion());
+ }
+
+ public function testRequestHasPath()
+ {
+ $this->assertEquals('/', $this->request->getPath());
+ $this->assertEquals($this->request, $this->request->setPath('/index.html'));
+ $this->assertEquals('/index.html', $this->request->getPath());
+ $this->assertEquals($this->request, $this->request->setPath('index.html'));
+ $this->assertEquals('/index.html', $this->request->getPath());
+ }
+
+ public function testPermitsFalsyComponents()
+ {
+ $request = new Request('GET', 'http://0/0?0');
+ $this->assertSame('0', $request->getHost());
+ $this->assertSame('/0', $request->getPath());
+ $this->assertSame('0', $request->getQuery(true));
+
+ $request = new Request('GET', '0');
+ $this->assertEquals('/0', $request->getPath());
+ }
+
+ public function testRequestHasPort()
+ {
+ $this->assertEquals(8124, $this->request->getPort());
+ $this->assertEquals('127.0.0.1:8124', $this->request->getHeader('Host'));
+
+ $this->assertEquals($this->request, $this->request->setPort('8080'));
+ $this->assertEquals('8080', $this->request->getPort());
+ $this->assertEquals('127.0.0.1:8080', $this->request->getHeader('Host'));
+
+ $this->request->setPort(80);
+ $this->assertEquals('127.0.0.1', $this->request->getHeader('Host'));
+ }
+
+ public function testRequestHandlesAuthorization()
+ {
+ // Uninitialized auth
+ $this->assertEquals(null, $this->request->getUsername());
+ $this->assertEquals(null, $this->request->getPassword());
+
+ // Set an auth
+ $this->assertSame($this->request, $this->request->setAuth('michael', '123'));
+ $this->assertEquals('michael', $this->request->getUsername());
+ $this->assertEquals('123', $this->request->getPassword());
+
+ // Set an auth with blank password
+ $this->assertSame($this->request, $this->request->setAuth('michael', ''));
+ $this->assertEquals('michael', $this->request->getUsername());
+ $this->assertEquals('', $this->request->getPassword());
+
+ // Remove the auth
+ $this->request->setAuth(false);
+ $this->assertEquals(null, $this->request->getUsername());
+ $this->assertEquals(null, $this->request->getPassword());
+
+ // Make sure that the cURL based auth works too
+ $request = new Request('GET', $this->getServer()->getUrl());
+ $request->setAuth('michael', 'password', CURLAUTH_DIGEST);
+ $this->assertEquals('michael:password', $request->getCurlOptions()->get(CURLOPT_USERPWD));
+ $this->assertEquals(CURLAUTH_DIGEST, $request->getCurlOptions()->get(CURLOPT_HTTPAUTH));
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testValidatesAuth()
+ {
+ $this->request->setAuth('foo', 'bar', 'bam');
+ }
+
+ public function testGetResourceUri()
+ {
+ $this->assertEquals('/', $this->request->getResource());
+ $this->request->setPath('/index.html');
+ $this->assertEquals('/index.html', $this->request->getResource());
+ $this->request->getQuery()->add('v', '1');
+ $this->assertEquals('/index.html?v=1', $this->request->getResource());
+ }
+
+ public function testRequestHasMutableUrl()
+ {
+ $url = 'http://www.test.com:8081/path?q=123#fragment';
+ $u = Url::factory($url);
+ $this->assertSame($this->request, $this->request->setUrl($url));
+ $this->assertEquals($url, $this->request->getUrl());
+
+ $this->assertSame($this->request, $this->request->setUrl($u));
+ $this->assertEquals($url, $this->request->getUrl());
+ }
+
+ public function testRequestHasState()
+ {
+ $this->assertEquals(RequestInterface::STATE_NEW, $this->request->getState());
+ $this->request->setState(RequestInterface::STATE_TRANSFER);
+ $this->assertEquals(RequestInterface::STATE_TRANSFER, $this->request->getState());
+ }
+
+ public function testSetManualResponse()
+ {
+ $response = new Response(200, array(
+ 'Date' => 'Sat, 16 Oct 2010 17:27:14 GMT',
+ 'Expires' => '-1',
+ 'Cache-Control' => 'private, max-age=0',
+ 'Content-Type' => 'text/html; charset=ISO-8859-1',
+ ), 'response body');
+
+ $this->assertSame($this->request, $this->request->setResponse($response), '-> setResponse() must use a fluent interface');
+ $this->assertEquals('complete', $this->request->getState(), '-> setResponse() must change the state of the request to complete');
+ $this->assertSame($response, $this->request->getResponse(), '-> setResponse() must set the exact same response that was passed in to it');
+ }
+
+ public function testRequestCanHaveManuallySetResponseBody()
+ {
+ $file = __DIR__ . '/../../TestData/temp.out';
+ if (file_exists($file)) {
+ unlink($file);
+ }
+
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ndata");
+ $request = RequestFactory::getInstance()->create('GET', $this->getServer()->getUrl());
+ $request->setClient($this->client);
+ $entityBody = EntityBody::factory(fopen($file, 'w+'));
+ $request->setResponseBody($entityBody);
+ $response = $request->send();
+ $this->assertSame($entityBody, $response->getBody());
+
+ $this->assertTrue(file_exists($file));
+ $this->assertEquals('data', file_get_contents($file));
+ unlink($file);
+
+ $this->assertEquals('data', $response->getBody(true));
+ }
+
+ public function testHoldsCookies()
+ {
+ $this->assertNull($this->request->getCookie('test'));
+
+ // Set a cookie
+ $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
+ $this->assertEquals('abc', $this->request->getCookie('test'));
+
+ // Multiple cookies by setting the Cookie header
+ $this->request->setHeader('Cookie', '__utma=1.638370270.1344367610.1374365610.1944450276.2; __utmz=1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); hl=de; PHPSESSID=ak93pqashi5uubuoq8fjv60897');
+ $this->assertEquals('1.638370270.1344367610.1374365610.1944450276.2', $this->request->getCookie('__utma'));
+ $this->assertEquals('1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', $this->request->getCookie('__utmz'));
+ $this->assertEquals('de', $this->request->getCookie('hl'));
+ $this->assertEquals('ak93pqashi5uubuoq8fjv60897', $this->request->getCookie('PHPSESSID'));
+
+ // Unset the cookies by setting the Cookie header to null
+ $this->request->setHeader('Cookie', null);
+ $this->assertNull($this->request->getCookie('test'));
+ $this->request->removeHeader('Cookie');
+
+ // Set and remove a cookie
+ $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
+ $this->assertEquals('abc', $this->request->getCookie('test'));
+ $this->assertSame($this->request, $this->request->removeCookie('test'));
+ $this->assertNull($this->request->getCookie('test'));
+
+ // Remove the cookie header
+ $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
+ $this->request->removeHeader('Cookie');
+ $this->assertEquals('', (string) $this->request->getHeader('Cookie'));
+
+ // Remove a cookie value
+ $this->request->addCookie('foo', 'bar')->addCookie('baz', 'boo');
+ $this->request->removeCookie('foo');
+ $this->assertEquals(array(
+ 'baz' => 'boo'
+ ), $this->request->getCookies());
+
+ $this->request->addCookie('foo', 'bar');
+ $this->assertEquals('baz=boo; foo=bar', (string) $this->request->getHeader('Cookie'));
+ }
+
+ /**
+ * @expectedException \Guzzle\Http\Exception\RequestException
+ * @expectedExceptionMessage Error completing request
+ */
+ public function testRequestThrowsExceptionWhenSetToCompleteWithNoResponse()
+ {
+ $this->request->setState(RequestInterface::STATE_COMPLETE);
+ }
+
+ public function testClonedRequestsUseNewInternalState()
+ {
+ $p = new AsyncPlugin();
+ $this->request->getEventDispatcher()->addSubscriber($p);
+ $h = $this->request->getHeader('Host');
+
+ $r = clone $this->request;
+ $this->assertEquals(RequestInterface::STATE_NEW, $r->getState());
+ $this->assertNotSame($r->getQuery(), $this->request->getQuery());
+ $this->assertNotSame($r->getCurlOptions(), $this->request->getCurlOptions());
+ $this->assertNotSame($r->getEventDispatcher(), $this->request->getEventDispatcher());
+ $this->assertEquals($r->getHeaders(), $this->request->getHeaders());
+ $this->assertNotSame($h, $r->getHeader('Host'));
+ $this->assertNotSame($r->getParams(), $this->request->getParams());
+ $this->assertTrue($this->request->getEventDispatcher()->hasListeners('request.sent'));
+ }
+
+ public function testRecognizesBasicAuthCredentialsInUrls()
+ {
+ $this->request->setUrl('http://michael:test@test.com/');
+ $this->assertEquals('michael', $this->request->getUsername());
+ $this->assertEquals('test', $this->request->getPassword());
+ }
+
+ public function testRequestCanBeSentUsingCurl()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 4\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\nConnection: close\r\n\r\ndata",
+ "HTTP/1.1 200 OK\r\nContent-Length: 4\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\nConnection: close\r\n\r\ndata",
+ "HTTP/1.1 404 Not Found\r\nContent-Encoding: application/xml\r\nContent-Length: 48\r\n\r\n<error><mesage>File not found</message></error>"
+ ));
+
+ $request = RequestFactory::getInstance()->create('GET', $this->getServer()->getUrl());
+ $request->setClient($this->client);
+ $response = $request->send();
+
+ $this->assertEquals('data', $response->getBody(true));
+ $this->assertEquals(200, (int) $response->getStatusCode());
+ $this->assertEquals('OK', $response->getReasonPhrase());
+ $this->assertEquals(4, $response->getContentLength());
+ $this->assertEquals('Thu, 01 Dec 1994 16:00:00 GMT', $response->getExpires());
+
+ // Test that the same handle can be sent twice without setting state to new
+ $response2 = $request->send();
+ $this->assertNotSame($response, $response2);
+
+ try {
+ $request = RequestFactory::getInstance()->create('GET', $this->getServer()->getUrl() . 'index.html');
+ $request->setClient($this->client);
+ $response = $request->send();
+ $this->fail('Request did not receive a 404 response');
+ } catch (BadResponseException $e) {
+ }
+
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $messages = $this->getServer()->getReceivedRequests(false);
+ $port = $this->getServer()->getPort();
+
+ $userAgent = $this->client->getDefaultUserAgent();
+
+ $this->assertEquals('127.0.0.1:' . $port, $requests[0]->getHeader('Host'));
+ $this->assertEquals('127.0.0.1:' . $port, $requests[1]->getHeader('Host'));
+ $this->assertEquals('127.0.0.1:' . $port, $requests[2]->getHeader('Host'));
+
+ $this->assertEquals('/', $requests[0]->getPath());
+ $this->assertEquals('/', $requests[1]->getPath());
+ $this->assertEquals('/index.html', $requests[2]->getPath());
+
+ $parts = explode("\r\n", $messages[0]);
+ $this->assertEquals('GET / HTTP/1.1', $parts[0]);
+
+ $parts = explode("\r\n", $messages[1]);
+ $this->assertEquals('GET / HTTP/1.1', $parts[0]);
+
+ $parts = explode("\r\n", $messages[2]);
+ $this->assertEquals('GET /index.html HTTP/1.1', $parts[0]);
+ }
+
+ public function testThrowsExceptionsWhenUnsuccessfulResponseIsReceivedByDefault()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 404 Not found\r\nContent-Length: 0\r\n\r\n");
+
+ try {
+ $request = $this->client->get('/index.html');
+ $response = $request->send();
+ $this->fail('Request did not receive a 404 response');
+ } catch (BadResponseException $e) {
+ $this->assertContains('Client error response', $e->getMessage());
+ $this->assertContains('[status code] 404', $e->getMessage());
+ $this->assertContains('[reason phrase] Not found', $e->getMessage());
+ }
+ }
+
+ public function testCanShortCircuitErrorHandling()
+ {
+ $request = $this->request;
+ $response = new Response(404);
+ $request->setResponse($response, true);
+ $out = '';
+ $that = $this;
+ $request->getEventDispatcher()->addListener('request.error', function($event) use (&$out, $that) {
+ $out .= $event['request'] . "\n" . $event['response'] . "\n";
+ $event->stopPropagation();
+ });
+ $request->send();
+ $this->assertContains((string) $request, $out);
+ $this->assertContains((string) $request->getResponse(), $out);
+ $this->assertSame($response, $request->getResponse());
+ }
+
+ public function testCanOverrideUnsuccessfulResponses()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 404 NOT FOUND\r\n" .
+ "Content-Length: 0\r\n" .
+ "\r\n",
+ "HTTP/1.1 200 OK\r\n" .
+ "Content-Length: 0\r\n" .
+ "\r\n"
+ ));
+
+ $newResponse = null;
+
+ $request = $this->request;
+ $request->getEventDispatcher()->addListener('request.error', function($event) use (&$newResponse) {
+ if ($event['response']->getStatusCode() == 404) {
+ $newRequest = clone $event['request'];
+ $newResponse = $newRequest->send();
+ // Override the original response and bypass additional response processing
+ $event['response'] = $newResponse;
+ // Call $event['request']->setResponse($newResponse); to re-apply events
+ $event->stopPropagation();
+ }
+ });
+
+ $request->send();
+
+ $this->assertEquals(200, $request->getResponse()->getStatusCode());
+ $this->assertSame($newResponse, $request->getResponse());
+ $this->assertEquals(2, count($this->getServer()->getReceivedRequests()));
+ }
+
+ public function testCanRetrieveUrlObject()
+ {
+ $request = new Request('GET', 'http://www.example.com/foo?abc=d');
+ $this->assertInstanceOf('Guzzle\Http\Url', $request->getUrl(true));
+ $this->assertEquals('http://www.example.com/foo?abc=d', $request->getUrl());
+ $this->assertEquals('http://www.example.com/foo?abc=d', (string) $request->getUrl(true));
+ }
+
+ public function testUnresolvedRedirectsReturnResponse()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 303 SEE OTHER\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 301 Foo\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n"
+ ));
+ $request = $this->request;
+ $this->assertEquals(303, $request->send()->getStatusCode());
+ $request->getParams()->set(RedirectPlugin::DISABLE, true);
+ $this->assertEquals(301, $request->send()->getStatusCode());
+ }
+
+ public function testCanSendCustomRequests()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request = $this->client->createRequest('PROPFIND', $this->getServer()->getUrl(), array(
+ 'Content-Type' => 'text/plain'
+ ), 'foo');
+ $response = $request->send();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('PROPFIND', $requests[0]->getMethod());
+ $this->assertEquals(3, (string) $requests[0]->getHeader('Content-Length'));
+ $this->assertEquals('foo', (string) $requests[0]->getBody());
+ }
+
+ /**
+ * @expectedException \PHPUnit_Framework_Error_Warning
+ */
+ public function testEnsuresFileCanBeCreated()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest");
+ $this->client->get('/')->setResponseBody('/wefwefefefefwewefwe/wefwefwefefwe/wefwefewfw.txt')->send();
+ }
+
+ public function testAllowsFilenameForDownloadingContent()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest");
+ $name = sys_get_temp_dir() . '/foo.txt';
+ $this->client->get('/')->setResponseBody($name)->send();
+ $this->assertEquals('test', file_get_contents($name));
+ unlink($name);
+ }
+
+ public function testUsesCustomResponseBodyWhenItIsCustom()
+ {
+ $en = EntityBody::factory();
+ $request = $this->client->get();
+ $request->setResponseBody($en);
+ $request->setResponse(new Response(200, array(), 'foo'));
+ $this->assertEquals('foo', (string) $en);
+ }
+
+ public function testCanChangePortThroughScheme()
+ {
+ $request = new Request('GET', 'http://foo.com');
+ $request->setScheme('https');
+ $this->assertEquals('https://foo.com', (string) $request->getUrl());
+ $this->assertEquals('foo.com', $request->getHost());
+ $request->setScheme('http');
+ $this->assertEquals('http://foo.com', (string) $request->getUrl());
+ $this->assertEquals('foo.com', $request->getHost());
+ $request->setPort(null);
+ $this->assertEquals('http://foo.com', (string) $request->getUrl());
+ $this->assertEquals('foo.com', $request->getHost());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/ResponseTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/ResponseTest.php
new file mode 100644
index 0000000..08b4df8
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Message/ResponseTest.php
@@ -0,0 +1,677 @@
+<?php
+
+namespace Guzzle\Tests\Message;
+
+use Guzzle\Common\Collection;
+use Guzzle\Http\ClientInterface;
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\HttpException;
+use Guzzle\Http\Exception\BadResponseException;
+use Guzzle\Http\Message\Response;
+
+/**
+ * @group server
+ * @covers Guzzle\Http\Message\Response
+ */
+class ResponseTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /** @var Response The response object to test */
+ protected $response;
+
+ public function setup()
+ {
+ $this->response = new Response(200, new Collection(array(
+ 'Accept-Ranges' => 'bytes',
+ 'Age' => '12',
+ 'Allow' => 'GET, HEAD',
+ 'Cache-Control' => 'no-cache',
+ 'Content-Encoding' => 'gzip',
+ 'Content-Language' => 'da',
+ 'Content-Length' => '348',
+ 'Content-Location' => '/index.htm',
+ 'Content-Disposition' => 'attachment; filename=fname.ext',
+ 'Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ==',
+ 'Content-Range' => 'bytes 21010-47021/47022',
+ 'Content-Type' => 'text/html; charset=utf-8',
+ 'Date' => 'Tue, 15 Nov 1994 08:12:31 GMT',
+ 'ETag' => '737060cd8c284d8af7ad3082f209582d',
+ 'Expires' => 'Thu, 01 Dec 1994 16:00:00 GMT',
+ 'Last-Modified' => 'Tue, 15 Nov 1994 12:45:26 GMT',
+ 'Location' => 'http://www.w3.org/pub/WWW/People.html',
+ 'Pragma' => 'no-cache',
+ 'Proxy-Authenticate' => 'Basic',
+ 'Retry-After' => '120',
+ 'Server' => 'Apache/1.3.27 (Unix) (Red-Hat/Linux)',
+ 'Set-Cookie' => 'UserID=JohnDoe; Max-Age=3600; Version=1',
+ 'Trailer' => 'Max-Forwards',
+ 'Transfer-Encoding' => 'chunked',
+ 'Vary' => '*',
+ 'Via' => '1.0 fred, 1.1 nowhere.com (Apache/1.1)',
+ 'Warning' => '199 Miscellaneous warning',
+ 'WWW-Authenticate' => 'Basic'
+ )), 'body');
+ }
+
+ public function tearDown()
+ {
+ unset($this->response);
+ }
+
+ public function testConstructor()
+ {
+ $params = new Collection();
+ $body = EntityBody::factory('');
+ $response = new Response(200, $params, $body);
+ $this->assertEquals(200, $response->getStatusCode());
+ $this->assertEquals($body, $response->getBody());
+ $this->assertEquals('OK', $response->getReasonPhrase());
+ $this->assertEquals("HTTP/1.1 200 OK\r\n\r\n", $response->getRawHeaders());
+
+ // Make sure Content-Length is set automatically
+ $response = new Response(200, $params);
+ $this->assertEquals("HTTP/1.1 200 OK\r\n\r\n", $response->getRawHeaders());
+
+ // Pass bodies to the response
+ $response = new Response(200, null, 'data');
+ $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $response->getBody());
+ $response = new Response(200, null, EntityBody::factory('data'));
+ $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $response->getBody());
+ $this->assertEquals('data', $response->getBody(true));
+ $response = new Response(200, null, '0');
+ $this->assertSame('0', $response->getBody(true), 'getBody(true) should return "0" if response body is "0".');
+
+ // Make sure the proper exception is thrown
+ try {
+ //$response = new Response(200, null, array('foo' => 'bar'));
+ //$this->fail('Response did not throw exception when passing invalid body');
+ } catch (HttpException $e) {
+ }
+
+ // Ensure custom codes can be set
+ $response = new Response(2);
+ $this->assertEquals(2, $response->getStatusCode());
+ $this->assertEquals('', $response->getReasonPhrase());
+
+ // Make sure the proper exception is thrown when sending invalid headers
+ try {
+ $response = new Response(200, 'adidas');
+ $this->fail('Response did not throw exception when passing invalid $headers');
+ } catch (BadResponseException $e) {
+ }
+ }
+
+ public function test__toString()
+ {
+ $response = new Response(200);
+ $this->assertEquals("HTTP/1.1 200 OK\r\n\r\n", (string) $response);
+
+ // Add another header
+ $response = new Response(200, array(
+ 'X-Test' => 'Guzzle'
+ ));
+ $this->assertEquals("HTTP/1.1 200 OK\r\nX-Test: Guzzle\r\n\r\n", (string) $response);
+
+ $response = new Response(200, array(
+ 'Content-Length' => 4
+ ), 'test');
+ $this->assertEquals("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest", (string) $response);
+ }
+
+ public function testFactory()
+ {
+ $response = Response::fromMessage("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest");
+ $this->assertEquals(200, $response->getStatusCode());
+ $this->assertEquals('OK', $response->getReasonPhrase());
+ $this->assertEquals(4, (string) $response->getContentLength());
+ $this->assertEquals('test', $response->getBody(true));
+
+ // Make sure that automatic Content-Length works
+ $response = Response::fromMessage("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest");
+ $this->assertEquals(4, (string) $response->getContentLength());
+ $this->assertEquals('test', $response->getBody(true));
+ }
+
+ public function testFactoryCanCreateHeadResponses()
+ {
+ $response = Response::fromMessage("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\n");
+ $this->assertEquals(200, $response->getStatusCode());
+ $this->assertEquals('OK', $response->getReasonPhrase());
+ $this->assertEquals(4, (string) $response->getContentLength());
+ $this->assertEquals('', $response->getBody(true));
+ }
+
+ public function testFactoryRequiresMessage()
+ {
+ $this->assertFalse(Response::fromMessage(''));
+ }
+
+ public function testGetBody()
+ {
+ $body = EntityBody::factory('');
+ $response = new Response(403, new Collection(), $body);
+ $this->assertEquals($body, $response->getBody());
+ $response->setBody('foo');
+ $this->assertEquals('foo', $response->getBody(true));
+ }
+
+ public function testManagesStatusCode()
+ {
+ $response = new Response(403);
+ $this->assertEquals(403, $response->getStatusCode());
+ }
+
+ public function testGetMessage()
+ {
+ $response = new Response(200, new Collection(array(
+ 'Content-Length' => 4
+ )), 'body');
+
+ $this->assertEquals("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\nbody", $response->getMessage());
+ }
+
+ public function testGetRawHeaders()
+ {
+ $response = new Response(200, new Collection(array(
+ 'Keep-Alive' => 155,
+ 'User-Agent' => 'Guzzle',
+ 'Content-Length' => 4
+ )), 'body');
+
+ $this->assertEquals("HTTP/1.1 200 OK\r\nKeep-Alive: 155\r\nUser-Agent: Guzzle\r\nContent-Length: 4\r\n\r\n", $response->getRawHeaders());
+ }
+
+ public function testHandlesStatusAndStatusCodes()
+ {
+ $response = new Response(200, new Collection(), 'body');
+ $this->assertEquals('OK', $response->getReasonPhrase());
+
+ $this->assertSame($response, $response->setStatus(204));
+ $this->assertEquals('No Content', $response->getReasonPhrase());
+ $this->assertEquals(204, $response->getStatusCode());
+
+ $this->assertSame($response, $response->setStatus(204, 'Testing!'));
+ $this->assertEquals('Testing!', $response->getReasonPhrase());
+ $this->assertEquals(204, $response->getStatusCode());
+
+ $response->setStatus(2000);
+ $this->assertEquals(2000, $response->getStatusCode());
+ $this->assertEquals('', $response->getReasonPhrase());
+
+ $response->setStatus(200, 'Foo');
+ $this->assertEquals(200, $response->getStatusCode());
+ $this->assertEquals('Foo', $response->getReasonPhrase());
+ }
+
+ public function testIsClientError()
+ {
+ $response = new Response(403);
+ $this->assertTrue($response->isClientError());
+ $response = new Response(200);
+ $this->assertFalse($response->isClientError());
+ }
+
+ public function testIsError()
+ {
+ $response = new Response(403);
+ $this->assertTrue($response->isError());
+ $response = new Response(200);
+ $this->assertFalse($response->isError());
+ $response = new Response(500);
+ $this->assertTrue($response->isError());
+ }
+
+ public function testIsInformational()
+ {
+ $response = new Response(100);
+ $this->assertTrue($response->isInformational());
+ $response = new Response(200);
+ $this->assertFalse($response->isInformational());
+ }
+
+ public function testIsRedirect()
+ {
+ $response = new Response(301);
+ $this->assertTrue($response->isRedirect());
+ $response = new Response(200);
+ $this->assertFalse($response->isRedirect());
+ }
+
+ public function testIsServerError()
+ {
+ $response = new Response(500);
+ $this->assertTrue($response->isServerError());
+ $response = new Response(400);
+ $this->assertFalse($response->isServerError());
+ }
+
+ public function testIsSuccessful()
+ {
+ $response = new Response(200);
+ $this->assertTrue($response->isSuccessful());
+ $response = new Response(403);
+ $this->assertFalse($response->isSuccessful());
+ }
+
+ public function testGetAcceptRanges()
+ {
+ $this->assertEquals('bytes', $this->response->getAcceptRanges());
+ }
+
+ public function testCalculatesAge()
+ {
+ $this->assertEquals(12, $this->response->calculateAge());
+
+ $this->response->removeHeader('Age');
+ $this->response->removeHeader('Date');
+ $this->assertNull($this->response->calculateAge());
+
+ $this->response->setHeader('Date', gmdate(ClientInterface::HTTP_DATE, strtotime('-1 minute')));
+ // If the test runs slowly, still pass with a +5 second allowance
+ $this->assertTrue($this->response->getAge() - 60 <= 5);
+ }
+
+ public function testGetAllow()
+ {
+ $this->assertEquals('GET, HEAD', $this->response->getAllow());
+ }
+
+ public function testGetCacheControl()
+ {
+ $this->assertEquals('no-cache', $this->response->getCacheControl());
+ }
+
+ public function testGetContentEncoding()
+ {
+ $this->assertEquals('gzip', $this->response->getContentEncoding());
+ }
+
+ public function testGetContentLanguage()
+ {
+ $this->assertEquals('da', $this->response->getContentLanguage());
+ }
+
+ public function testGetContentLength()
+ {
+ $this->assertEquals('348', $this->response->getContentLength());
+ }
+
+ public function testGetContentLocation()
+ {
+ $this->assertEquals('/index.htm', $this->response->getContentLocation());
+ }
+
+ public function testGetContentDisposition()
+ {
+ $this->assertEquals('attachment; filename=fname.ext', $this->response->getContentDisposition());
+ }
+
+ public function testGetContentMd5()
+ {
+ $this->assertEquals('Q2hlY2sgSW50ZWdyaXR5IQ==', $this->response->getContentMd5());
+ }
+
+ public function testGetContentRange()
+ {
+ $this->assertEquals('bytes 21010-47021/47022', $this->response->getContentRange());
+ }
+
+ public function testGetContentType()
+ {
+ $this->assertEquals('text/html; charset=utf-8', $this->response->getContentType());
+ }
+
+ public function testGetDate()
+ {
+ $this->assertEquals('Tue, 15 Nov 1994 08:12:31 GMT', $this->response->getDate());
+ }
+
+ public function testGetEtag()
+ {
+ $this->assertEquals('737060cd8c284d8af7ad3082f209582d', $this->response->getEtag());
+ }
+
+ public function testGetExpires()
+ {
+ $this->assertEquals('Thu, 01 Dec 1994 16:00:00 GMT', $this->response->getExpires());
+ }
+
+ public function testGetLastModified()
+ {
+ $this->assertEquals('Tue, 15 Nov 1994 12:45:26 GMT', $this->response->getLastModified());
+ }
+
+ public function testGetLocation()
+ {
+ $this->assertEquals('http://www.w3.org/pub/WWW/People.html', $this->response->getLocation());
+ }
+
+ public function testGetPragma()
+ {
+ $this->assertEquals('no-cache', $this->response->getPragma());
+ }
+
+ public function testGetProxyAuthenticate()
+ {
+ $this->assertEquals('Basic', $this->response->getProxyAuthenticate());
+ }
+
+ public function testGetServer()
+ {
+ $this->assertEquals('Apache/1.3.27 (Unix) (Red-Hat/Linux)', $this->response->getServer());
+ }
+
+ public function testGetSetCookie()
+ {
+ $this->assertEquals('UserID=JohnDoe; Max-Age=3600; Version=1', $this->response->getSetCookie());
+ }
+
+ public function testGetMultipleSetCookie()
+ {
+ $this->response->addHeader('Set-Cookie', 'UserID=Mike; Max-Age=200');
+ $this->assertEquals(array(
+ 'UserID=JohnDoe; Max-Age=3600; Version=1',
+ 'UserID=Mike; Max-Age=200',
+ ), $this->response->getHeader('Set-Cookie')->toArray());
+ }
+
+ public function testGetSetCookieNormalizesHeaders()
+ {
+ $this->response->addHeaders(array(
+ 'Set-Cooke' => 'boo',
+ 'set-cookie' => 'foo'
+ ));
+
+ $this->assertEquals(array(
+ 'UserID=JohnDoe; Max-Age=3600; Version=1',
+ 'foo'
+ ), $this->response->getHeader('Set-Cookie')->toArray());
+
+ $this->response->addHeaders(array(
+ 'set-cookie' => 'fubu'
+ ));
+ $this->assertEquals(
+ array('UserID=JohnDoe; Max-Age=3600; Version=1', 'foo', 'fubu'),
+ $this->response->getHeader('Set-Cookie')->toArray()
+ );
+ }
+
+ public function testGetTrailer()
+ {
+ $this->assertEquals('Max-Forwards', $this->response->getTrailer());
+ }
+
+ public function testGetTransferEncoding()
+ {
+ $this->assertEquals('chunked', $this->response->getTransferEncoding());
+ }
+
+ public function testGetVary()
+ {
+ $this->assertEquals('*', $this->response->getVary());
+ }
+
+ public function testReturnsViaHeader()
+ {
+ $this->assertEquals('1.0 fred, 1.1 nowhere.com (Apache/1.1)', $this->response->getVia());
+ }
+ public function testGetWarning()
+ {
+ $this->assertEquals('199 Miscellaneous warning', $this->response->getWarning());
+ }
+
+ public function testReturnsWwwAuthenticateHeader()
+ {
+ $this->assertEquals('Basic', $this->response->getWwwAuthenticate());
+ }
+
+ public function testReturnsConnectionHeader()
+ {
+ $this->assertEquals(null, $this->response->getConnection());
+ $this->response->setHeader('Connection', 'close');
+ $this->assertEquals('close', $this->response->getConnection());
+ }
+
+ public function testReturnsHeaders()
+ {
+ $this->assertEquals('Basic', $this->response->getHeader('WWW-Authenticate', null, true));
+ $this->assertEquals('chunked', $this->response->getHeader('Transfer-Encoding', null, false));
+ }
+
+ public function testHasTransferInfo()
+ {
+ $stats = array (
+ 'url' => 'http://www.google.com/',
+ 'content_type' => 'text/html; charset=ISO-8859-1',
+ 'http_code' => 200,
+ 'header_size' => 606,
+ 'request_size' => 53,
+ 'filetime' => -1,
+ 'ssl_verify_result' => 0,
+ 'redirect_count' => 0,
+ 'total_time' => 0.093284,
+ 'namelookup_time' => 0.001349,
+ 'connect_time' => 0.01635,
+ 'pretransfer_time' => 0.016358,
+ 'size_upload' => 0,
+ 'size_download' => 10330,
+ 'speed_download' => 110737,
+ 'speed_upload' => 0,
+ 'download_content_length' => -1,
+ 'upload_content_length' => 0,
+ 'starttransfer_time' => 0.07066,
+ 'redirect_time' => 0,
+ );
+
+ // Uninitialized state
+ $this->assertNull($this->response->getInfo('url'));
+ $this->assertEquals(array(), $this->response->getInfo());
+
+ // Set the stats
+ $this->response->setInfo($stats);
+ $this->assertEquals($stats, $this->response->getInfo());
+ $this->assertEquals(606, $this->response->getInfo('header_size'));
+ $this->assertNull($this->response->getInfo('does_not_exist'));
+ }
+
+ /**
+ * @return Response
+ */
+ private function getResponse($code, array $headers = null, EntityBody $body = null)
+ {
+ return new Response($code, $headers, $body);
+ }
+
+ public function testDeterminesIfItCanBeCached()
+ {
+ $this->assertTrue($this->getResponse(200)->canCache());
+ $this->assertTrue($this->getResponse(410)->canCache());
+ $this->assertFalse($this->getResponse(404)->canCache());
+ $this->assertTrue($this->getResponse(200, array(
+ 'Cache-Control' => 'public'
+ ))->canCache());
+
+ // This has the no-store directive
+ $this->assertFalse($this->getResponse(200, array(
+ 'Cache-Control' => 'private, no-store'
+ ))->canCache());
+
+ // The body cannot be read, so it cannot be cached
+ $tmp = tempnam('/tmp', 'not-readable');
+ $resource = fopen($tmp, 'w');
+ $this->assertFalse($this->getResponse(200, array(
+ 'Transfer-Encoding' => 'chunked'
+ ), EntityBody::factory($resource, 10))->canCache());
+ unlink($tmp);
+
+ // The body is 0 length, cannot be read, so it can be cached
+ $tmp = tempnam('/tmp', 'not-readable');
+ $resource = fopen($tmp, 'w');
+ $this->assertTrue($this->getResponse(200, array(array(
+ 'Content-Length' => 0
+ )), EntityBody::factory($resource, 0))->canCache());
+ unlink($tmp);
+ }
+
+ public function testDeterminesResponseMaxAge()
+ {
+ $this->assertEquals(null, $this->getResponse(200)->getMaxAge());
+
+ // Uses the response's s-maxage
+ $this->assertEquals(140, $this->getResponse(200, array(
+ 'Cache-Control' => 's-maxage=140'
+ ))->getMaxAge());
+
+ // Uses the response's max-age
+ $this->assertEquals(120, $this->getResponse(200, array(
+ 'Cache-Control' => 'max-age=120'
+ ))->getMaxAge());
+
+ // Uses the response's max-age
+ $this->assertEquals(120, $this->getResponse(200, array(
+ 'Cache-Control' => 'max-age=120',
+ 'Expires' => gmdate(ClientInterface::HTTP_DATE, strtotime('+1 day'))
+ ))->getMaxAge());
+
+ // Uses the Expires date
+ $this->assertGreaterThanOrEqual(82400, $this->getResponse(200, array(
+ 'Expires' => gmdate(ClientInterface::HTTP_DATE, strtotime('+1 day'))
+ ))->getMaxAge());
+
+ // Uses the Expires date
+ $this->assertGreaterThanOrEqual(82400, $this->getResponse(200, array(
+ 'Expires' => gmdate(ClientInterface::HTTP_DATE, strtotime('+1 day'))
+ ))->getMaxAge());
+ }
+
+ public function testDeterminesIfItCanValidate()
+ {
+ $response = new Response(200);
+ $this->assertFalse($response->canValidate());
+ $response->setHeader('ETag', '123');
+ $this->assertTrue($response->canValidate());
+ $response->removeHeader('ETag');
+ $this->assertFalse($response->canValidate());
+ $response->setHeader('Last-Modified', '123');
+ $this->assertTrue($response->canValidate());
+ }
+
+ public function testCalculatesFreshness()
+ {
+ $response = new Response(200);
+ $this->assertNull($response->isFresh());
+ $this->assertNull($response->getFreshness());
+
+ $response->setHeader('Cache-Control', 'max-age=120');
+ $response->setHeader('Age', 100);
+ $this->assertEquals(20, $response->getFreshness());
+ $this->assertTrue($response->isFresh());
+
+ $response->setHeader('Age', 120);
+ $this->assertEquals(0, $response->getFreshness());
+ $this->assertTrue($response->isFresh());
+
+ $response->setHeader('Age', 150);
+ $this->assertEquals(-30, $response->getFreshness());
+ $this->assertFalse($response->isFresh());
+ }
+
+ public function testHandlesProtocols()
+ {
+ $this->assertSame($this->response, $this->response->setProtocol('HTTP', '1.0'));
+ $this->assertEquals('HTTP', $this->response->getProtocol());
+ $this->assertEquals('1.0', $this->response->getProtocolVersion());
+ }
+
+ public function testComparesContentType()
+ {
+ $response = new Response(200, array(
+ 'Content-Type' => 'text/html; charset=ISO-8859-4'
+ ));
+
+ $this->assertTrue($response->isContentType('text/html'));
+ $this->assertTrue($response->isContentType('TExT/html'));
+ $this->assertTrue($response->isContentType('charset=ISO-8859-4'));
+ $this->assertFalse($response->isContentType('application/xml'));
+ }
+
+ public function testResponseDeterminesIfMethodIsAllowedBaseOnAllowHeader()
+ {
+ $response = new Response(200, array(
+ 'Allow' => 'OPTIONS, POST, deletE,GET'
+ ));
+
+ $this->assertTrue($response->isMethodAllowed('get'));
+ $this->assertTrue($response->isMethodAllowed('GET'));
+ $this->assertTrue($response->isMethodAllowed('options'));
+ $this->assertTrue($response->isMethodAllowed('post'));
+ $this->assertTrue($response->isMethodAllowed('Delete'));
+ $this->assertFalse($response->isMethodAllowed('put'));
+ $this->assertFalse($response->isMethodAllowed('PUT'));
+
+ $response = new Response(200);
+ $this->assertFalse($response->isMethodAllowed('get'));
+ }
+
+ public function testParsesJsonResponses()
+ {
+ $response = new Response(200, array(), '{"foo": "bar"}');
+ $this->assertEquals(array('foo' => 'bar'), $response->json());
+ // Return array when null is a service response
+ $response = new Response(200);
+ $this->assertEquals(array(), $response->json());
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\RuntimeException
+ * @expectedExceptionMessage Unable to parse response body into JSON: 4
+ */
+ public function testThrowsExceptionWhenFailsToParseJsonResponse()
+ {
+ $response = new Response(200, array(), '{"foo": "');
+ $response->json();
+ }
+
+ public function testParsesXmlResponses()
+ {
+ $response = new Response(200, array(), '<abc><foo>bar</foo></abc>');
+ $this->assertEquals('bar', (string) $response->xml()->foo);
+ // Always return a SimpleXMLElement from the xml method
+ $response = new Response(200);
+ $this->assertEmpty((string) $response->xml()->foo);
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\RuntimeException
+ * @expectedExceptionMessage Unable to parse response body into XML: String could not be parsed as XML
+ */
+ public function testThrowsExceptionWhenFailsToParseXmlResponse()
+ {
+ $response = new Response(200, array(), '<abc');
+ $response->xml();
+ }
+
+ public function testResponseIsSerializable()
+ {
+ $response = new Response(200, array('Foo' => 'bar'), 'test');
+ $r = unserialize(serialize($response));
+ $this->assertEquals(200, $r->getStatusCode());
+ $this->assertEquals('bar', (string) $r->getHeader('Foo'));
+ $this->assertEquals('test', (string) $r->getBody());
+ }
+
+ public function testPreventsComplexExternalEntities()
+ {
+ $xml = '<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=ResponseTest.php">]><scan>&test;</scan>';
+ $response = new Response(200, array(), $xml);
+
+ $oldCwd = getcwd();
+ chdir(__DIR__);
+ try {
+ $xml = $response->xml();
+ chdir($oldCwd);
+ $this->markTestIncomplete('Did not throw the expected exception! XML resolved as: ' . $xml->asXML());
+ } catch (\Exception $e) {
+ chdir($oldCwd);
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/MimetypesTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/MimetypesTest.php
new file mode 100644
index 0000000..7228453
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/MimetypesTest.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\Mimetypes;
+
+/**
+ * @covers Guzzle\Http\Mimetypes
+ */
+class MimetypesTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testGetsFromExtension()
+ {
+ $this->assertEquals('text/x-php', Mimetypes::getInstance()->fromExtension('php'));
+ }
+
+ public function testGetsFromFilename()
+ {
+ $this->assertEquals('text/x-php', Mimetypes::getInstance()->fromFilename(__FILE__));
+ }
+
+ public function testGetsFromCaseInsensitiveFilename()
+ {
+ $this->assertEquals('text/x-php', Mimetypes::getInstance()->fromFilename(strtoupper(__FILE__)));
+ }
+
+ public function testReturnsNullWhenNoMatchFound()
+ {
+ $this->assertNull(Mimetypes::getInstance()->fromExtension('foobar'));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/CommaAggregatorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/CommaAggregatorTest.php
new file mode 100644
index 0000000..549d3ed
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/CommaAggregatorTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\QueryString;
+use Guzzle\Http\QueryAggregator\CommaAggregator as Ag;
+
+class CommaAggregatorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testAggregates()
+ {
+ $query = new QueryString();
+ $a = new Ag();
+ $key = 'test 123';
+ $value = array('foo 123', 'baz', 'bar');
+ $result = $a->aggregate($key, $value, $query);
+ $this->assertEquals(array('test%20123' => 'foo%20123,baz,bar'), $result);
+ }
+
+ public function testEncodes()
+ {
+ $query = new QueryString();
+ $query->useUrlEncoding(false);
+ $a = new Ag();
+ $key = 'test 123';
+ $value = array('foo 123', 'baz', 'bar');
+ $result = $a->aggregate($key, $value, $query);
+ $this->assertEquals(array('test 123' => 'foo 123,baz,bar'), $result);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/DuplicateAggregatorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/DuplicateAggregatorTest.php
new file mode 100644
index 0000000..6a4d9d9
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/DuplicateAggregatorTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\QueryString;
+use Guzzle\Http\QueryAggregator\DuplicateAggregator as Ag;
+
+class DuplicateAggregatorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testAggregates()
+ {
+ $query = new QueryString();
+ $a = new Ag();
+ $key = 'facet 1';
+ $value = array('size a', 'width b');
+ $result = $a->aggregate($key, $value, $query);
+ $this->assertEquals(array('facet%201' => array('size%20a', 'width%20b')), $result);
+ }
+
+ public function testEncodes()
+ {
+ $query = new QueryString();
+ $query->useUrlEncoding(false);
+ $a = new Ag();
+ $key = 'facet 1';
+ $value = array('size a', 'width b');
+ $result = $a->aggregate($key, $value, $query);
+ $this->assertEquals(array('facet 1' => array('size a', 'width b')), $result);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/PhpAggregatorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/PhpAggregatorTest.php
new file mode 100644
index 0000000..1e7f0c2
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryAggregator/PhpAggregatorTest.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\QueryString;
+use Guzzle\Http\QueryAggregator\PhpAggregator as Ag;
+
+class PhpAggregatorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testEncodes()
+ {
+ $query = new QueryString();
+ $query->useUrlEncoding(false);
+ $a = new Ag();
+ $key = 't';
+ $value = array(
+ 'v1' => 'a',
+ 'v2' => 'b',
+ 'v3' => array(
+ 'v4' => 'c',
+ 'v5' => 'd',
+ )
+ );
+ $result = $a->aggregate($key, $value, $query);
+ $this->assertEquals(array(
+ 't[v1]' => 'a',
+ 't[v2]' => 'b',
+ 't[v3][v4]' => 'c',
+ 't[v3][v5]' => 'd',
+ ), $result);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryStringTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryStringTest.php
new file mode 100644
index 0000000..948db44
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/QueryStringTest.php
@@ -0,0 +1,233 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\QueryString;
+use Guzzle\Http\QueryAggregator\DuplicateAggregator;
+use Guzzle\Http\QueryAggregator\CommaAggregator;
+
+class QueryStringTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /** @var \Guzzle\Http\QueryString The query string object to test */
+ protected $q;
+
+ public function setup()
+ {
+ $this->q = new QueryString();
+ }
+
+ public function testGetFieldSeparator()
+ {
+ $this->assertEquals('&', $this->q->getFieldSeparator());
+ }
+
+ public function testGetValueSeparator()
+ {
+ $this->assertEquals('=', $this->q->getValueSeparator());
+ }
+
+ public function testIsUrlEncoding()
+ {
+ $this->assertEquals('RFC 3986', $this->q->getUrlEncoding());
+ $this->assertTrue($this->q->isUrlEncoding());
+ $this->assertEquals('foo%20bar', $this->q->encodeValue('foo bar'));
+
+ $this->q->useUrlEncoding(QueryString::FORM_URLENCODED);
+ $this->assertTrue($this->q->isUrlEncoding());
+ $this->assertEquals(QueryString::FORM_URLENCODED, $this->q->getUrlEncoding());
+ $this->assertEquals('foo+bar', $this->q->encodeValue('foo bar'));
+
+ $this->assertSame($this->q, $this->q->useUrlEncoding(false));
+ $this->assertFalse($this->q->isUrlEncoding());
+ $this->assertFalse($this->q->isUrlEncoding());
+ }
+
+ public function testSetFieldSeparator()
+ {
+ $this->assertEquals($this->q, $this->q->setFieldSeparator('/'));
+ $this->assertEquals('/', $this->q->getFieldSeparator());
+ }
+
+ public function testSetValueSeparator()
+ {
+ $this->assertEquals($this->q, $this->q->setValueSeparator('/'));
+ $this->assertEquals('/', $this->q->getValueSeparator());
+ }
+
+ public function testUrlEncode()
+ {
+ $params = array(
+ 'test' => 'value',
+ 'test 2' => 'this is a test?',
+ 'test3' => array('v1', 'v2', 'v3'),
+ 'ሴ' => 'bar'
+ );
+ $encoded = array(
+ 'test' => 'value',
+ 'test%202' => rawurlencode('this is a test?'),
+ 'test3%5B0%5D' => 'v1',
+ 'test3%5B1%5D' => 'v2',
+ 'test3%5B2%5D' => 'v3',
+ '%E1%88%B4' => 'bar'
+ );
+ $this->q->replace($params);
+ $this->assertEquals($encoded, $this->q->urlEncode());
+
+ // Disable encoding
+ $testData = array('test 2' => 'this is a test');
+ $this->q->replace($testData);
+ $this->q->useUrlEncoding(false);
+ $this->assertEquals($testData, $this->q->urlEncode());
+ }
+
+ public function testToString()
+ {
+ // Check with no parameters
+ $this->assertEquals('', $this->q->__toString());
+
+ $params = array(
+ 'test' => 'value',
+ 'test 2' => 'this is a test?',
+ 'test3' => array('v1', 'v2', 'v3'),
+ 'test4' => null,
+ );
+ $this->q->replace($params);
+ $this->assertEquals('test=value&test%202=this%20is%20a%20test%3F&test3%5B0%5D=v1&test3%5B1%5D=v2&test3%5B2%5D=v3&test4', $this->q->__toString());
+ $this->q->useUrlEncoding(false);
+ $this->assertEquals('test=value&test 2=this is a test?&test3[0]=v1&test3[1]=v2&test3[2]=v3&test4', $this->q->__toString());
+
+ // Use an alternative aggregator
+ $this->q->setAggregator(new CommaAggregator());
+ $this->assertEquals('test=value&test 2=this is a test?&test3=v1,v2,v3&test4', $this->q->__toString());
+ }
+
+ public function testAllowsMultipleValuesPerKey()
+ {
+ $q = new QueryString();
+ $q->add('facet', 'size');
+ $q->add('facet', 'width');
+ $q->add('facet.field', 'foo');
+ // Use the duplicate aggregator
+ $q->setAggregator(new DuplicateAggregator());
+ $this->assertEquals('facet=size&facet=width&facet.field=foo', $q->__toString());
+ }
+
+ public function testAllowsNestedQueryData()
+ {
+ $this->q->replace(array(
+ 'test' => 'value',
+ 't' => array(
+ 'v1' => 'a',
+ 'v2' => 'b',
+ 'v3' => array(
+ 'v4' => 'c',
+ 'v5' => 'd',
+ )
+ )
+ ));
+
+ $this->q->useUrlEncoding(false);
+ $this->assertEquals('test=value&t[v1]=a&t[v2]=b&t[v3][v4]=c&t[v3][v5]=d', $this->q->__toString());
+ }
+
+ public function parseQueryProvider()
+ {
+ return array(
+ // Ensure that multiple query string values are allowed per value
+ array('q=a&q=b', array('q' => array('a', 'b'))),
+ // Ensure that PHP array style query string values are parsed
+ array('q[]=a&q[]=b', array('q' => array('a', 'b'))),
+ // Ensure that a single PHP array style query string value is parsed into an array
+ array('q[]=a', array('q' => array('a'))),
+ // Ensure that decimals are allowed in query strings
+ array('q.a=a&q.b=b', array(
+ 'q.a' => 'a',
+ 'q.b' => 'b'
+ )),
+ // Ensure that query string values are percent decoded
+ array('q%20a=a%20b', array('q a' => 'a b')),
+ // Ensure null values can be added
+ array('q&a', array('q' => false, 'a' => false)),
+ );
+ }
+
+ /**
+ * @dataProvider parseQueryProvider
+ */
+ public function testParsesQueryStrings($query, $data)
+ {
+ $query = QueryString::fromString($query);
+ $this->assertEquals($data, $query->getAll());
+ }
+
+ public function testProperlyDealsWithDuplicateQueryStringValues()
+ {
+ $query = QueryString::fromString('foo=a&foo=b&?µ=c');
+ $this->assertEquals(array('a', 'b'), $query->get('foo'));
+ $this->assertEquals('c', $query->get('?µ'));
+ }
+
+ public function testAllowsBlankQueryStringValues()
+ {
+ $query = QueryString::fromString('foo');
+ $this->assertEquals('foo', (string) $query);
+ $query->set('foo', QueryString::BLANK);
+ $this->assertEquals('foo', (string) $query);
+ }
+
+ public function testAllowsFalsyQueryStringValues()
+ {
+ $query = QueryString::fromString('0');
+ $this->assertEquals('0', (string) $query);
+ $query->set('0', QueryString::BLANK);
+ $this->assertSame('0', (string) $query);
+ }
+
+ public function testFromStringIgnoresQuestionMark()
+ {
+ $query = QueryString::fromString('foo=baz&bar=boo');
+ $this->assertEquals('foo=baz&bar=boo', (string) $query);
+ }
+
+ public function testConvertsPlusSymbolsToSpaces()
+ {
+ $query = QueryString::fromString('var=foo+bar');
+ $this->assertEquals('foo bar', $query->get('var'));
+ }
+
+ public function testFromStringDoesntMangleZeroes()
+ {
+ $query = QueryString::fromString('var=0');
+ $this->assertSame('0', $query->get('var'));
+ }
+
+ public function testAllowsZeroValues()
+ {
+ $query = new QueryString(array(
+ 'foo' => 0,
+ 'baz' => '0',
+ 'bar' => null,
+ 'boo' => false,
+ 'bam' => ''
+ ));
+ $this->assertEquals('foo=0&baz=0&bar&boo&bam=', (string) $query);
+ }
+
+ public function testFromStringDoesntStripTrailingEquals()
+ {
+ $query = QueryString::fromString('data=mF0b3IiLCJUZWFtIERldiJdfX0=');
+ $this->assertEquals('mF0b3IiLCJUZWFtIERldiJdfX0=', $query->get('data'));
+ }
+
+ public function testGuessesIfDuplicateAggregatorShouldBeUsed()
+ {
+ $query = QueryString::fromString('test=a&test=b');
+ $this->assertEquals('test=a&test=b', (string) $query);
+ }
+
+ public function testGuessesIfDuplicateAggregatorShouldBeUsedAndChecksForPhpStyle()
+ {
+ $query = QueryString::fromString('test[]=a&test[]=b');
+ $this->assertEquals('test%5B0%5D=a&test%5B1%5D=b', (string) $query);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/ReadLimitEntityBodyTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/ReadLimitEntityBodyTest.php
new file mode 100644
index 0000000..6bb3fed
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/ReadLimitEntityBodyTest.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\ReadLimitEntityBody;
+
+/**
+ * @covers Guzzle\Http\ReadLimitEntityBody
+ */
+class ReadLimitEntityBodyTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /** @var ReadLimitEntityBody */
+ protected $body;
+
+ /** @var EntityBody */
+ protected $decorated;
+
+ public function setUp()
+ {
+ $this->decorated = EntityBody::factory(fopen(__FILE__, 'r'));
+ $this->body = new ReadLimitEntityBody($this->decorated, 10, 3);
+ }
+
+ public function testReturnsSubsetWhenCastToString()
+ {
+ $body = EntityBody::factory('foo_baz_bar');
+ $limited = new ReadLimitEntityBody($body, 3, 4);
+ $this->assertEquals('baz', (string) $limited);
+ }
+
+ public function testReturnsSubsetOfEmptyBodyWhenCastToString()
+ {
+ $body = EntityBody::factory('');
+ $limited = new ReadLimitEntityBody($body, 0, 10);
+ $this->assertEquals('', (string) $limited);
+ }
+
+ public function testSeeksWhenConstructed()
+ {
+ $this->assertEquals(3, $this->body->ftell());
+ }
+
+ public function testAllowsBoundedSeek()
+ {
+ $this->body->seek(100);
+ $this->assertEquals(13, $this->body->ftell());
+ $this->body->seek(0);
+ $this->assertEquals(3, $this->body->ftell());
+ $this->assertEquals(false, $this->body->seek(1000, SEEK_END));
+ }
+
+ public function testReadsOnlySubsetOfData()
+ {
+ $data = $this->body->read(100);
+ $this->assertEquals(10, strlen($data));
+ $this->assertFalse($this->body->read(1000));
+
+ $this->body->setOffset(10);
+ $newData = $this->body->read(100);
+ $this->assertEquals(10, strlen($newData));
+ $this->assertNotSame($data, $newData);
+ }
+
+ public function testClaimsConsumedWhenReadLimitIsReached()
+ {
+ $this->assertFalse($this->body->isConsumed());
+ $this->body->read(1000);
+ $this->assertTrue($this->body->isConsumed());
+ }
+
+ public function testContentLengthIsBounded()
+ {
+ $this->assertEquals(10, $this->body->getContentLength());
+ }
+
+ public function testContentMd5IsBasedOnSubsection()
+ {
+ $this->assertNotSame($this->body->getContentMd5(), $this->decorated->getContentMd5());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php
new file mode 100755
index 0000000..886236d
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php
@@ -0,0 +1,277 @@
+<?php
+
+namespace Guzzle\Tests\Plugin\Redirect;
+
+use Guzzle\Http\Client;
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\RedirectPlugin;
+use Guzzle\Http\Exception\TooManyRedirectsException;
+use Guzzle\Plugin\History\HistoryPlugin;
+
+/**
+ * @covers Guzzle\Http\RedirectPlugin
+ */
+class RedirectPluginTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testRedirectsRequests()
+ {
+ // Flush the server and queue up a redirect followed by a successful response
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "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",
+ ));
+
+ // Create a client that uses the default redirect behavior
+ $client = new Client($this->getServer()->getUrl());
+ $history = new HistoryPlugin();
+ $client->addSubscriber($history);
+
+ $request = $client->get('/foo');
+ $response = $request->send();
+ $this->assertEquals(200, $response->getStatusCode());
+ $this->assertContains('/redirect2', $response->getEffectiveUrl());
+
+ // Ensure that two requests were sent
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('/foo', $requests[0]->getResource());
+ $this->assertEquals('GET', $requests[0]->getMethod());
+ $this->assertEquals('/redirect1', $requests[1]->getResource());
+ $this->assertEquals('GET', $requests[1]->getMethod());
+ $this->assertEquals('/redirect2', $requests[2]->getResource());
+ $this->assertEquals('GET', $requests[2]->getMethod());
+
+ // Ensure that the redirect count was incremented
+ $this->assertEquals(2, $request->getParams()->get(RedirectPlugin::REDIRECT_COUNT));
+ $this->assertCount(3, $history);
+ $requestHistory = $history->getAll();
+
+ $this->assertEquals(301, $requestHistory[0]['response']->getStatusCode());
+ $this->assertEquals('/redirect1', (string) $requestHistory[0]['response']->getHeader('Location'));
+ $this->assertEquals(301, $requestHistory[1]['response']->getStatusCode());
+ $this->assertEquals('/redirect2', (string) $requestHistory[1]['response']->getHeader('Location'));
+ $this->assertEquals(200, $requestHistory[2]['response']->getStatusCode());
+ }
+
+ public function testCanLimitNumberOfRedirects()
+ {
+ // Flush the server and queue up a redirect followed by a successful response
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "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 301 Moved Permanently\r\nLocation: /redirect3\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect4\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect5\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect6\r\nContent-Length: 0\r\n\r\n"
+ ));
+
+ try {
+ $client = new Client($this->getServer()->getUrl());
+ $client->get('/foo')->send();
+ $this->fail('Did not throw expected exception');
+ } catch (TooManyRedirectsException $e) {
+ $this->assertContains(
+ "5 redirects were issued for this request:\nGET /foo HTTP/1.1\r\n",
+ $e->getMessage()
+ );
+ }
+ }
+
+ public function testDefaultBehaviorIsToRedirectWithGetForEntityEnclosingRequests()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ ));
+
+ $client = new Client($this->getServer()->getUrl());
+ $client->post('/foo', array('X-Baz' => 'bar'), 'testing')->send();
+
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('POST', $requests[0]->getMethod());
+ $this->assertEquals('GET', $requests[1]->getMethod());
+ $this->assertEquals('bar', (string) $requests[1]->getHeader('X-Baz'));
+ $this->assertEquals('GET', $requests[2]->getMethod());
+ }
+
+ public function testCanRedirectWithStrictRfcCompliance()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ ));
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->post('/foo', array('X-Baz' => 'bar'), 'testing');
+ $request->getParams()->set(RedirectPlugin::STRICT_REDIRECTS, true);
+ $request->send();
+
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('POST', $requests[0]->getMethod());
+ $this->assertEquals('POST', $requests[1]->getMethod());
+ $this->assertEquals('bar', (string) $requests[1]->getHeader('X-Baz'));
+ $this->assertEquals('POST', $requests[2]->getMethod());
+ }
+
+ public function testRedirect303WithGet()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 303 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ ));
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->post('/foo');
+ $request->send();
+
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('POST', $requests[0]->getMethod());
+ $this->assertEquals('GET', $requests[1]->getMethod());
+ }
+
+ public function testRedirect303WithGetWithStrictRfcCompliance()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 303 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ ));
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->post('/foo');
+ $request->getParams()->set(RedirectPlugin::STRICT_REDIRECTS, true);
+ $request->send();
+
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('POST', $requests[0]->getMethod());
+ $this->assertEquals('GET', $requests[1]->getMethod());
+ }
+
+ public function testRewindsStreamWhenRedirectingIfNeeded()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ ));
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put();
+ $request->configureRedirects(true);
+ $body = EntityBody::factory('foo');
+ $body->read(1);
+ $request->setBody($body);
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('foo', (string) $requests[0]->getBody());
+ }
+
+ /**
+ * @expectedException \Guzzle\Http\Exception\CouldNotRewindStreamException
+ */
+ public function testThrowsExceptionWhenStreamCannotBeRewound()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi",
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n"
+ ));
+
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put();
+ $request->configureRedirects(true);
+ $body = EntityBody::factory(fopen($this->getServer()->getUrl(), 'r'));
+ $body->read(1);
+ $request->setBody($body)->send();
+ }
+
+ public function testRedirectsCanBeDisabledPerRequest()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array("HTTP/1.1 301 Foo\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n"));
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->put();
+ $request->configureRedirects(false, 0);
+ $this->assertEquals(301, $request->send()->getStatusCode());
+ }
+
+ public function testCanRedirectWithNoLeadingSlashAndQuery()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: redirect?foo=bar\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get('?foo=bar');
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals($this->getServer()->getUrl() . '?foo=bar', $requests[0]->getUrl());
+ $this->assertEquals($this->getServer()->getUrl() . 'redirect?foo=bar', $requests[1]->getUrl());
+ // Ensure that the history on the actual request is correct
+ $this->assertEquals($this->getServer()->getUrl() . '?foo=bar', $request->getUrl());
+ }
+
+ public function testRedirectWithStrictRfc386Compliance()
+ {
+ // Flush the server and queue up a redirect followed by a successful response
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: redirect\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get('/foo');
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('/redirect', $requests[1]->getResource());
+ }
+
+ public function testResetsHistoryEachSend()
+ {
+ // Flush the server and queue up a redirect followed by a successful response
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "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",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
+ ));
+
+ // Create a client that uses the default redirect behavior
+ $client = new Client($this->getServer()->getUrl());
+ $history = new HistoryPlugin();
+ $client->addSubscriber($history);
+
+ $request = $client->get('/foo');
+ $response = $request->send();
+ $this->assertEquals(3, count($history));
+ $this->assertTrue($request->getParams()->hasKey('redirect.count'));
+ $this->assertContains('/redirect2', $response->getEffectiveUrl());
+
+ $request->send();
+ $this->assertFalse($request->getParams()->hasKey('redirect.count'));
+ }
+
+ public function testHandlesRedirectsWithSpacesProperly()
+ {
+ // Flush the server and queue up a redirect followed by a successful response
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect 1\r\nContent-Length: 0\r\n\r\n",
+ "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
+ ));
+ $client = new Client($this->getServer()->getUrl());
+ $request = $client->get('/foo');
+ $request->send();
+ $reqs = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals('/redirect%201', $reqs[1]->getResource());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Server.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Server.php
new file mode 100644
index 0000000..94eb59a
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/Server.php
@@ -0,0 +1,191 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\Exception\BadResponseException;
+use Guzzle\Common\Exception\RuntimeException;
+use Guzzle\Http\Message\Request;
+use Guzzle\Http\Message\Response;
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Http\Message\RequestFactory;
+use Guzzle\Http\Client;
+
+/**
+ * The Server class is used to control a scripted webserver using node.js that
+ * will respond to HTTP requests with queued responses.
+ *
+ * Queued responses will be served to requests using a FIFO order. All requests
+ * received by the server are stored on the node.js server and can be retrieved
+ * by calling {@see Server::getReceivedRequests()}.
+ *
+ * Mock responses that don't require data to be transmitted over HTTP a great
+ * for testing. Mock response, however, cannot test the actual sending of an
+ * HTTP request using cURL. This test server allows the simulation of any
+ * number of HTTP request response transactions to test the actual sending of
+ * requests over the wire without having to leave an internal network.
+ */
+class Server
+{
+ const DEFAULT_PORT = 8124;
+ const REQUEST_DELIMITER = "\n----[request]\n";
+
+ /** @var int Port that the server will listen on */
+ private $port;
+
+ /** @var bool Is the server running */
+ private $running = false;
+
+ /** @var Client */
+ private $client;
+
+ /**
+ * Create a new scripted server
+ *
+ * @param int $port Port to listen on (defaults to 8124)
+ */
+ public function __construct($port = null)
+ {
+ $this->port = $port ?: self::DEFAULT_PORT;
+ $this->client = new Client($this->getUrl());
+ register_shutdown_function(array($this, 'stop'));
+ }
+
+ /**
+ * Flush the received requests from the server
+ * @throws RuntimeException
+ */
+ public function flush()
+ {
+ $this->client->delete('guzzle-server/requests')->send();
+ }
+
+ /**
+ * Queue an array of responses or a single response on the server.
+ *
+ * Any currently queued responses will be overwritten. Subsequent requests
+ * on the server will return queued responses in FIFO order.
+ *
+ * @param array|Response $responses A single or array of Responses to queue
+ * @throws BadResponseException
+ */
+ public function enqueue($responses)
+ {
+ $data = array();
+ foreach ((array) $responses as $response) {
+
+ // Create the response object from a string
+ if (is_string($response)) {
+ $response = Response::fromMessage($response);
+ } elseif (!($response instanceof Response)) {
+ throw new BadResponseException('Responses must be strings or implement Response');
+ }
+
+ $data[] = array(
+ 'statusCode' => $response->getStatusCode(),
+ 'reasonPhrase' => $response->getReasonPhrase(),
+ 'headers' => $response->getHeaders()->toArray(),
+ 'body' => $response->getBody(true)
+ );
+ }
+
+ $request = $this->client->put('guzzle-server/responses', null, json_encode($data));
+ $request->send();
+ }
+
+ /**
+ * Check if the server is running
+ *
+ * @return bool
+ */
+ public function isRunning()
+ {
+ if ($this->running) {
+ return true;
+ }
+
+ try {
+ $this->client->get('guzzle-server/perf', array(), array('timeout' => 5))->send();
+ $this->running = true;
+ return true;
+ } catch (\Exception $e) {
+ return false;
+ }
+ }
+
+ /**
+ * Get the URL to the server
+ *
+ * @return string
+ */
+ public function getUrl()
+ {
+ return 'http://127.0.0.1:' . $this->getPort() . '/';
+ }
+
+ /**
+ * Get the port that the server is listening on
+ *
+ * @return int
+ */
+ public function getPort()
+ {
+ return $this->port;
+ }
+
+ /**
+ * Get all of the received requests
+ *
+ * @param bool $hydrate Set to TRUE to turn the messages into
+ * actual {@see RequestInterface} objects. If $hydrate is FALSE,
+ * requests will be returned as strings.
+ *
+ * @return array
+ * @throws RuntimeException
+ */
+ public function getReceivedRequests($hydrate = false)
+ {
+ $response = $this->client->get('guzzle-server/requests')->send();
+ $data = array_filter(explode(self::REQUEST_DELIMITER, $response->getBody(true)));
+ if ($hydrate) {
+ $data = array_map(function($message) {
+ return RequestFactory::getInstance()->fromMessage($message);
+ }, $data);
+ }
+
+ return $data;
+ }
+
+ /**
+ * Start running the node.js server in the background
+ */
+ public function start()
+ {
+ if (!$this->isRunning()) {
+ exec('node ' . __DIR__ . \DIRECTORY_SEPARATOR
+ . 'server.js ' . $this->port
+ . ' >> /tmp/server.log 2>&1 &');
+ // Wait at most 5 seconds for the server the setup before
+ // proceeding.
+ $start = time();
+ while (!$this->isRunning() && time() - $start < 5);
+ if (!$this->running) {
+ throw new RuntimeException(
+ 'Unable to contact server.js. Have you installed node.js v0.5.0+? node must be in your path.'
+ );
+ }
+ }
+ }
+
+ /**
+ * Stop running the node.js server
+ */
+ public function stop()
+ {
+ if (!$this->isRunning()) {
+ return false;
+ }
+
+ $this->running = false;
+ $this->client->delete('guzzle-server')->send();
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/StaticClientTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/StaticClientTest.php
new file mode 100644
index 0000000..091314b
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/StaticClientTest.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Guzzle\Tests\Plugin\Redirect;
+
+use Guzzle\Http\Client;
+use Guzzle\Http\StaticClient;
+use Guzzle\Plugin\Mock\MockPlugin;
+use Guzzle\Http\Message\Response;
+use Guzzle\Stream\Stream;
+
+/**
+ * @covers Guzzle\Http\StaticClient
+ */
+class StaticClientTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testMountsClient()
+ {
+ $client = new Client();
+ StaticClient::mount('FooBazBar', $client);
+ $this->assertTrue(class_exists('FooBazBar'));
+ $this->assertSame($client, $this->readAttribute('Guzzle\Http\StaticClient', 'client'));
+ }
+
+ public function requestProvider()
+ {
+ return array_map(
+ function ($m) { return array($m); },
+ array('GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS')
+ );
+ }
+
+ /**
+ * @dataProvider requestProvider
+ */
+ public function testSendsRequests($method)
+ {
+ $mock = new MockPlugin(array(new Response(200)));
+ call_user_func('Guzzle\Http\StaticClient::' . $method, 'http://foo.com', array(
+ 'plugins' => array($mock)
+ ));
+ $requests = $mock->getReceivedRequests();
+ $this->assertCount(1, $requests);
+ $this->assertEquals($method, $requests[0]->getMethod());
+ }
+
+ public function testCanCreateStreamsUsingDefaultFactory()
+ {
+ $this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest"));
+ $stream = StaticClient::get($this->getServer()->getUrl(), array('stream' => true));
+ $this->assertInstanceOf('Guzzle\Stream\StreamInterface', $stream);
+ $this->assertEquals('test', (string) $stream);
+ }
+
+ public function testCanCreateStreamsUsingCustomFactory()
+ {
+ $stream = $this->getMockBuilder('Guzzle\Stream\StreamRequestFactoryInterface')
+ ->setMethods(array('fromRequest'))
+ ->getMockForAbstractClass();
+ $resource = new Stream(fopen('php://temp', 'r+'));
+ $stream->expects($this->once())
+ ->method('fromRequest')
+ ->will($this->returnValue($resource));
+ $this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest"));
+ $result = StaticClient::get($this->getServer()->getUrl(), array('stream' => $stream));
+ $this->assertSame($resource, $result);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/UrlTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/UrlTest.php
new file mode 100644
index 0000000..28f2671
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/UrlTest.php
@@ -0,0 +1,303 @@
+<?php
+
+namespace Guzzle\Tests\Http;
+
+use Guzzle\Http\QueryString;
+use Guzzle\Http\Url;
+
+/**
+ * @covers Guzzle\Http\Url
+ */
+class UrlTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testEmptyUrl()
+ {
+ $url = Url::factory('');
+ $this->assertEquals('', (string) $url);
+ }
+
+ public function testPortIsDeterminedFromScheme()
+ {
+ $this->assertEquals(80, Url::factory('http://www.test.com/')->getPort());
+ $this->assertEquals(443, Url::factory('https://www.test.com/')->getPort());
+ $this->assertEquals(null, Url::factory('ftp://www.test.com/')->getPort());
+ $this->assertEquals(8192, Url::factory('http://www.test.com:8192/')->getPort());
+ }
+
+ public function testCloneCreatesNewInternalObjects()
+ {
+ $u1 = Url::factory('http://www.test.com/');
+ $u2 = clone $u1;
+ $this->assertNotSame($u1->getQuery(), $u2->getQuery());
+ }
+
+ public function testValidatesUrlPartsInFactory()
+ {
+ $url = Url::factory('/index.php');
+ $this->assertEquals('/index.php', (string) $url);
+ $this->assertFalse($url->isAbsolute());
+
+ $url = 'http://michael:test@test.com:80/path/123?q=abc#test';
+ $u = Url::factory($url);
+ $this->assertEquals('http://michael:test@test.com/path/123?q=abc#test', (string) $u);
+ $this->assertTrue($u->isAbsolute());
+ }
+
+ public function testAllowsFalsyUrlParts()
+ {
+ $url = Url::factory('http://0:50/0?0#0');
+ $this->assertSame('0', $url->getHost());
+ $this->assertEquals(50, $url->getPort());
+ $this->assertSame('/0', $url->getPath());
+ $this->assertEquals('0', (string) $url->getQuery());
+ $this->assertSame('0', $url->getFragment());
+ $this->assertEquals('http://0:50/0?0#0', (string) $url);
+
+ $url = Url::factory('');
+ $this->assertSame('', (string) $url);
+
+ $url = Url::factory('0');
+ $this->assertSame('0', (string) $url);
+ }
+
+ public function testBuildsRelativeUrlsWithFalsyParts()
+ {
+ $url = Url::buildUrl(array(
+ 'host' => '0',
+ 'path' => '0',
+ ));
+
+ $this->assertSame('//0/0', $url);
+
+ $url = Url::buildUrl(array(
+ 'path' => '0',
+ ));
+ $this->assertSame('0', $url);
+ }
+
+ public function testUrlStoresParts()
+ {
+ $url = Url::factory('http://test:pass@www.test.com:8081/path/path2/?a=1&b=2#fragment');
+ $this->assertEquals('http', $url->getScheme());
+ $this->assertEquals('test', $url->getUsername());
+ $this->assertEquals('pass', $url->getPassword());
+ $this->assertEquals('www.test.com', $url->getHost());
+ $this->assertEquals(8081, $url->getPort());
+ $this->assertEquals('/path/path2/', $url->getPath());
+ $this->assertEquals('fragment', $url->getFragment());
+ $this->assertEquals('a=1&b=2', (string) $url->getQuery());
+
+ $this->assertEquals(array(
+ 'fragment' => 'fragment',
+ 'host' => 'www.test.com',
+ 'pass' => 'pass',
+ 'path' => '/path/path2/',
+ 'port' => 8081,
+ 'query' => 'a=1&b=2',
+ 'scheme' => 'http',
+ 'user' => 'test'
+ ), $url->getParts());
+ }
+
+ public function testHandlesPathsCorrectly()
+ {
+ $url = Url::factory('http://www.test.com');
+ $this->assertEquals('', $url->getPath());
+ $url->setPath('test');
+ $this->assertEquals('test', $url->getPath());
+
+ $url->setPath('/test/123/abc');
+ $this->assertEquals(array('test', '123', 'abc'), $url->getPathSegments());
+
+ $parts = parse_url('http://www.test.com/test');
+ $parts['path'] = '';
+ $this->assertEquals('http://www.test.com', Url::buildUrl($parts));
+ $parts['path'] = 'test';
+ $this->assertEquals('http://www.test.com/test', Url::buildUrl($parts));
+ }
+
+ public function testAddsQueryStringIfPresent()
+ {
+ $this->assertEquals('?foo=bar', Url::buildUrl(array(
+ 'query' => 'foo=bar'
+ )));
+ }
+
+ public function testAddsToPath()
+ {
+ // Does nothing here
+ $this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(false));
+ $this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(null));
+ $this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(array()));
+ $this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(new \stdClass()));
+ $this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath(''));
+ $this->assertEquals('http://e.com/base?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath('/'));
+ $this->assertEquals('http://e.com/baz/foo', (string) Url::factory('http://e.com/baz/')->addPath('foo'));
+ $this->assertEquals('http://e.com/base/relative?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath('relative'));
+ $this->assertEquals('http://e.com/base/relative?a=1', (string) Url::factory('http://e.com/base?a=1')->addPath('/relative'));
+ $this->assertEquals('http://e.com/base/0', (string) Url::factory('http://e.com/base')->addPath('0'));
+ $this->assertEquals('http://e.com/base/0/1', (string) Url::factory('http://e.com/base')->addPath('0')->addPath('1'));
+ }
+
+ /**
+ * URL combination data provider
+ *
+ * @return array
+ */
+ public function urlCombineDataProvider()
+ {
+ return array(
+ array('http://www.example.com/', 'http://www.example.com/', 'http://www.example.com/'),
+ array('http://www.example.com/path', '/absolute', 'http://www.example.com/absolute'),
+ array('http://www.example.com/path', '/absolute?q=2', 'http://www.example.com/absolute?q=2'),
+ array('http://www.example.com/path', 'more', 'http://www.example.com/path/more'),
+ array('http://www.example.com/path', 'more?q=1', 'http://www.example.com/path/more?q=1'),
+ array('http://www.example.com/', '?q=1', 'http://www.example.com/?q=1'),
+ array('http://www.example.com/path', 'http://test.com', 'http://test.com'),
+ array('http://www.example.com:8080/path', 'http://test.com', 'http://test.com'),
+ array('http://www.example.com:8080/path', '?q=2#abc', 'http://www.example.com:8080/path?q=2#abc'),
+ array('http://u:a@www.example.com/path', 'test', 'http://u:a@www.example.com/path/test'),
+ array('http://www.example.com/path', 'http://u:a@www.example.com/', 'http://u:a@www.example.com/'),
+ array('/path?q=2', 'http://www.test.com/', 'http://www.test.com/path?q=2'),
+ array('http://api.flickr.com/services/', 'http://www.flickr.com/services/oauth/access_token', 'http://www.flickr.com/services/oauth/access_token'),
+ array('http://www.example.com/?foo=bar', 'some/path', 'http://www.example.com/some/path?foo=bar'),
+ array('http://www.example.com/?foo=bar', 'some/path?boo=moo', 'http://www.example.com/some/path?boo=moo&foo=bar'),
+ array('http://www.example.com/some/', 'path?foo=bar&foo=baz', 'http://www.example.com/some/path?foo=bar&foo=baz'),
+ );
+ }
+
+ /**
+ * @dataProvider urlCombineDataProvider
+ */
+ public function testCombinesUrls($a, $b, $c)
+ {
+ $this->assertEquals($c, (string) Url::factory($a)->combine($b));
+ }
+
+ public function testHasGettersAndSetters()
+ {
+ $url = Url::factory('http://www.test.com/');
+ $this->assertEquals('example.com', $url->setHost('example.com')->getHost());
+ $this->assertEquals('8080', $url->setPort(8080)->getPort());
+ $this->assertEquals('/foo/bar', $url->setPath(array('foo', 'bar'))->getPath());
+ $this->assertEquals('a', $url->setPassword('a')->getPassword());
+ $this->assertEquals('b', $url->setUsername('b')->getUsername());
+ $this->assertEquals('abc', $url->setFragment('abc')->getFragment());
+ $this->assertEquals('https', $url->setScheme('https')->getScheme());
+ $this->assertEquals('a=123', (string) $url->setQuery('a=123')->getQuery());
+ $this->assertEquals('https://b:a@example.com:8080/foo/bar?a=123#abc', (string) $url);
+ $this->assertEquals('b=boo', (string) $url->setQuery(new QueryString(array(
+ 'b' => 'boo'
+ )))->getQuery());
+ $this->assertEquals('https://b:a@example.com:8080/foo/bar?b=boo#abc', (string) $url);
+ }
+
+ public function testSetQueryAcceptsArray()
+ {
+ $url = Url::factory('http://www.test.com');
+ $url->setQuery(array('a' => 'b'));
+ $this->assertEquals('http://www.test.com?a=b', (string) $url);
+ }
+
+ public function urlProvider()
+ {
+ return array(
+ array('/foo/..', '/'),
+ array('//foo//..', '/'),
+ array('/foo/../..', '/'),
+ array('/foo/../.', '/'),
+ array('/./foo/..', '/'),
+ array('/./foo', '/foo'),
+ array('/./foo/', '/foo/'),
+ array('/./foo/bar/baz/pho/../..', '/foo/bar'),
+ array('*', '*'),
+ array('/foo', '/foo'),
+ array('/abc/123/../foo/', '/abc/foo/'),
+ array('/a/b/c/./../../g', '/a/g'),
+ array('/b/c/./../../g', '/g'),
+ array('/b/c/./../../g', '/g'),
+ array('/c/./../../g', '/g'),
+ array('/./../../g', '/g'),
+ );
+ }
+
+ /**
+ * @dataProvider urlProvider
+ */
+ public function testNormalizesPaths($path, $result)
+ {
+ $url = Url::factory('http://www.example.com/');
+ $url->setPath($path)->normalizePath();
+ $this->assertEquals($result, $url->getPath());
+ }
+
+ public function testSettingHostWithPortModifiesPort()
+ {
+ $url = Url::factory('http://www.example.com');
+ $url->setHost('foo:8983');
+ $this->assertEquals('foo', $url->getHost());
+ $this->assertEquals(8983, $url->getPort());
+ }
+
+ /**
+ * @expectedException \Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testValidatesUrlCanBeParsed()
+ {
+ Url::factory('foo:////');
+ }
+
+ public function testConvertsSpecialCharsInPathWhenCastingToString()
+ {
+ $url = Url::factory('http://foo.com/baz bar?a=b');
+ $url->addPath('?');
+ $this->assertEquals('http://foo.com/baz%20bar/%3F?a=b', (string) $url);
+ }
+
+ /**
+ * @link http://tools.ietf.org/html/rfc3986#section-5.4.1
+ */
+ public function rfc3986UrlProvider()
+ {
+ $result = array(
+ array('g', 'http://a/b/c/g'),
+ array('./g', 'http://a/b/c/g'),
+ array('g/', 'http://a/b/c/g/'),
+ array('/g', 'http://a/g'),
+ array('?y', 'http://a/b/c/d;p?y'),
+ array('g?y', 'http://a/b/c/g?y'),
+ array('#s', 'http://a/b/c/d;p?q#s'),
+ array('g#s', 'http://a/b/c/g#s'),
+ array('g?y#s', 'http://a/b/c/g?y#s'),
+ array(';x', 'http://a/b/c/;x'),
+ array('g;x', 'http://a/b/c/g;x'),
+ array('g;x?y#s', 'http://a/b/c/g;x?y#s'),
+ array('', 'http://a/b/c/d;p?q'),
+ array('.', 'http://a/b/c'),
+ array('./', 'http://a/b/c/'),
+ array('..', 'http://a/b'),
+ array('../', 'http://a/b/'),
+ array('../g', 'http://a/b/g'),
+ array('../..', 'http://a/'),
+ array('../../', 'http://a/'),
+ array('../../g', 'http://a/g')
+ );
+
+ // This support was added in PHP 5.4.7: https://bugs.php.net/bug.php?id=62844
+ if (version_compare(PHP_VERSION, '5.4.7', '>=')) {
+ $result[] = array('//g', 'http://g');
+ }
+
+ return $result;
+ }
+
+ /**
+ * @dataProvider rfc3986UrlProvider
+ */
+ public function testCombinesUrlsUsingRfc3986($relative, $result)
+ {
+ $a = Url::factory('http://a/b/c/d;p?q');
+ $b = Url::factory($relative);
+ $this->assertEquals($result, trim((string) $a->combine($b, true), '='));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/server.js b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/server.js
new file mode 100644
index 0000000..4156f1a
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/server.js
@@ -0,0 +1,146 @@
+/**
+ * Guzzle node.js test server to return queued responses to HTTP requests and
+ * expose a RESTful API for enqueueing responses and retrieving the requests
+ * that have been received.
+ *
+ * - Delete all requests that have been received:
+ * DELETE /guzzle-server/requests
+ * Host: 127.0.0.1:8124
+ *
+ * - Enqueue responses
+ * PUT /guzzle-server/responses
+ * Host: 127.0.0.1:8124
+ *
+ * [{ "statusCode": 200, "reasonPhrase": "OK", "headers": {}, "body": "" }]
+ *
+ * - Get the received requests
+ * GET /guzzle-server/requests
+ * Host: 127.0.0.1:8124
+ *
+ * - Shutdown the server
+ * DELETE /guzzle-server
+ * Host: 127.0.0.1:8124
+ *
+ * @package Guzzle PHP <http://www.guzzlephp.org>
+ * @license See the LICENSE file that was distributed with this source code.
+ */
+
+var http = require("http");
+
+/**
+ * Guzzle node.js server
+ * @class
+ */
+var GuzzleServer = function(port, log) {
+
+ this.port = port;
+ this.log = log;
+ this.responses = [];
+ this.requests = [];
+ var that = this;
+
+ var controlRequest = function(request, req, res) {
+ if (req.url == '/guzzle-server/perf') {
+ res.writeHead(200, "OK", {"Content-Length": 16});
+ res.end("Body of response");
+ } else if (req.method == "DELETE") {
+ if (req.url == "/guzzle-server/requests") {
+ // Clear the received requests
+ that.requests = [];
+ res.writeHead(200, "OK", { "Content-Length": 0 });
+ res.end();
+ if (this.log) {
+ console.log("Flushing requests");
+ }
+ } else if (req.url == "/guzzle-server") {
+ // Shutdown the server
+ res.writeHead(200, "OK", { "Content-Length": 0, "Connection": "close" });
+ res.end();
+ if (this.log) {
+ console.log("Shutting down");
+ }
+ that.server.close();
+ }
+ } else if (req.method == "GET") {
+ if (req.url === "/guzzle-server/requests") {
+ // Get received requests
+ var data = that.requests.join("\n----[request]\n");
+ res.writeHead(200, "OK", { "Content-Length": data.length });
+ res.end(data);
+ if (that.log) {
+ console.log("Sending receiving requests");
+ }
+ }
+ } else if (req.method == "PUT") {
+ if (req.url == "/guzzle-server/responses") {
+ if (that.log) {
+ console.log("Adding responses...");
+ }
+ // Received response to queue
+ var data = request.split("\r\n\r\n")[1];
+ if (!data) {
+ if (that.log) {
+ console.log("No response data was provided");
+ }
+ res.writeHead(400, "NO RESPONSES IN REQUEST", { "Content-Length": 0 });
+ } else {
+ that.responses = eval("(" + data + ")");
+ if (that.log) {
+ console.log(that.responses);
+ }
+ res.writeHead(200, "OK", { "Content-Length": 0 });
+ }
+ res.end();
+ }
+ }
+ };
+
+ var receivedRequest = function(request, req, res) {
+ if (req.url.indexOf("/guzzle-server") === 0) {
+ controlRequest(request, req, res);
+ } else if (req.url.indexOf("/guzzle-server") == -1 && !that.responses.length) {
+ res.writeHead(500);
+ res.end("No responses in queue");
+ } else {
+ var response = that.responses.shift();
+ res.writeHead(response.statusCode, response.reasonPhrase, response.headers);
+ res.end(response.body);
+ that.requests.push(request);
+ }
+ };
+
+ this.start = function() {
+
+ that.server = http.createServer(function(req, res) {
+
+ var request = req.method + " " + req.url + " HTTP/" + req.httpVersion + "\r\n";
+ for (var i in req.headers) {
+ request += i + ": " + req.headers[i] + "\r\n";
+ }
+ request += "\r\n";
+
+ // Receive each chunk of the request body
+ req.addListener("data", function(chunk) {
+ request += chunk;
+ });
+
+ // Called when the request completes
+ req.addListener("end", function() {
+ receivedRequest(request, req, res);
+ });
+ });
+ that.server.listen(port, "127.0.0.1");
+
+ if (this.log) {
+ console.log("Server running at http://127.0.0.1:8124/");
+ }
+ };
+};
+
+// Get the port from the arguments
+port = process.argv.length >= 3 ? process.argv[2] : 8124;
+log = process.argv.length >= 4 ? process.argv[3] : false;
+
+// Start the server
+server = new GuzzleServer(port, log);
+server.start();