diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9a37427..ab2c878 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,11 +8,8 @@ jobs: strategy: fail-fast: true matrix: - php: [ 7.4, 8.0 ] + php: [ 7.3, 8.0 ] laravel: [ 8.* ] - include: - - laravel: 8.* - testbench: 6.* name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} @@ -35,7 +32,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update composer update --prefer-dist --no-interaction --no-progress - name: Execute tests diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb0d31..0fe5bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog -All notable changes to `laravel-sns-broadcast-driver` will be documented in this file. +All notable changes to `laravel-sns-broadcaster` will be documented in this file. -## 0.1.0 - 2021-06-30 +## 0.1.0 - 2021-07-13 -- first release +- First release supporting PHP7.3+ and Laravel 8+ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b4ae1c4..e5da36d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,8 +38,6 @@ Before submitting a pull request: ## Requirements -If the project maintainer has any additional requirements, you will find them listed here. - - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). - **Add tests!** - Your patch won't be accepted if it doesn't have tests. diff --git a/README.md b/README.md index b0fa9e8..8686370 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# Laravel SNS Broadcaster +# Laravel 8 SNS Broadcaster -[![Latest Version on Packagist](https://img.shields.io/packagist/v/pod-point/laravel-sns-broadcast-driver.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-sns-broadcast-driver) -![GitHub Workflow Status](https://img.shields.io/github/workflow/status/pod-point/laravel-sns-broadcast-driver/run-tests?label=tests) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/pod-point/laravel-sns-broadcaster.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-sns-broadcaster) +![GitHub Workflow Status](https://img.shields.io/github/workflow/status/pod-point/laravel-sns-broadcaster/run-tests?label=tests) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) -[![Total Downloads](https://img.shields.io/packagist/dt/pod-point/laravel-sns-broadcast-driver.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-sns-broadcast-driver) +[![Total Downloads](https://img.shields.io/packagist/dt/pod-point/laravel-sns-broadcaster.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-sns-broadcaster) This package adds support for broadcasting events via SNS (Simple Notification Service). @@ -27,7 +27,7 @@ Add the sns driver to `config/broadcasting.php` in the `connections` array: ], ``` -Update the `.env` to use the driver and add the AWS values: +Update your `.env` to use the driver and add the AWS values: ```dotenv BROADCAST_DRIVER=sns @@ -74,7 +74,7 @@ public function broadcastOn($event) By default, the package will publish the default Laravel payload, but you can transform the data that is published by transforming the data using `broadcastWith`. -Here you, can define exactly what payload gets published. +Here you can define exactly what payload gets published. The `broadcastWith()` method receives an `$event` parameter that specifies the type of action performed, e.g. created. @@ -98,11 +98,11 @@ public function broadcastWith($event) #### Defining which actions are publishable -By default, the following actions performed on a Model will be published: +By default, the following actions performed on a Model will be published: -`created`, `updated`, `deleted` and if soft delete is enabled, `trashed`, `restored`. +`created`, `updated`, `deleted` and if soft delete is enabled: `trashed`, `restored`. -To only publish specific actions from the list above, add a `broadcastEvents` method the model and define an array of the publishable actions: +To only publish specific actions from the list above, add a `broadcastEvents` method to the model and define an array of the publishable actions: ```injectablephp /** @@ -116,7 +116,7 @@ public function broadcastEvents() } ``` -Now, only the created and updated events for this Model will be published. +Now only the created and updated events for this Model will be published. ### Custom Events @@ -146,6 +146,7 @@ public function broadcastOn() ``` #### Customizing the published data + By default, all public properties on the Event will be added to the payload that is published. Unlike a Model Event, you will need to manually set an action as a public property to the Event if you wish to see it in the payload. @@ -246,9 +247,9 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Credits - [laravel-sns-broadcaster](https://github.com/maxgaurav/laravel-sns-broadcaster) for some inspiration -- [Laravel Package Development](https://laravelpackage.com) documentation by [John Braun](https://github.com/Jhnbrn90) +- [Laravel Package Development](https://laravelpackage.com) documentation by [John Braun](https://github.com/Jhnbrn90) - [Pod Point](https://github.com/pod-point) -- [All Contributors](https://github.com/pod-point/laravel-sns-broadcast-driver/graphs/contributors) +- [All Contributors](https://github.com/pod-point/laravel-sns-broadcaster/graphs/contributors) ## License diff --git a/composer.json b/composer.json index 05f0088..2be117c 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "pod-point/laravel-sns-broadcaster", "description": "A broadcast driver that allows broadcast events to be published to SNS.", "keywords": ["laravel", "sns", "broadcast"], - "homepage": "https://github.com/pod-point/laravel-sns-broadcast-driver", + "homepage": "https://github.com/pod-point/laravel-sns-broadcaster", "license": "MIT", "authors": [ { @@ -11,7 +11,7 @@ } ], "require": { - "php": "^7.4|^8.0", + "php": "^7.3|^8.0", "ext-json": "*", "illuminate/support": "^8.0", "aws/aws-sdk-php-laravel": "^3.6" diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..167e3f8 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,18 @@ + + + + + ./tests/ + + + diff --git a/src/BroadcastableModelEventOccurred.php b/src/BroadcastableModelEventOccurred.php index 3be13ab..082e3e5 100644 --- a/src/BroadcastableModelEventOccurred.php +++ b/src/BroadcastableModelEventOccurred.php @@ -11,7 +11,7 @@ class BroadcastableModelEventOccurred extends EloquentBroadcastableModelEventOcc * * @return array */ - public function broadcastWith() + public function broadcastWith(): array { return method_exists($this->model, 'broadcastWith') ? $this->model->broadcastWith($this->event) : [ 'model' => $this->model->toArray(), diff --git a/src/Broadcasters/SnsBroadcaster.php b/src/Broadcasters/SnsBroadcaster.php index d360977..4b612f0 100644 --- a/src/Broadcasters/SnsBroadcaster.php +++ b/src/Broadcasters/SnsBroadcaster.php @@ -11,12 +11,12 @@ class SnsBroadcaster extends Broadcaster /** * @var SnsClient */ - protected SnsClient $snsClient; + protected $snsClient; /** * @var string */ - protected string $arnPrefix; + protected $arnPrefix; /** * SnsBroadcaster constructor. @@ -31,11 +31,12 @@ public function __construct(string $arnPrefix) /** * @inheritDoc - * @param array $channels - * @param $event - * @param array $payload + * @param array $channels + * @param string $event + * @param array $payload + * @return void */ - public function broadcast(array $channels, $event, array $payload = []) + public function broadcast(array $channels, $event, array $payload = []): void { $this->snsClient->publish([ 'TopicArn' => $this->topicName($channels), diff --git a/src/BroadcastsEvents.php b/src/BroadcastsEvents.php index 9a3c18e..ac691ab 100644 --- a/src/BroadcastsEvents.php +++ b/src/BroadcastsEvents.php @@ -37,12 +37,12 @@ public function newBroadcastableModelEvent($event) /** * Broadcast the given event instance if channels are configured for the model event. * - * @param mixed $instance - * @param string $event - * @param mixed $channels + * @param mixed $instance + * @param string $event + * @param mixed $channels * @return \Illuminate\Broadcasting\PendingBroadcast|null|void */ - protected function broadcastIfBroadcastChannelsExistForEvent($instance, $event, $channels = null) + protected function broadcastIfBroadcastChannelsExistForEvent($instance, string $event, $channels = null) { if (in_array($event, $this->broadcastEvents())) { return $this->eloquentBroadcastIfBroadcastChannelsExistForEvent($instance, $event, $channels); @@ -54,7 +54,7 @@ protected function broadcastIfBroadcastChannelsExistForEvent($instance, $event, * * @return array */ - public function broadcastEvents() + public function broadcastEvents(): array { return ['created', 'updated', 'trashed', 'restored', 'deleted']; } diff --git a/src/SnsBroadcasterServiceProvider.php b/src/SnsBroadcasterServiceProvider.php index c8e1dc4..3b83e48 100644 --- a/src/SnsBroadcasterServiceProvider.php +++ b/src/SnsBroadcasterServiceProvider.php @@ -17,7 +17,7 @@ class SnsBroadcasterServiceProvider extends ServiceProvider * * @return void */ - public function register() + public function register(): void { $this->app->bind(EloquentBroadcastableModelEventOccurred::class, BroadcastableModelEventOccurred::class); } @@ -28,7 +28,7 @@ public function register() * @return void * @throws BindingResolutionException */ - public function boot() + public function boot(): void { $this->app->singleton(SnsClient::class, function () { $config = [ diff --git a/tests/Dummies/Events/UserRetrieved.php b/tests/Dummies/Events/UserRetrieved.php index 79998b1..d7e33bd 100644 --- a/tests/Dummies/Events/UserRetrieved.php +++ b/tests/Dummies/Events/UserRetrieved.php @@ -12,14 +12,14 @@ class UserRetrieved implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; - public string $action = 'RETRIEVED'; + public $action = 'RETRIEVED'; - public string $foo = 'bar'; + public $foo = 'bar'; /** * @var User */ - public User $user; + public $user; /** * Create a new event instance. diff --git a/tests/Dummies/Events/UserRetrievedWithBroadcastWith.php b/tests/Dummies/Events/UserRetrievedWithCustomPayload.php similarity index 89% rename from tests/Dummies/Events/UserRetrievedWithBroadcastWith.php rename to tests/Dummies/Events/UserRetrievedWithCustomPayload.php index 558ab6c..b0e10ee 100644 --- a/tests/Dummies/Events/UserRetrievedWithBroadcastWith.php +++ b/tests/Dummies/Events/UserRetrievedWithCustomPayload.php @@ -8,16 +8,16 @@ use Illuminate\Queue\SerializesModels; use PodPoint\SnsBroadcaster\Tests\Dummies\Models\User; -class UserRetrievedWithBroadcastWith implements ShouldBroadcast +class UserRetrievedWithCustomPayload implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; - public string $action = 'RETRIEVED'; + public $action = 'RETRIEVED'; /** * @var User */ - public User $user; + public $user; /** * Create a new event instance. diff --git a/tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastEvents.php b/tests/Dummies/Models/UserWithBroadcastingEventsForSpecificEvents.php similarity index 88% rename from tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastEvents.php rename to tests/Dummies/Models/UserWithBroadcastingEventsForSpecificEvents.php index bb0e753..ca8a93a 100644 --- a/tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastEvents.php +++ b/tests/Dummies/Models/UserWithBroadcastingEventsForSpecificEvents.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; use PodPoint\SnsBroadcaster\BroadcastsEvents; -class UserWithBroadcastingEventsWithBroadcastEvents extends Model +class UserWithBroadcastingEventsForSpecificEvents extends Model { use BroadcastsEvents; diff --git a/tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastWith.php b/tests/Dummies/Models/UserWithBroadcastingEventsWithCustomPayload.php similarity index 90% rename from tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastWith.php rename to tests/Dummies/Models/UserWithBroadcastingEventsWithCustomPayload.php index 5b10a4f..b2246ac 100644 --- a/tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastWith.php +++ b/tests/Dummies/Models/UserWithBroadcastingEventsWithCustomPayload.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; use PodPoint\SnsBroadcaster\BroadcastsEvents; -class UserWithBroadcastingEventsWithBroadcastWith extends Model +class UserWithBroadcastingEventsWithCustomPayload extends Model { use BroadcastsEvents; diff --git a/tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents.php b/tests/Dummies/Models/UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents.php similarity index 90% rename from tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents.php rename to tests/Dummies/Models/UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents.php index 7d29477..29995fe 100644 --- a/tests/Dummies/Models/UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents.php +++ b/tests/Dummies/Models/UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; use PodPoint\SnsBroadcaster\BroadcastsEvents; -class UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents extends Model +class UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents extends Model { use BroadcastsEvents; diff --git a/tests/Unit/CustomEventsTest.php b/tests/Unit/CustomEventsTest.php index 7bf307a..35620fa 100644 --- a/tests/Unit/CustomEventsTest.php +++ b/tests/Unit/CustomEventsTest.php @@ -5,7 +5,7 @@ use Aws\Sns\SnsClient; use Mockery; use PodPoint\SnsBroadcaster\Tests\Dummies\Events\UserRetrieved; -use PodPoint\SnsBroadcaster\Tests\Dummies\Events\UserRetrievedWithBroadcastWith; +use PodPoint\SnsBroadcaster\Tests\Dummies\Events\UserRetrievedWithCustomPayload; use PodPoint\SnsBroadcaster\Tests\Dummies\Models\User; use PodPoint\SnsBroadcaster\Tests\TestCase; @@ -63,6 +63,6 @@ public function test_broadcasts_custom_event_with_custom_payload() && $message['data']['foo'] == 'baz'; })); - event(new UserRetrievedWithBroadcastWith($user)); + event(new UserRetrievedWithCustomPayload($user)); } } diff --git a/tests/Unit/ModelEventsTest.php b/tests/Unit/ModelEventsTest.php index 3cbd1b5..255f67f 100644 --- a/tests/Unit/ModelEventsTest.php +++ b/tests/Unit/ModelEventsTest.php @@ -5,9 +5,9 @@ use Aws\Sns\SnsClient; use Mockery; use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEvents; -use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithBroadcastEvents; -use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithBroadcastWith; -use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents; +use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsForSpecificEvents; +use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithCustomPayload; +use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents; use PodPoint\SnsBroadcaster\Tests\TestCase; class ModelEventsTest extends TestCase @@ -60,7 +60,7 @@ public function test_broadcasts_model_event_with_custom_payload() && $message['data']['foo'] == 'bar'; })); - UserWithBroadcastingEventsWithBroadcastWith::create($userData); + UserWithBroadcastingEventsWithCustomPayload::create($userData); } /** @test */ @@ -70,7 +70,7 @@ public function test_broadcasts_model_event_with_specified_event() $this->app->instance(SnsClient::class, $mocked); - $user = UserWithBroadcastingEventsWithBroadcastEvents::create([ + $user = UserWithBroadcastingEventsForSpecificEvents::create([ 'name' => 'Foo Bar', 'email' => 'model-event-3@email.com', 'password' => 'password', @@ -96,7 +96,7 @@ public function test_does_not_broadcast_model_event_without_specified_event() $mocked->shouldNotHaveReceived('publish'); - $user = UserWithBroadcastingEventsWithBroadcastEvents::create([ + $user = UserWithBroadcastingEventsForSpecificEvents::create([ 'name' => 'Foo Bar', 'email' => 'model-event-4@email.com', 'password' => 'password', @@ -112,7 +112,7 @@ public function test_broadcasts_model_event_with_specified_event_and_custom_payl $this->app->instance(SnsClient::class, $mocked); - $user = UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents::create([ + $user = UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents::create([ 'name' => 'Foo Bar', 'email' => 'model-event-5@email.com', 'password' => 'password',