Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from cedricziel/issue-12
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricziel authored Feb 2, 2021
2 parents 9fb4811 + a112f21 commit 8d5a31e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ composer.lock

.php_cs.cache
.php_cs

.phpunit.result.cache
9 changes: 0 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,4 @@
<directory>tests</directory>
</testsuite>
</testsuites>

<filter processUncoveredFilesFromWhitelist="true">
<whitelist>
<directory suffix=".php">src</directory>
<exclude>
<directory>tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
4 changes: 1 addition & 3 deletions src/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,7 @@ public function getVisibility($path)
*/
public function getUrl($path)
{
$path = $this->applyPathPrefix($path);

return implode('/', [$this->baseUrl, $path]);
return sprintf('%s/%s', rtrim($this->baseUrl, '/'), ltrim($path, '/'));
}

/**
Expand Down
Binary file removed test-key.json.enc
Binary file not shown.
42 changes: 41 additions & 1 deletion tests/GoogleCloudStorageAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function testDeletingNonExistentObjectsWillNotFail(): void

public function testPrefixesCanBeUsed(): void
{
$testId = uniqid();
$testId = uniqid('', true);
$testPrefix = "my/prefix/testPrefixesCanBeUsed-{$testId}/";

$simpleConfig = new Config([]);
Expand Down Expand Up @@ -473,4 +473,44 @@ public function bucketPrefixDataProvider()
['my-bucket/prefix/in/bucket/', '/bar/baz.txt', GoogleCloudStorageAdapter::GCS_BASE_URL.'/my-bucket/prefix/in/bucket/bar/baz.txt'],
];
}

/**
* @see https://github.com/cedricziel/flysystem-gcs/issues/12
*
* @covers \CedricZiel\FlysystemGcs\GoogleCloudStorageAdapter::getUrl()
*/
public function testPrefixIsNotAddedTwiceForUrl(): void
{
$testId = uniqid('', true);
$adapterConfig = [
'bucket' => $this->bucket,
'projectId' => $this->project,
'prefix' => sprintf('icon-%s', $testId),
];

$adapter = new GoogleCloudStorageAdapter(null, $adapterConfig);
$url = $adapter->getUrl('test.txt');

self::assertEquals(sprintf('%s/%s/%s/test.txt', GoogleCloudStorageAdapter::GCS_BASE_URL, $adapterConfig['bucket'], $adapterConfig['prefix']), $url);
}

/**
* @see https://github.com/cedricziel/flysystem-gcs/issues/12
*
* @covers \CedricZiel\FlysystemGcs\GoogleCloudStorageAdapter::getUrl()
*/
public function testUrlCanBeCreated(): void
{
$testId = uniqid('', true);
$adapterConfig = [
'bucket' => $this->bucket,
'projectId' => $this->project,
];

$adapter = new GoogleCloudStorageAdapter(null, $adapterConfig);
$objectName = sprintf('%s/test.txt', sprintf('icon-%s', $testId));
$url = $adapter->getUrl($objectName);

self::assertEquals(sprintf('%s/%s/%s', GoogleCloudStorageAdapter::GCS_BASE_URL, $adapterConfig['bucket'], $objectName), $url);
}
}

0 comments on commit 8d5a31e

Please sign in to comment.