Skip to content

Commit

Permalink
Merge pull request #2 from geekcom/develop
Browse files Browse the repository at this point in the history
update sendMessage method, update tests
  • Loading branch information
geekcom authored Nov 5, 2019
2 parents b4c5fe6 + 26aaa5a commit 7094bab
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .felicio.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AWS_SQS_ACCESS_KEY=
AWS_SQS_SECRET_KEY=
AWS_SQS_REGION=
AWS_SQS_REGION=
AWS_SQS_API_VERSION=latest
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ services:
container_name: felicio
volumes:
- .:/var/www/app
environment:
- XDEBUG_ENABLED=true
tty: true
18 changes: 12 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ _A simple AWS SQS Messages with PHP_

## About Felicio and SQS

Felicio is a simple library to send and receive(_coming soon_) [AWS SQS Messages](https://aws.amazon.com/pt/sqs/).
Felicio is a simple library to manipulate [AWS SQS Messages](https://aws.amazon.com/pt/sqs/).

- Simple.
- Configurable.
- Testable.
- Simple;
- Configurable;
- Testable;
- Open source.

[Amazon Simple Queue Service (SQS)](https://aws.amazon.com/pt/sqs/) is a fully managed message queuing service
Expand Down Expand Up @@ -49,6 +49,7 @@ Rename `.felicio.example` to `.felicio` and fill in the correct information abou
AWS_SQS_ACCESS_KEY=
AWS_SQS_SECRET_KEY=
AWS_SQS_REGION=
AWS_SQS_API_VERSION=latest
```

## Send a message
Expand All @@ -61,7 +62,12 @@ $felicioDotFile = __DIR__ . '/.felicio';

$felicio = new Felicio($felicioDotFile);

$felicio->sendMessage('https://sqs.us-west-2.amazonaws.com/000/my_queue', 'message');
$params = [
'QueueUrl' => 'https://sqs.us-west-2.amazonaws.com/999999999/my_queue',
'MessageBody' => 'test message'
];

$felicio->sendMessage($params);
```

## Contributing
Expand All @@ -74,4 +80,4 @@ The Felicio library is open-source software licensed under the [MIT license](htt

## [Questions?](https://github.com/felicio/issues)

Open a new [Issue](https://github.com/felicio/issues) or look for a closed issue
Open a new [Issue](https://github.com/felicio/issues) or look for a closed issue
2 changes: 1 addition & 1 deletion src/Contracts/FelicioContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface FelicioContract
{
public function sendMessage($queueURl, $messageBody);
public function sendMessage(array $params);
}
36 changes: 21 additions & 15 deletions src/Felicio.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
<?php

declare(strict_types=1);

namespace Felicio;

use Felicio\Contracts\FelicioContract;
use Aws\Sqs\SqsClient;
use Aws\Sdk;
use Aws\Credentials\Credentials;
use Aws\Exception\AwsException;
use Symfony\Component\Dotenv\Dotenv;

final class Felicio implements FelicioContract
{
protected $felicioClient;

public function __construct($dotFelicioFile)
public function __construct($felicioDotFile)
{
$dotenv = new Dotenv();
$dotenv->load($dotFelicioFile);
$dotenv->load($felicioDotFile);

$credentials = new Credentials(
$_ENV['AWS_SQS_ACCESS_KEY'],
$_ENV['AWS_SQS_SECRET_KEY']
);

$this->felicioClient = SqsClient::factory([
'credentials' => [
'key' => $_ENV['AWS_SQS_ACCESS_KEY'],
'secret' => $_ENV['AWS_SQS_SECRET_KEY']
],
$configs = [
'credentials' => $credentials,
'region' => $_ENV['AWS_SQS_REGION'],
'version' => 'latest'
]);
'version' => $_ENV['AWS_SQS_API_VERSION'],
];

$sdk = new Sdk($configs);

$this->felicioClient = $sdk->createSqs();
}

public function sendMessage($queueURl, $messageBody)
public function sendMessage(array $params): void
{
try {
$this->felicioClient->sendMessage([
'QueueUrl' => $queueURl,
'MessageBody' => $messageBody,
]);
$this->felicioClient->sendMessage($params);
} catch (AwsException $e) {
throw new AwsException();
}
Expand Down
20 changes: 10 additions & 10 deletions tests/FelicioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@

use Felicio\Felicio;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Dotenv\Dotenv;
use ArgumentCountError;

final class FelicioTest Extends TestCase
{
private $instance;

private $env;

public function setUp(): void
{
$this->env = new Dotenv();
$this->instance = new Felicio();

$this->env->load(__DIR__ . '/../.felicio');
$this->instance = new Felicio(__DIR__ . '/../.felicio');
}

public function testSendMessageWithoutParameters()
public function testSendMessageWithoutRequiredParameters()
{
$this->expectException(\ArgumentCountError::class);
$this->expectException(ArgumentCountError::class);

$params = [
'QueueUrl' => '',
'MessageBody' => ''
];

$this->instance->sendMessage('', '');
$this->instance->sendMessage($params);
}
}

0 comments on commit 7094bab

Please sign in to comment.