Skip to content

Commit

Permalink
Merge branch 'master' into add_invalid_argument_exception
Browse files Browse the repository at this point in the history
  • Loading branch information
gmponos committed Oct 6, 2018
2 parents 3e6a823 + 3ff39a4 commit 49a7493
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 22 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM composer:latest as setup

RUN mkdir /guzzle

WORKDIR /guzzle

RUN set -xe \
&& composer init --name=guzzlehttp/test --description="Simple project for testing Guzzle scripts" --author="Márk Sági-Kazár <mark.sagikazar@gmail.com>" --no-interaction \
&& composer require guzzlehttp/guzzle


FROM php:7.2

RUN mkdir /guzzle

WORKDIR /guzzle

COPY --from=setup /guzzle /guzzle
49 changes: 43 additions & 6 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ requests.
'webp' => $client->getAsync('/image/webp')
];
// Wait on all of the requests to complete. Throws a ConnectException
// Wait on all of the requests to complete. Throws a ConnectException
// if any of the requests fail
$results = Promise\unwrap($promises);
// Wait for the requests to complete, even if some of them fail
$results = Promise\settle($promises)->wait();
Expand Down Expand Up @@ -229,7 +229,7 @@ amount of requests you wish to send.
// Force the pool of requests to complete.
$promise->wait();
Or using a closure that will return a promise once the pool calls the closure.

.. code-block:: php
Expand All @@ -246,7 +246,7 @@ Or using a closure that will return a promise once the pool calls the closure.
};
$pool = new Pool($client, $requests(100));
Using Responses
===============
Expand Down Expand Up @@ -447,6 +447,43 @@ to use a shared cookie jar for all requests.
$client = new \GuzzleHttp\Client(['cookies' => true]);
$r = $client->request('GET', 'http://httpbin.org/cookies');
Different implementations exist for the ``GuzzleHttp\Cookie\CookieJarInterface``
:

- The ``GuzzleHttp\Cookie\CookieJar`` class stores cookies as an array.
- The ``GuzzleHttp\Cookie\FileCookieJar`` class persists non-session cookies
using a JSON formatted file.
- The ``GuzzleHttp\Cookie\SessionCookieJar`` class persists cookies in the
client session.

You can manually set cookies into a cookie jar with the named constructor
``fromArray(array $cookies, $domain)``.

.. code-block:: php
$jar = \GuzzleHttp\Cookie\CookieJar::fromArray(
[
'some_cookie' => 'foo',
'other_cookie' => 'barbaz1234'
],
'example.org'
);
You can get a cookie by its name with the ``getCookieByName($name)`` method
which returns a ``GuzzleHttp\Cookie\SetCookie`` instance.

.. code-block:: php
$cookie = $jar->getCookieByName('some_cookie');
$cookie->getValue(); // 'foo'
$cookie->getDomain(); // 'example.org'
$cookie->getExpires(); // expiration date as a Unix timestamp
The cookies can be also fetched into an array thanks to the `toArray()` method.
The ``GuzzleHttp\Cookie\CookieJarInterface`` interface extends
``Traversable`` so it can be iterated in a foreach loop.


Redirects
=========
Expand Down Expand Up @@ -499,7 +536,7 @@ on each other.
│ └── ClientException
├── ConnectionException
└── TooManyRedirectsException
Guzzle throws exceptions for errors that occur during a transfer.

- In the event of a networking error (connection timeout, DNS errors, etc.),
Expand Down Expand Up @@ -568,7 +605,7 @@ behavior of the library.
the timeout.
``HTTP_PROXY``
Defines the proxy to use when sending requests using the "http" protocol.

Note: because the HTTP_PROXY variable may contain arbitrary user input on some (CGI) environments, the variable is only used on the CLI SAPI. See https://httpoxy.org for more information.
``HTTPS_PROXY``
Defines the proxy to use when sending requests using the "https" protocol.
Expand Down
2 changes: 1 addition & 1 deletion docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ a response or exception by shifting return values off of a queue.
$mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar']),
new Response(202, ['Content-Length' => 0]),
new RequestException("Error Communicating with Server", new Request('GET', 'test'))
new RequestException('Error Communicating with Server', new Request('GET', 'test'))
]);
$handlerStack = HandlerStack::create($mock);
Expand Down
2 changes: 1 addition & 1 deletion src/Cookie/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function clear($domain = null, $path = null, $name = null)
} elseif (!$path) {
$this->cookies = array_filter(
$this->cookies,
function (SetCookie $cookie) use ($path, $domain) {
function (SetCookie $cookie) use ($domain) {
return !$cookie->matchesDomain($domain);
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/StreamHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __invoke(RequestInterface $request, array $options)
// Append a content-length header if body size is zero to match
// cURL's behavior.
if (0 === $request->getBody()->getSize()) {
$request = $request->withHeader('Content-Length', 0);
$request = $request->withHeader('Content-Length', '0');
}

return $this->createResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/HandlerStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function resolve()
}

/**
* @param $name
* @param string $name
* @return int
*/
private function findByName($name)
Expand All @@ -223,10 +223,10 @@ private function findByName($name)
/**
* Splices a function into the middleware list at a specific position.
*
* @param $findName
* @param $withName
* @param string $findName
* @param string $withName
* @param callable $middleware
* @param $before
* @param bool $before
*/
private function splice($findName, $withName, callable $middleware, $before)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function httpErrors()
return $handler($request, $options);
}
return $handler($request, $options)->then(
function (ResponseInterface $response) use ($request, $handler) {
function (ResponseInterface $response) use ($request) {
$code = $response->getStatusCode();
if ($code < 400) {
return $response;
Expand Down
5 changes: 4 additions & 1 deletion src/RetryMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class RetryMiddleware
/** @var callable */
private $decider;

/** @var callable */
private $delay;

/**
* @param callable $decider Function that accepts the number of retries,
* a request, [response], and [exception] and
Expand All @@ -42,7 +45,7 @@ public function __construct(
/**
* Default exponential backoff delay function.
*
* @param $retries
* @param int $retries
*
* @return int
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/Cookie/FileCookieJarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testLoadsFromFile()
}

/**
* @dataProvider testPersistsToFileFileParameters
* @dataProvider providerPersistsToFileFileParameters
*/
public function testPersistsToFile($testSaveSessionCookie = false)
{
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testPersistsToFile($testSaveSessionCookie = false)
unlink($this->file);
}

public function testPersistsToFileFileParameters()
public function providerPersistsToFileFileParameters()
{
return array(
array(false),
Expand Down
4 changes: 2 additions & 2 deletions tests/Cookie/SessionCookieJarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testLoadsFromSession()
}

/**
* @dataProvider testPersistsToSessionParameters
* @dataProvider providerPersistsToSessionParameters
*/
public function testPersistsToSession($testSaveSessionCookie = false)
{
Expand Down Expand Up @@ -82,7 +82,7 @@ public function testPersistsToSession($testSaveSessionCookie = false)
unset($_SESSION[$this->sessionVar]);
}

public function testPersistsToSessionParameters()
public function providerPersistsToSessionParameters()
{
return array(
array(false),
Expand Down
4 changes: 2 additions & 2 deletions tests/Handler/CurlHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function testReusesHandles()
Server::enqueue([$response, $response]);
$a = new CurlHandler();
$request = new Request('GET', Server::$url);
$a($request, []);
$a($request, []);
$this->assertInstanceOf('GuzzleHttp\Promise\FulfilledPromise', $a($request, []));
$this->assertInstanceOf('GuzzleHttp\Promise\FulfilledPromise', $a($request, []));
}

public function testDoesSleep()
Expand Down
5 changes: 5 additions & 0 deletions tests/Handler/CurlMultiHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function testCanCancel()
$response->cancel();
$responses[] = $response;
}

foreach($responses as $r) {
$this->assertEquals('rejected', $response->getState());
}
}

public function testCannotCancelFinished()
Expand All @@ -56,6 +60,7 @@ public function testCannotCancelFinished()
$response = $a(new Request('GET', Server::$url), []);
$response->wait();
$response->cancel();
$this->assertEquals('fulfilled', $response->getState());
}

public function testDelaysConcurrently()
Expand Down
5 changes: 4 additions & 1 deletion tests/Handler/StreamHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ public function testVerifiesVerifyIsValidIfPath()

public function testVerifyCanBeDisabled()
{
$this->getSendResult(['verify' => false]);
$handler = $this->getSendResult(['verify' => false]);
$this->assertInstanceOf('GuzzleHttp\Psr7\Response', $handler);
}

/**
Expand Down Expand Up @@ -337,6 +338,8 @@ public function testUsesSystemDefaultBundle()
$opts = stream_context_get_options($res->getBody()->detach());
if (PHP_VERSION_ID < 50600) {
$this->assertEquals($path, $opts['ssl']['cafile']);
} else {
$this->assertArrayNotHasKey('cafile', $opts['ssl']);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/HandlerStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function testSetsHandlerInCtor()
$this->assertTrue($h->hasHandler());
}

/**
* @doesNotPerformAssertions
*/
public function testCanSetDifferentHandlerAfterConstruction()
{
$f = function () {};
Expand Down
6 changes: 6 additions & 0 deletions tests/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ public function testValidatesEachElement()
$p->promise()->wait();
}

/**
* @doesNotPerformAssertions
*/
public function testSendsAndRealizesFuture()
{
$c = $this->getClient();
$p = new Pool($c, [new Request('GET', 'http://example.com')]);
$p->promise()->wait();
}

/**
* @doesNotPerformAssertions
*/
public function testExecutesPendingWhenWaiting()
{
$r1 = new Promise(function () use (&$r1) { $r1->resolve(new Response()); });
Expand Down

0 comments on commit 49a7493

Please sign in to comment.