Skip to content

Commit

Permalink
Merge pull request #21 from mcrumm/storage_connection_uri_expansion
Browse files Browse the repository at this point in the history
Fix array to string conversion in REST::sendRequest()
  • Loading branch information
dwsupplee committed Mar 9, 2016
2 parents 9431369 + b38d440 commit ef69161
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Storage/Connection/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function uploadObject(array $options = [])
private function loadServiceDefinition()
{
return json_decode(
file_get_contents('ServiceDefinition/storage-v1.json', true),
file_get_contents(__DIR__ . '/ServiceDefinition/storage-v1.json', true),
true
);
}
Expand All @@ -240,7 +240,7 @@ private function sendRequest($resource, $method, $options)
{
// @todo quick POC. need to tighten this up
$action = $this->service[$resource]['methods'][$method];
$template = new UriTemplate();
$template = new UriTemplate(self::BASE_URI);
$path = [];
$query = [];
$body = [];
Expand All @@ -260,7 +260,7 @@ private function sendRequest($resource, $method, $options)
}

$uri = $this->buildUri(
$template->expand($action['path'], self::BASE_URI . $path),
$template->expand($action['path'], $path),
$query
);

Expand Down
39 changes: 39 additions & 0 deletions tests/Storage/Connection/RESTTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* Copyright 2015 Google Inc.
*
* 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 Google\Gcloud\Tests\Storage\Connection;

use Google\Gcloud\HttpRequestWrapper;
use Google\Gcloud\Storage\Connection\REST;
use Psr\Http\Message\ResponseInterface;

class RESTTest extends \PHPUnit_Framework_TestCase
{
public function testGetObjectReturnsResponseArray()
{
$response = $this->getMock(ResponseInterface::class);
$response->method('getBody')->willReturn('{"name": "foo.txt"}');

$wrapper = $this->getMock(HttpRequestWrapper::class);
$wrapper->method('send')->willReturn($response);

$object = (new REST($wrapper))->getObject();

$this->assertEquals(['name' => 'foo.txt'], $object);
}
}

0 comments on commit ef69161

Please sign in to comment.