Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 3daa9e7

Browse files
add support for using a custom auth cache with the google cloud adapter (#10)
1 parent df9d48b commit 3daa9e7

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.0.5 - 2017-07-03
4+
5+
* Add support for using a custom auth cache with the Google Cloud adapter
6+
37
## 2.0.4 - 2017-05-24
48

59
* Add support for HTTP adapter

config/pubsub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
'client_identifier' => null,
6060
'auto_create_topics' => true,
6161
'auto_create_subscriptions' => true,
62+
'auth_cache' => null, // eg: \Google\Auth\Cache\MemoryCacheItemPool::class,
6263
],
6364

6465
'http' => [

src/PubSubConnectionFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ protected function makeGoogleCloudAdapter(array $config)
115115
'projectId' => $config['project_id'],
116116
'keyFilePath' => $config['key_file'],
117117
];
118+
if (isset($config['auth_cache'])) {
119+
$clientConfig['authCache'] = $this->container->make($config['auth_cache']);
120+
}
121+
118122
$client = $this->container->makeWith('pubsub.gcloud.pub_sub_client', ['config' => $clientConfig]);
119123

120124
$clientIdentifier = array_get($config, 'client_identifier');

tests/PubSubConnectionFactoryTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use InvalidArgumentException;
99
use Mockery;
1010
use Predis\Client as RedisClient;
11+
use Psr\Cache\CacheItemPoolInterface;
1112
use Superbalist\LaravelPubSub\PubSubConnectionFactory;
1213
use Superbalist\PubSub\Adapters\DevNullPubSubAdapter;
1314
use Superbalist\PubSub\Adapters\LocalPubSubAdapter;
@@ -179,6 +180,39 @@ public function testMakeGoogleCloudAdapter()
179180
$this->assertTrue($adapter->areSubscriptionsAutoCreated());
180181
}
181182

183+
public function testMakeGoogleCloudAdapterWithAuthCache()
184+
{
185+
$cacheImplementation = Mockery::mock(CacheItemPoolInterface::class);
186+
187+
$container = Mockery::mock(Container::class);
188+
$container->shouldReceive('make')
189+
->with('MyPSR6CacheImplementation::class')
190+
->andReturn($cacheImplementation);
191+
$container->shouldReceive('makeWith')
192+
->withArgs([
193+
'pubsub.gcloud.pub_sub_client',
194+
[
195+
'config' => [
196+
'projectId' => 12345,
197+
'keyFilePath' => 'my_key_file.json',
198+
'authCache' => $cacheImplementation,
199+
],
200+
],
201+
])
202+
->andReturn(Mockery::mock(GoogleCloudPubSubClient::class));
203+
204+
$factory = new PubSubConnectionFactory($container);
205+
206+
$config = [
207+
'project_id' => '12345',
208+
'key_file' => 'my_key_file.json',
209+
'auth_cache' => 'MyPSR6CacheImplementation::class',
210+
];
211+
212+
$adapter = $factory->make('gcloud', $config);
213+
$this->assertInstanceOf(GoogleCloudPubSubAdapter::class, $adapter);
214+
}
215+
182216
public function testMakeHTTPAdapter()
183217
{
184218
$container = Mockery::mock(Container::class);

0 commit comments

Comments
 (0)