Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<?php
if (!file_exists(__DIR__.'/src')) {
exit(0);
}
return PhpCsFixer\Config::create()
->setRules(
[
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'protected_to_private' => false
]
)
->setUsingCache(false)
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->append([__FILE__, __DIR__.'/samples'])
);
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ before_install:
before_script:
- composer install --prefer-source
- vendor/bin/parallel-lint --exclude vendor .
- vendor/bin/php-cs-fixer fix --dry-run --diff --level psr2 .
- vendor/bin/php-cs-fixer fix --dry-run --diff
- phpenv config-add ./xdebug.ini

after_script:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"psr/log": "~1.0",
"satooshi/php-coveralls": "~1.0",
"jakub-onderka/php-parallel-lint": "0.*",
"friendsofphp/php-cs-fixer": "^1.0"
"friendsofphp/php-cs-fixer": "^2.9"
}
}
13 changes: 7 additions & 6 deletions samples/identity/v2/authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use OpenStack\Common\Transport\Utils as TransportUtils;
use OpenStack\Identity\v2\Service;
use OpenStack\OpenStack;

$authUrl = 'https://keystone.example.com:5000/v2.0';

$httpClient = new Client([
'base_uri' => TransportUtils::normalizeUrl($authUrl),
'handler' => HandlerStack::create(),
]);

$options = [
'authUrl' => $authUrl,
'region' => 'RegionOne',
'username' => 'foo',
'password' => 'bar',
'tenantName' => 'baz',
'identityService' => new Client(
[
'base_uri' => TransportUtils::normalizeUrl($authUrl),
'handler' => HandlerStack::create(),
]
),
'identityService' => Service::factory($httpClient),
];

/** @var OpenStack $openstack */
Expand Down
9 changes: 7 additions & 2 deletions src/Common/Api/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ private function validateEnums($userValues)
{
if (!empty($this->enum) && $this->type == 'string' && !in_array($userValues, $this->enum)) {
throw new \Exception(sprintf(
'The only permitted values are %s. You provided %s', implode(', ', $this->enum), print_r($userValues, true)
'The only permitted values are %s. You provided %s',
implode(', ', $this->enum),
print_r($userValues, true)
));
}
}
Expand All @@ -217,7 +219,10 @@ private function validateType($userValues)
if (!$this->hasCorrectType($userValues)) {
throw new \Exception(sprintf(
'The key provided "%s" has the wrong value type. You provided %s (%s) but was expecting %s',
$this->name, print_r($userValues, true), gettype($userValues), $this->type
$this->name,
print_r($userValues, true),
gettype($userValues),
$this->type
));
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/Common/Error/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ public function httpError(RequestInterface $request, ResponseInterface $response
{
$message = $this->header('HTTP Error');

$message .= sprintf("The remote server returned a \"%d %s\" error for the following transaction:\n\n",
$response->getStatusCode(), $response->getReasonPhrase());
$message .= sprintf(
"The remote server returned a \"%d %s\" error for the following transaction:\n\n",
$response->getStatusCode(),
$response->getReasonPhrase()
);

$message .= $this->header('Request');
$message .= trim($this->str($request)) . PHP_EOL . PHP_EOL;
Expand Down Expand Up @@ -163,8 +166,11 @@ public function userInputError(string $expectedType, $userValue, string $further
{
$message = $this->header('User Input Error');

$message .= sprintf("%s was expected, but the following value was passed in:\n\n%s\n",
$expectedType, print_r($userValue, true));
$message .= sprintf(
"%s was expected, but the following value was passed in:\n\n%s\n",
$expectedType,
print_r($userValue, true)
);

$message .= "Please ensure that the value adheres to the expectation above. ";

Expand Down
3 changes: 2 additions & 1 deletion src/Common/Service/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ private function mergeOptions(array $serviceOptions): array

if (!isset($options['identityService']) || !($options['identityService'] instanceof IdentityService)) {
throw new \InvalidArgumentException(sprintf(
'"identityService" must be specified and implement %s', IdentityService::class
'"identityService" must be specified and implement %s',
IdentityService::class
));
}

Expand Down
3 changes: 2 additions & 1 deletion src/Common/Transport/JsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ private function serializeObjectValue($value)
} elseif (!($value instanceof \stdClass)) {
throw new \InvalidArgumentException(sprintf(
'When an object value is provided, it must either be \stdClass or implement the Serializable '
. 'interface, you provided %s', print_r($value, true)
. 'interface, you provided %s',
print_r($value, true)
));
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Identity/v2/Models/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public function getServiceUrl(

throw new \RuntimeException(sprintf(
"Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
$serviceName, $serviceType, $region, $urlType
$serviceName,
$serviceType,
$region,
$urlType
));
}
}
5 changes: 4 additions & 1 deletion src/Identity/v3/Models/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function getServiceUrl(string $name, string $type, string $region, string

throw new \RuntimeException(sprintf(
"Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s",
$name, $type, $region, $urlType
$name,
$type,
$region,
$urlType
));
}
}
9 changes: 7 additions & 2 deletions src/Identity/v3/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ public function authenticate(array $options): array
return [$token, $baseUrl];
}

throw new \RuntimeException(sprintf("No service found with type [%s] name [%s] region [%s] interface [%s]",
$type, $name, $region, $interface));
throw new \RuntimeException(sprintf(
"No service found with type [%s] name [%s] region [%s] interface [%s]",
$type,
$name,
$region,
$interface
));
}

/**
Expand Down
18 changes: 16 additions & 2 deletions src/ObjectStore/v1/Models/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,22 @@ public function getPublicUri(): Uri
*/
public function create(array $data): Creatable
{
$response = $this->execute($this->api->putObject(), $data + ['containerName' => $this->containerName]);
return $this->populateFromResponse($response);
// Override containerName from input params only if local instance contains containerName attr
if ($this->containerName) {
$data['containerName'] = $this->containerName;
}

$response = $this->execute($this->api->putObject(), $data);
$storageObject = $this->populateFromResponse($response);

// Repopulate data for this newly created object instance
// due to the response from API does not contain object name and containerName
$storageObject = $storageObject->populateFromArray([
'name' => $data['name'],
'containerName' => $data['containerName']
]);

return $storageObject;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/ObjectStore/v1/Fixtures/GET_Container.resp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Date: Wed, 15 Jan 2014 16:57:35 GMT
"hash": "ed076287532e86365e841e92bfc50d8c",
"last_modified": "2014-01-15T16:37:43.427570",
"bytes": 12,
"name": "helloworld",
"content_type": "application/octet-stream"
"name": "helloworld.json",
"content_type": "application/json"
}
]
39 changes: 36 additions & 3 deletions tests/unit/ObjectStore/v1/Models/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function test_It_Create_Objects()

$this->setupMock('PUT', self::NAME . '/' . $objectName, $content, $headers, 'Created');

$this->container->createObject([
/** @var Object $storageObject */
$storageObject = $this->container->createObject([
'name' => $objectName,
'content' => $content,
'contentType' => $headers['Content-Type'],
Expand All @@ -125,6 +126,9 @@ public function test_It_Create_Objects()
'deleteAfter' => $headers['X-Delete-After'],
'metadata' => ['Author' => 'foo', 'genre' => 'bar'],
]);

$this->assertEquals('foo.txt', $storageObject->name);
$this->assertEquals(self::NAME, $storageObject->containerName);
}

public function test_it_lists_objects()
Expand All @@ -134,8 +138,37 @@ public function test_it_lists_objects()
->shouldBeCalled()
->willReturn($this->getFixture('GET_Container'));

foreach ($this->container->listObjects(['limit' => 2]) as $object) {
$this->assertInstanceOf(Object::class, $object);
$objects = iterator_to_array($this->container->listObjects(['limit' => 2]));

$this->assertEquals(2, count($objects));

$expected = [
[
'name' => 'goodbye',
'contentLength' => '14',
'lastModified' => new \DateTimeImmutable('2014-01-15T16:41:49.390270'),
'contentType' => 'application/octet-stream',
'hash' => '451e372e48e0f6b1114fa0724aa79fa1'
],
[
'name' => 'helloworld.json',
'contentLength' => '12',
'lastModified' => new \DateTimeImmutable('2014-01-15T16:37:43.427570'),
'contentType' => 'application/json',
'hash' => 'ed076287532e86365e841e92bfc50d8c'
],
];

for ($i = 0; $i < count($objects); $i++)
{
$exp = $expected[$i];
/** @var Object $obj */
$obj = $objects[$i];

foreach ($exp as $attr => $attrVal)
{
$this->assertEquals($attrVal, $obj->{$attr});
}
}
}

Expand Down