1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gaufrette\Functional\Adapter; |
4
|
|
|
|
5
|
|
|
use Gaufrette\Adapter\GCS\GCS; |
6
|
|
|
use Gaufrette\Filesystem; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Functional tests for the GoogleCloudStorage adapter. |
10
|
|
|
* |
11
|
|
|
* Copy the ../adapters/GoogleCloudStorage.php.dist to GoogleCloudStorage.php and |
12
|
|
|
* adapt to your needs. |
13
|
|
|
* |
14
|
|
|
* @author Patrik Karisch <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class GCSTest extends FunctionalTestCase |
17
|
|
|
{ |
18
|
|
|
public function setUp() |
19
|
|
|
{ |
20
|
|
|
$client = new \Google_Client(); |
21
|
|
|
$client->setApplicationName(getenv('GCS_APP_NAME')); |
22
|
|
|
$cred = $client->loadServiceAccountJson( |
23
|
|
|
getenv('GCS_ACCOUNT_JSON'), |
24
|
|
|
'https://www.googleapis.com/auth/devstorage.read_write' |
25
|
|
|
); |
26
|
|
|
$client->setAssertionCredentials($cred); |
27
|
|
|
|
28
|
|
|
$service = new \Google_Service_Storage($client); |
29
|
|
|
$this->filesystem = new Filesystem(new GCS($service, getenv('GCS_BUCKET'))); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @test |
34
|
|
|
* @group functional |
35
|
|
|
* |
36
|
|
|
* @expectedException \RuntimeException |
37
|
|
|
*/ |
38
|
|
|
public function shouldThrowExceptionIfBucketMissing() |
39
|
|
|
{ |
40
|
|
|
/** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */ |
41
|
|
|
$adapter = $this->filesystem->getAdapter(); |
42
|
|
|
$oldBucket = $adapter->getOptions(); |
43
|
|
|
$adapter->setBucket('Gaufrette-' . mt_rand()); |
44
|
|
|
|
45
|
|
|
$adapter->read('foo'); |
46
|
|
|
$adapter->setBucket($oldBucket); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @test |
51
|
|
|
* @group functional |
52
|
|
|
*/ |
53
|
|
|
public function shouldWriteAndReadWithDirectory() |
54
|
|
|
{ |
55
|
|
|
/** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */ |
56
|
|
|
$adapter = $this->filesystem->getAdapter(); |
57
|
|
|
$oldOptions = $adapter->getOptions(); |
58
|
|
|
$adapter->setOptions(array('directory' => 'Gaufrette')); |
59
|
|
|
|
60
|
|
|
$this->assertEquals(12, $this->filesystem->write('foo', 'Some content')); |
61
|
|
|
$this->assertEquals(13, $this->filesystem->write('test/subdir/foo', 'Some content1', true)); |
62
|
|
|
|
63
|
|
|
$this->assertEquals('Some content', $this->filesystem->read('foo')); |
64
|
|
|
$this->assertEquals('Some content1', $this->filesystem->read('test/subdir/foo')); |
65
|
|
|
|
66
|
|
|
$this->filesystem->delete('foo'); |
67
|
|
|
$this->filesystem->delete('test/subdir/foo'); |
68
|
|
|
$adapter->setOptions($oldOptions); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @test |
73
|
|
|
* @group functional |
74
|
|
|
*/ |
75
|
|
|
public function shouldSetMetadataCorrectly() |
76
|
|
|
{ |
77
|
|
|
/** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */ |
78
|
|
|
$adapter = $this->filesystem->getAdapter(); |
79
|
|
|
|
80
|
|
|
$adapter->setMetadata('metadata.txt', array( |
81
|
|
|
'CacheControl' => 'public, maxage=7200', |
82
|
|
|
'ContentDisposition' => 'attachment; filename="test.txt"', |
83
|
|
|
'ContentEncoding' => 'identity', |
84
|
|
|
'ContentLanguage' => 'en', |
85
|
|
|
'Colour' => 'Yellow', |
86
|
|
|
)); |
87
|
|
|
|
88
|
|
|
$this->assertEquals(12, $this->filesystem->write('metadata.txt', 'Some content', true)); |
89
|
|
|
|
90
|
|
|
$reflectionObject = new \ReflectionObject($adapter); |
91
|
|
|
$reflectionMethod = $reflectionObject->getMethod('getObjectData'); |
92
|
|
|
$reflectionMethod->setAccessible(true); |
93
|
|
|
$metadata = $reflectionMethod->invoke($adapter, array('metadata.txt')); |
94
|
|
|
|
95
|
|
|
$this->assertEquals('public, maxage=7200', $metadata->cacheControl); |
96
|
|
|
$this->assertEquals('attachment; filename="test.txt"', $metadata->contentDisposition); |
97
|
|
|
$this->assertEquals('identity', $metadata->contentEncoding); |
98
|
|
|
$this->assertEquals('en', $metadata->contentLanguage); |
99
|
|
|
$this->assertEquals(array( |
100
|
|
|
'Colour' => 'Yellow', |
101
|
|
|
), $metadata->metadata); |
102
|
|
|
|
103
|
|
|
$this->filesystem->delete('metadata.txt'); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: