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

Commit

Permalink
add support for using a custom auth cache with the google cloud adapt…
Browse files Browse the repository at this point in the history
…er (#10)
  • Loading branch information
matthewgoslett authored Jul 3, 2017
1 parent df9d48b commit 3daa9e7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.5 - 2017-07-03

* Add support for using a custom auth cache with the Google Cloud adapter

## 2.0.4 - 2017-05-24

* Add support for HTTP adapter
Expand Down
1 change: 1 addition & 0 deletions config/pubsub.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'client_identifier' => null,
'auto_create_topics' => true,
'auto_create_subscriptions' => true,
'auth_cache' => null, // eg: \Google\Auth\Cache\MemoryCacheItemPool::class,
],

'http' => [
Expand Down
4 changes: 4 additions & 0 deletions src/PubSubConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ protected function makeGoogleCloudAdapter(array $config)
'projectId' => $config['project_id'],
'keyFilePath' => $config['key_file'],
];
if (isset($config['auth_cache'])) {
$clientConfig['authCache'] = $this->container->make($config['auth_cache']);
}

$client = $this->container->makeWith('pubsub.gcloud.pub_sub_client', ['config' => $clientConfig]);

$clientIdentifier = array_get($config, 'client_identifier');
Expand Down
34 changes: 34 additions & 0 deletions tests/PubSubConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use InvalidArgumentException;
use Mockery;
use Predis\Client as RedisClient;
use Psr\Cache\CacheItemPoolInterface;
use Superbalist\LaravelPubSub\PubSubConnectionFactory;
use Superbalist\PubSub\Adapters\DevNullPubSubAdapter;
use Superbalist\PubSub\Adapters\LocalPubSubAdapter;
Expand Down Expand Up @@ -179,6 +180,39 @@ public function testMakeGoogleCloudAdapter()
$this->assertTrue($adapter->areSubscriptionsAutoCreated());
}

public function testMakeGoogleCloudAdapterWithAuthCache()
{
$cacheImplementation = Mockery::mock(CacheItemPoolInterface::class);

$container = Mockery::mock(Container::class);
$container->shouldReceive('make')
->with('MyPSR6CacheImplementation::class')
->andReturn($cacheImplementation);
$container->shouldReceive('makeWith')
->withArgs([
'pubsub.gcloud.pub_sub_client',
[
'config' => [
'projectId' => 12345,
'keyFilePath' => 'my_key_file.json',
'authCache' => $cacheImplementation,
],
],
])
->andReturn(Mockery::mock(GoogleCloudPubSubClient::class));

$factory = new PubSubConnectionFactory($container);

$config = [
'project_id' => '12345',
'key_file' => 'my_key_file.json',
'auth_cache' => 'MyPSR6CacheImplementation::class',
];

$adapter = $factory->make('gcloud', $config);
$this->assertInstanceOf(GoogleCloudPubSubAdapter::class, $adapter);
}

public function testMakeHTTPAdapter()
{
$container = Mockery::mock(Container::class);
Expand Down

0 comments on commit 3daa9e7

Please sign in to comment.