Skip to content

Commit 1c7af1f

Browse files
author
Jurgen van Arragon
committed
Fixes issues with guzzle psr7 compliance
- Changed guzzle final HandlerStack extension to factory class HandlerStackFactory - Updated old guzzle psr7 utill functions to work with the new Utill class functions
1 parent 42e2d09 commit 1c7af1f

File tree

9 files changed

+26
-19
lines changed

9 files changed

+26
-19
lines changed

samples/images/v2/images/upload_binary_data.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use GuzzleHttp\Psr7\Utils;
4+
35
require 'vendor/autoload.php';
46

57
$openstack = new OpenStack\OpenStack([
@@ -12,5 +14,5 @@
1214
$service = $openstack->imagesV2();
1315

1416
$image = $service->getImage('{imageId}');
15-
$stream = \GuzzleHttp\Psr7\stream_for(fopen('{fileName}', 'r'));
17+
$stream = Utils::streamFor(fopen('{fileName}', 'r'));
1618
$image->uploadData($stream);

src/Common/Service/Builder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
use GuzzleHttp\Client;
88
use GuzzleHttp\ClientInterface;
9+
use GuzzleHttp\HandlerStack;
910
use GuzzleHttp\Middleware as GuzzleMiddleware;
1011
use OpenStack\Common\Auth\IdentityService;
1112
use OpenStack\Common\Auth\Token;
12-
use OpenStack\Common\Transport\HandlerStack;
13+
use OpenStack\Common\Transport\HandlerStackFactory;
1314
use OpenStack\Common\Transport\Middleware;
1415
use OpenStack\Common\Transport\Utils;
1516

@@ -132,7 +133,7 @@ private function stockAuthHandler(array &$options)
132133

133134
private function getStack(callable $authHandler, Token $token = null): HandlerStack
134135
{
135-
$stack = HandlerStack::create();
136+
$stack = HandlerStackFactory::create();
136137
$stack->push(Middleware::authHandler($authHandler, $token));
137138

138139
return $stack;

src/Common/Transport/HandlerStack.php renamed to src/Common/Transport/HandlerStackFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace OpenStack\Common\Transport;
66

7-
use GuzzleHttp\HandlerStack as GuzzleStack;
7+
use GuzzleHttp\HandlerStack;
88
use GuzzleHttp\Utils;
99

10-
class HandlerStack extends GuzzleStack
10+
class HandlerStackFactory
1111
{
12-
public static function create(?callable $handler = null): GuzzleStack
12+
public static function create(?callable $handler = null): HandlerStack
1313
{
14-
$stack = new self($handler ?: Utils::chooseHandler());
14+
$stack = new HandlerStack($handler ?: Utils::chooseHandler());
1515
$stack->push(Middleware::httpErrors(), 'http_errors');
1616
$stack->push(Middleware::prepareBody(), 'prepare_body');
1717

src/OpenStack.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use GuzzleHttp\Client;
88
use GuzzleHttp\Middleware as GuzzleMiddleware;
99
use OpenStack\Common\Service\Builder;
10-
use OpenStack\Common\Transport\HandlerStack;
10+
use OpenStack\Common\Transport\HandlerStackFactory;
1111
use OpenStack\Common\Transport\Utils;
1212
use OpenStack\Identity\v3\Service;
1313

@@ -50,7 +50,7 @@ private function getDefaultIdentityService(array $options): Service
5050
throw new \InvalidArgumentException("'authUrl' is a required option");
5151
}
5252

53-
$stack = HandlerStack::create();
53+
$stack = HandlerStackFactory::create();
5454

5555
if (!empty($options['debugLog'])
5656
&& !empty($options['logger'])

tests/unit/Common/Resource/OperatorResourceTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use GuzzleHttp\Psr7\Response;
66
use GuzzleHttp\Psr7\Uri;
7+
use GuzzleHttp\Psr7\Utils;
78
use OpenStack\Common\Resource\OperatorResource;
89
use OpenStack\Common\Resource\ResourceInterface;
910
use OpenStack\Test\Common\Service\Fixtures\Api;
@@ -28,7 +29,7 @@ public function setUp(): void
2829

2930
public function test_it_retrieves_base_http_url()
3031
{
31-
$returnedUri = \GuzzleHttp\Psr7\uri_for('http://foo.com');
32+
$returnedUri = Utils::uriFor('http://foo.com');
3233
$this->client->getConfig('base_uri')->shouldBeCalled()->willReturn($returnedUri);
3334

3435
$uri = $this->resource->testBaseUri();

tests/unit/Common/Transport/HandlerStackTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace OpenStack\Test\Common\Transport;
44

55
use GuzzleHttp\Handler\MockHandler;
6-
use OpenStack\Common\Transport\HandlerStack;
6+
use GuzzleHttp\HandlerStack;
7+
use OpenStack\Common\Transport\HandlerStackFactory;
78
use OpenStack\Test\TestCase;
89

910
class HandlerStackTest extends TestCase
1011
{
1112
public function test_it_is_created()
1213
{
13-
self::assertInstanceOf(HandlerStack::class, HandlerStack::create(new MockHandler()));
14+
self::assertInstanceOf(HandlerStack::class, HandlerStackFactory::create(new MockHandler()));
1415
}
1516
}

tests/unit/Images/v2/Models/ImageTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GuzzleHttp\Psr7\Response;
66
use GuzzleHttp\Psr7\Stream;
77
use GuzzleHttp\Psr7\Uri;
8+
use GuzzleHttp\Psr7\Utils;
89
use OpenStack\Images\v2\Api;
910
use OpenStack\Images\v2\Models\Member;
1011
use OpenStack\Images\v2\Models\Image;
@@ -30,7 +31,7 @@ public function setUp(): void
3031

3132
public function test_it_retrieves()
3233
{
33-
$this->client->getConfig('base_uri')->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\uri_for(''));
34+
$this->client->getConfig('base_uri')->shouldBeCalled()->willReturn(Utils::uriFor(''));
3435

3536
$this->setupMock('GET', $this->path, null, [], 'GET_image');
3637

@@ -123,7 +124,7 @@ public function test_it_deactivates()
123124

124125
public function test_it_uploads_data_stream()
125126
{
126-
$stream = \GuzzleHttp\Psr7\stream_for('data');
127+
$stream = Utils::streamFor('data');
127128
$headers = ['Content-Type' => 'application/octet-stream'];
128129

129130
$this->setupMock('PUT', $this->path . '/file', $stream, $headers, new Response(204));
@@ -133,7 +134,7 @@ public function test_it_uploads_data_stream()
133134

134135
public function test_it_downloads_data()
135136
{
136-
$stream = \GuzzleHttp\Psr7\stream_for('data');
137+
$stream = Utils::streamFor('data');
137138
$headers = ['Content-Type' => 'application/octet-stream'];
138139
$response = new Response(200, $headers, $stream);
139140

tests/unit/Images/v2/ServiceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OpenStack\Test\Images\v2;
44

55
use GuzzleHttp\Psr7\Uri;
6+
use GuzzleHttp\Psr7\Utils;
67
use OpenStack\Images\v2\Api;
78
use OpenStack\Images\v2\Models\Image;
89
use OpenStack\Images\v2\Service;
@@ -26,7 +27,7 @@ public function test_it_creates_image()
2627
$this->client
2728
->getConfig('base_uri')
2829
->shouldBeCalled()
29-
->willReturn(\GuzzleHttp\Psr7\uri_for(''));
30+
->willReturn(Utils::uriFor(''));
3031

3132
$expectedJson = [
3233
"name" => "Ubuntu 12.10",
@@ -61,7 +62,7 @@ public function test_it_lists_images()
6162
$this->client
6263
->getConfig('base_uri')
6364
->shouldBeCalled()
64-
->willReturn(\GuzzleHttp\Psr7\uri_for(''));
65+
->willReturn(Utils::uriFor(''));
6566

6667
$this->client
6768
->request('GET', 'v2/images', ['query' => ['limit' => 5], 'headers' => []])

tests/unit/ObjectStore/v1/Models/ContainerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use GuzzleHttp\Psr7\Stream;
7+
use GuzzleHttp\Psr7\Utils;
88
use OpenStack\Common\Error\BadResponseError;
99
use OpenStack\ObjectStore\v1\Api;
1010
use OpenStack\ObjectStore\v1\Models\Container;
@@ -211,7 +211,7 @@ public function test_other_exceptions_are_thrown()
211211
public function test_it_chunks_according_to_provided_segment_size()
212212
{
213213
/** @var \GuzzleHttp\Psr7\Stream $stream */
214-
$stream = \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'X')));
214+
$stream = Utils::streamFor(implode('', range('A', 'X')));
215215

216216
$data = [
217217
'name' => 'object',

0 commit comments

Comments
 (0)