
This patch achieves three interrelated changes 1. an update to the ClientInterface, making it more efficient and consistent with other HTTP libraries. PSR-FIG messages have also been added as separate classes, rather than lumped as one. Guzzle functionality has also been moved to its own namespace; 2. the refactoring of `GuzzleClient` to `GuzzleAdapter`, including relevant changes needed for the interface change (1). We now have ADAPTERS that bridge our interfaces with Guzzle's - making that difference much clearer, extensible, less tightly coupled and less brittle; 3. moving "bad request" error handling into its own dedicated space, based on how the new Adapter functionality (2). Previously the client tried to do all the exception logic - but this is not strictly its responsibility. This logic has been shipped out to a base RequestException which instantiates one of its children exception based on the HTTP status code. Although I have attempted to keep the scope of this patch to a minimum, as granular as possible, because the interface is a core internal API, various other files need to be modified to reflect the change. In terms of the other two changes, these are inextricably linked to the interface change, so cannot be teased out into their own patches. Change-Id: Ibc1b50cec125c11d32ee6e4f0dbb395fcaea864e
93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Copyright 2014 OpenStack Foundation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
namespace OpenStack\Tests\Common\Transport;
|
|
|
|
use OpenStack\Tests\TestCase;
|
|
|
|
class AbstractClientTest extends TestCase
|
|
{
|
|
const URI = 'http://openstack.org';
|
|
|
|
private $client;
|
|
private $request;
|
|
private $options = ['foo' => 'bar'];
|
|
private $body = 'baz';
|
|
|
|
public function setUp()
|
|
{
|
|
$this->request = $this->getMockBuilder('OpenStack\Common\Transport\RequestInterface')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$this->client = $this->getMockForAbstractClass('OpenStack\Common\Transport\AbstractClient');
|
|
|
|
$this->client->expects($this->once())
|
|
->method('send')
|
|
->with($this->request);
|
|
}
|
|
|
|
public function testGet()
|
|
{
|
|
$this->client->expects($this->once())
|
|
->method('createRequest')
|
|
->with('GET', self::URI, null, $this->options)
|
|
->will($this->returnValue($this->request));
|
|
|
|
$this->client->get(self::URI, $this->options);
|
|
}
|
|
|
|
public function testHead()
|
|
{
|
|
$this->client->expects($this->once())
|
|
->method('createRequest')
|
|
->with('HEAD', self::URI, null, $this->options)
|
|
->will($this->returnValue($this->request));
|
|
|
|
$this->client->head(self::URI, $this->options);
|
|
}
|
|
|
|
public function testPost()
|
|
{
|
|
$this->client->expects($this->once())
|
|
->method('createRequest')
|
|
->with('POST', self::URI, $this->body, $this->options)
|
|
->will($this->returnValue($this->request));
|
|
|
|
$this->client->post(self::URI, $this->body, $this->options);
|
|
}
|
|
|
|
public function testPut()
|
|
{
|
|
$this->client->expects($this->once())
|
|
->method('createRequest')
|
|
->with('PUT', self::URI, $this->body, $this->options)
|
|
->will($this->returnValue($this->request));
|
|
|
|
$this->client->put(self::URI, $this->body, $this->options);
|
|
}
|
|
|
|
public function testDelete()
|
|
{
|
|
$this->client->expects($this->once())
|
|
->method('createRequest')
|
|
->with('DELETE', self::URI, null, $this->options)
|
|
->will($this->returnValue($this->request));
|
|
|
|
$this->client->delete(self::URI, $this->options);
|
|
}
|
|
} |