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 composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pod-point/laravel-aws-pubsub",
"description": "A Laravel broadcasting driver and queue driver that broadcasts and listens to events published to AWS SNS and SQS.",
"description": "A Laravel broadcasting driver and queue driver that broadcasts and listens to published events utilising AWS SNS, EventBridge and SQS.",
"keywords": ["laravel", "broadcasting", "broadcast", "queue", "listeners", "pubsub", "aws", "sns", "sqs"],
"homepage": "https://github.com/pod-point/laravel-aws-pubsub",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static function prepareConfigurationCredentials(array $config): array
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'));
&& Arr::get($config, 'key')
&& Arr::get($config, 'secret');
}
}
130 changes: 130 additions & 0 deletions tests/EventServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace PodPoint\AwsPubSub\Tests;

use PodPoint\AwsPubSub\EventServiceProvider;

class EventServiceProviderTest extends TestCase
{
/** @test */
public function it_can_prepare_configuration_credentials()
{
$config = EventServiceProvider::prepareConfigurationCredentials([
'foo' => 'bar',
'key' => 'some_key',
'secret' => 'some_secret',
]);

$this->assertEquals([
'foo' => 'bar',
'key' => 'some_key',
'secret' => 'some_secret',
'credentials' => [
'key' => 'some_key',
'secret' => 'some_secret',
],
], $config);
}

/** @test */
public function it_can_prepare_configuration_credentials_with_a_token()
{
$config = EventServiceProvider::prepareConfigurationCredentials([
'foo' => 'bar',
'key' => 'some_key',
'secret' => 'some_secret',
'token' => 'some_token',
]);

$this->assertEquals([
'foo' => 'bar',
'key' => 'some_key',
'secret' => 'some_secret',
'token' => 'some_token',
'credentials' => [
'key' => 'some_key',
'secret' => 'some_secret',
'token' => 'some_token',
],
], $config);
}

/** @test */
public function it_can_make_sure_some_aws_credentials_are_provided_before_preparing_the_credentials()
{
$config = EventServiceProvider::prepareConfigurationCredentials([
'foo' => 'bar',
'token' => 'some_token',
]);

$this->assertArrayNotHasKey('credentials', $config);
}

public function invalidCredentialsDataProvider()
{
return [
'key_is_empty' => [
'creds' => [
'key' => '',
'secret' => 'some_secret',
],
],
'secret_is_empty' => [
'creds' => [
'key' => 'some_key',
'secret' => '',
],
],
'key_and_secret_are_empty' => [
'creds' => [
'key' => '',
'secret' => '',
],
],
'key_is_null' => [
'creds' => [
'key' => null,
'secret' => 'some_secret',
],
],
'secret_is_null' => [
'creds' => [
'key' => 'some_key',
'secret' => null,
],
],
'key_and_secret_are_null' => [
'creds' => [
'key' => null,
'secret' => null,
],
],
'key_is_empty_and_secret_is_null' => [
'creds' => [
'key' => '',
'secret' => null,
],
],
'key_is_null_and_secret_is_empty' => [
'creds' => [
'key' => null,
'secret' => '',
],
],
];
}

/**
* @test
* @dataProvider invalidCredentialsDataProvider
*/
public function it_can_make_sure_some_aws_credentials_are_provided_and_valid(array $invalidCredentials)
{
$config = EventServiceProvider::prepareConfigurationCredentials(array_merge([
'foo' => 'bar',
], $invalidCredentials));

$this->assertArrayHasKey('foo', $config);
$this->assertArrayNotHasKey('credentials', $config);
}
}