Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit f81625f

Browse files
committed
Adds tests
1 parent f14404f commit f81625f

6 files changed

+138
-6
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
],
1313
"require": {
1414
"php": ">=5.4",
15-
"php-http/adapter-core": "dev-internal_separation",
15+
"php-http/adapter-common": "dev-client_separation",
1616
"guzzlehttp/guzzle": "~6.0"
1717
},
1818
"require-dev": {
1919
"ext-curl": "*",
20-
"php-http/adapter-integration-tests": "dev-internal_separation"
20+
"php-http/adapter-integration-tests": "dev-client_separation"
2121
},
2222
"provide": {
2323
"php-http/adapter-implementation": "0.1"

src/Guzzle6HttpAdapter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
use Http\Adapter\Common\Exception\HttpAdapterException;
1818
use Http\Adapter\Common\Exception\MultiHttpAdapterException;
1919
use Psr\Http\Message\RequestInterface;
20+
use Psr\Http\Message\ResponseInterface;
2021

2122
/**
2223
* Guzzle 6 HTTP adapter
2324
*
2425
* @author David de Boer <[email protected]>
2526
*/
26-
class Guzzle6HttpAdapter implements PsrHttpAdapter
27+
class Guzzle6HttpAdapter implements HttpAdapter
2728
{
2829
/**
2930
* @param Client $client
@@ -41,7 +42,7 @@ public function sendRequest(RequestInterface $request)
4142
try {
4243
return $this->client->send($request);
4344
} catch (RequestException $exception) {
44-
throw new $this->createException($exception);
45+
throw $this->createException($exception);
4546
}
4647
}
4748

@@ -56,14 +57,18 @@ public function sendRequests(array $requests)
5657
);
5758

5859
$exceptions = [];
60+
$responses = [];
61+
5962
foreach ($results as $result) {
60-
if ($result instanceof TransferException) {
63+
if ($result instanceof ResponseInterface) {
64+
$responses[] = $result;
65+
} elseif ($result instanceof RequestException) {
6166
$exceptions[] = $this->createException($result);
6267
}
6368
}
6469

6570
if (count($exceptions) > 0) {
66-
throw new MultiHttpAdapterException($exceptions);
71+
throw new MultiHttpAdapterException($exceptions, $responses);
6772
}
6873

6974
return $results;

tests/Guzzle6CurlHttpAdapterTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Adapter package.
5+
*
6+
* (c) Eric GELOEN <[email protected]>
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Adapter\Tests;
13+
14+
use GuzzleHttp\Handler\CurlHandler;
15+
16+
/**
17+
* @requires PHP 5.5
18+
*
19+
* @author GeLo <[email protected]>
20+
*/
21+
class Guzzle6CurlHttpAdapterTest extends Guzzle6HttpAdapterTest
22+
{
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
protected function createHandler()
27+
{
28+
return new CurlHandler();
29+
}
30+
}

tests/Guzzle6HttpAdapterTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Adapter package.
5+
*
6+
* (c) Eric GELOEN <[email protected]>
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Adapter\Tests;
13+
14+
use GuzzleHttp\Client;
15+
use Http\Adapter\Guzzle6HttpAdapter;
16+
17+
/**
18+
* @author GeLo <[email protected]>
19+
*/
20+
abstract class Guzzle6HttpAdapterTest extends HttpAdapterTest
21+
{
22+
public function testGetName()
23+
{
24+
$this->assertSame('guzzle6', $this->httpAdapter->getName());
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function createHttpAdapter()
31+
{
32+
return new Guzzle6HttpAdapter(new Client(['handler' => $this->createHandler()]));
33+
}
34+
35+
/**
36+
* Returns a handler for the client
37+
*
38+
* @return object
39+
*/
40+
abstract protected function createHandler();
41+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Adapter package.
5+
*
6+
* (c) Eric GELOEN <[email protected]>
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Adapter\Tests;
13+
14+
use GuzzleHttp\Handler\CurlMultiHandler;
15+
16+
/**
17+
* @author GeLo <[email protected]>
18+
*/
19+
class Guzzle6MultiCurlHttpAdapterTest extends Guzzle6HttpAdapterTest
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected function createHandler()
25+
{
26+
return new CurlMultiHandler();
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Adapter package.
5+
*
6+
* (c) Eric GELOEN <[email protected]>
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Adapter\Tests;
13+
14+
use GuzzleHttp\Handler\StreamHandler;
15+
16+
/**
17+
* @author GeLo <[email protected]>
18+
*/
19+
class Guzzle6StreamHttpAdapterTest extends Guzzle6HttpAdapterTest
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected function createHandler()
25+
{
26+
return new StreamHandler();
27+
}
28+
}

0 commit comments

Comments
 (0)