Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer require "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress
composer update --prefer-dist --no-interaction --no-progress --no-plugins

- name: Execute tests
run: vendor/bin/phpunit
25 changes: 18 additions & 7 deletions src/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function registerSnsBroadcaster()
* @param array $config
* @return \Illuminate\Contracts\Broadcasting\Broadcaster
*/
protected function createSnsDriver(array $config): \Illuminate\Contracts\Broadcasting\Broadcaster
public function createSnsDriver(array $config): \Illuminate\Contracts\Broadcasting\Broadcaster
{
$config = self::prepareConfigurationCredentials($config);

Expand Down Expand Up @@ -81,9 +81,7 @@ protected function registerEventBridgeBroadcaster()
{
$this->app->resolving(BroadcastManager::class, function (BroadcastManager $manager) {
$manager->extend('eventbridge', function (Container $app, array $config) {
return $this->createEventBridgeDriver(array_merge($config, [
'version' => '2015-10-07',
]));
return $this->createEventBridgeDriver($config);
});
});
}
Expand All @@ -94,12 +92,12 @@ protected function registerEventBridgeBroadcaster()
* @param array $config
* @return \Illuminate\Contracts\Broadcasting\Broadcaster
*/
protected function createEventBridgeDriver(array $config): \Illuminate\Contracts\Broadcasting\Broadcaster
public function createEventBridgeDriver(array $config): \Illuminate\Contracts\Broadcasting\Broadcaster
{
$config = self::prepareConfigurationCredentials($config);

return new EventBridgeBroadcaster(
new EventBridgeClient($config),
new EventBridgeClient(array_merge($config, ['version' => '2015-10-07'])),
$config['source'] ?? ''
);
}
Expand All @@ -112,10 +110,23 @@ protected function createEventBridgeDriver(array $config): \Illuminate\Contracts
*/
public static function prepareConfigurationCredentials(array $config): array
{
if (Arr::has($config, ['key', 'secret'])) {
if (static::configHasCredentials($config)) {
$config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);
}

return $config;
}

/**
* Make sure some AWS credentials were provided to the configuration array.
*
* @param array $config
* @return bool

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this JavaDoc string, can you type the input argument as well?

Copy link
Contributor

@oaklees oaklees Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's PHPDoc, which I guess is pretty much the same. We could indeed add @param array $config - for consistency, but believe we just took the code that was added as part of the PR to bring this functionality into the 0.4 branch.

Could we also bring in over the EventBridgeBroadcasterTest and SnsBroadcasterTest?

*/
private static function configHasCredentials(array $config): bool
{
return Arr::has($config, ['key', 'secret'])
&& is_string(Arr::get($config, 'key'))
&& is_string(Arr::get($config, 'secret'));
}
}
53 changes: 53 additions & 0 deletions tests/Pub/Broadcasting/Broadcasters/EventBridgeBroadcasterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace PodPoint\AwsPubSub\Tests\Pub\Broadcasting\Broadcasters;

use PodPoint\AwsPubSub\EventServiceProvider;
use PodPoint\AwsPubSub\Pub\Broadcasting\Broadcasters\EventBridgeBroadcaster;
use PodPoint\AwsPubSub\Tests\TestCase;

class EventBridgeBroadcasterTest extends TestCase
{
/** @test */
public function it_can_instantiate_the_broadcaster()
{
$broadcaster = (new EventServiceProvider($this->app))->createEventBridgeDriver([
'driver' => 'eventbridge',
'key' => 'dummy-key',
'secret' => 'dummy-secret',
'region' => 'eu-west-1',
'event_bus' => 'default',
'source' => 'my-app',
]);

$this->assertInstanceOf(EventBridgeBroadcaster::class, $broadcaster);
}

/** @test */
public function it_supports_optional_aws_credentials()
{
$broadcaster = (new EventServiceProvider($this->app))->createEventBridgeDriver([
'driver' => 'eventbridge',
'region' => 'eu-west-1',
'event_bus' => 'default',
'source' => 'my-app',
]);

$this->assertInstanceOf(EventBridgeBroadcaster::class, $broadcaster);
}

/** @test */
public function it_supports_null_aws_credentials()
{
$broadcaster = (new EventServiceProvider($this->app))->createEventBridgeDriver([
'driver' => 'eventbridge',
'key' => null,
'secret' => null,
'region' => 'eu-west-1',
'event_bus' => 'default',
'source' => 'my-app',
]);

$this->assertInstanceOf(EventBridgeBroadcaster::class, $broadcaster);
}
}
53 changes: 53 additions & 0 deletions tests/Pub/Broadcasting/Broadcasters/SnsBroadcasterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace PodPoint\AwsPubSub\Tests\Pub\Broadcasting\Broadcasters;

use PodPoint\AwsPubSub\EventServiceProvider;
use PodPoint\AwsPubSub\Pub\Broadcasting\Broadcasters\SnsBroadcaster;
use PodPoint\AwsPubSub\Tests\Pub\Concerns\InteractsWithSns;
use PodPoint\AwsPubSub\Tests\TestCase;

class SnsBroadcasterTest extends TestCase
{
use InteractsWithSns;

/** @test */
public function it_can_instantiate_the_broadcaster()
{
$broadcaster = (new EventServiceProvider($this->app))->createSnsDriver([
'driver' => 'sns',
'key' => 'dummy-key',
'secret' => 'dummy-secret',
'arn-prefix' => 'aws:arn:12345:',
'region' => 'eu-west-1',
]);

$this->assertInstanceOf(SnsBroadcaster::class, $broadcaster);
}

/** @test */
public function it_supports_optional_aws_credentials()
{
$broadcaster = (new EventServiceProvider($this->app))->createSnsDriver([
'driver' => 'sns',
'arn-prefix' => 'aws:arn:12345:',
'region' => 'eu-west-1',
]);

$this->assertInstanceOf(SnsBroadcaster::class, $broadcaster);
}

/** @test */
public function it_supports_null_aws_credentials()
{
$broadcaster = (new EventServiceProvider($this->app))->createSnsDriver([
'driver' => 'sns',
'key' => null,
'secret' => null,
'arn-prefix' => 'aws:arn:12345:',
'region' => 'eu-west-1',
]);

$this->assertInstanceOf(SnsBroadcaster::class, $broadcaster);
}
}