Skip to content

Commit

Permalink
Upgrade Laravel (#2)
Browse files Browse the repository at this point in the history
* switch to github actions

* upgrade phpunit

* remove testbench dependency

* install and apply php-cs-fixer

* use anonymous class in SendGridChannelTest

* update readme

* update composer.json
  • Loading branch information
aozisik committed Apr 7, 2022
1 parent 07bb7e8 commit 97bc67e
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 109 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: run-tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
# Disable testing on windows for now...
# os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
php: [7.4, 8.0, 8.1]
laravel: [7.*, 8.*, 9.*]
#stability: [prefer-lowest, prefer-stable]
stability: [prefer-stable]
include:
- laravel: 7.*
- laravel: 8.*
- laravel: 9.*
# Laravel 7 has no support for PHP 8.1
exclude:
- laravel: 7.*
php: 8.1
# Older versions of L7 doesn't support PHP 8
- laravel: 7.*
php: 8
stability: prefer-lowest
# Laravel 9 doesn't support < PHP 8
- laravel: 9.*
php: 7.4

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.phar
composer.lock
.DS_Store
.phpunit.result.cache
.php-cs-fixer.cache
43 changes: 43 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('vendor')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

$config = new PhpCsFixer\Config();

return $config->setRules([

'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'length'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
21 changes: 0 additions & 21 deletions .scrutinizer.yml

This file was deleted.

1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes will be documented in this file

## 2.0.0 - 2022-04-07

- Added support for Laravel 8 and 9.

## 1.0.1 - 2020-08-11

- stable release for Laravel 5, 6 and 7.

## 0.0.4 - 2020-08-11

- initial release
59 changes: 37 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Total Downloads](https://img.shields.io/packagist/dt/swiftmade/laravel-sendgrid-notification-channel.svg?style=flat-square)](https://packagist.org/packages/swiftmade/laravel-sendgrid-notification-channel)

This package makes it easy to send notifications using [SendGrid](https://sendgrid.com) Dynamic Emails API with Laravel 5.5+, 6.x and 7.x
Allows you to send Laravel notifications using Sendgrid's [Dynamic Transactional Templates](https://docs.sendgrid.com/ui/sending-email/how-to-send-an-email-with-dynamic-transactional-templates) feature. Supports Laravel 7.x, 8.x and 9.x.

## Contents
(For older versions of Laravel, install v1)

- [Installation](#installation)
- [Usage](#usage)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)
## Contents

- [Installation](#installation)
- [Usage](#usage)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

## Installation

Expand All @@ -24,19 +25,34 @@ To get started, you need to require this package:
composer require swiftmade/laravel-sendgrid-notification-channel
```

The service provider will be auto-detected by Laravel. So, no need to register it manually.
The service provider will be auto-detected by Laravel. If you've turned auto-discovery off, add the following service provider in your `config/app.php`.

```
NotificationChannels\SendGrid\SendGridServiceProvider::class,
```

Next, make sure you have a valid sendgrid api key at `config/services.php`. You may copy the example configuration below to get started:
Next, make sure you have a valid Sendgrid API key in `config/services.php`. You may copy the example configuration below to get started:

```php
return [

// other services...

// add this...
'sendgrid' => [
'api_key' => env('SENDGRID_API_KEY'),
],
];
```

## Usage

To make use of this package, your notification class should look like this:
To send an email using dynamic templates, you need to:

1. Return `SendGridChannel::class` in the `via()` method. (Not `mail`)
2. Add and implement the `toSendGrid($notifiable){ }` method.

Example:

```php
<?php
Expand All @@ -55,7 +71,7 @@ class ExampleNotification extends Notification
// And any other channels you want can go here...
];
}

// ...

public function toSendGrid($notifiable)
Expand All @@ -67,7 +83,7 @@ class ExampleNotification extends Notification
* ->from('no-reply@test.com', 'App name')
*/
/**
* optionally set the recipient.
* optionally set the recipient.
* by default it's $notifiable->email:
* ->to('hello@example.com', 'Mr. Smith')
*/
Expand All @@ -79,18 +95,17 @@ class ExampleNotification extends Notification

```

`toSendGrid` method will receive a `$notifiable` entity and should return a `NotificationChannels\SendGrid\SendGridMessage` instance.

💡 Unless you set them explicitly, **From** address will be `config('mail.from.address')` and the **To** value will be what returns from `$notifiable->routeNotificationFor('mail');`
`toSendGrid` method will receive a `$notifiable` entity and should return a `NotificationChannels\SendGrid\SendGridMessage` instance.

💡 Unless you set it explicitly, the **From** address will be set to `config('mail.from.address')` and the **To** value will be what returns from `$notifiable->routeNotificationFor('mail');`

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Testing

``` bash
```bash
$ composer test
```

Expand All @@ -104,9 +119,9 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Credits

- [swiftmade](https://github.com/swiftmade)
- [cuonggt](https://github.com/cuonggt/sendgrid)
- [All Contributors](../../contributors)
- [swiftmade](https://github.com/swiftmade)
- [cuonggt](https://github.com/cuonggt/sendgrid)
- [All Contributors](../../contributors)

## License

Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
],
"require": {
"php": ">=7.2",
"illuminate/notifications": "~5.5 || ~6.0 || ~7.0",
"illuminate/support": "~5.5 || ~6.0 || ~7.0",
"sendgrid/sendgrid": "^7.8"
"illuminate/notifications": "^7.0|^8.0|^9.0",
"illuminate/support": "^7.0|^8.0|^9.0",
"sendgrid/sendgrid": "^7.11"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.8",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^8.4|^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -45,4 +46,4 @@
]
}
}
}
}
7 changes: 0 additions & 7 deletions phpunit.xml.dist → phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion src/SendGridChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace NotificationChannels\SendGrid;

use SendGrid;
use Exception;
use Illuminate\Notifications\Notification;
use NotificationChannels\SendGrid\Exceptions\CouldNotSendNotification;
use SendGrid;

class SendGridChannel
{
Expand Down
2 changes: 1 addition & 1 deletion src/SendGridMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace NotificationChannels\SendGrid;

use SendGrid\Mail\To;
use SendGrid\Mail\From;
use SendGrid\Mail\Mail;
use SendGrid\Mail\ReplyTo;
use SendGrid\Mail\To;

class SendGridMessage
{
Expand Down
3 changes: 1 addition & 2 deletions src/SendGridServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace NotificationChannels\SendGrid;

use Illuminate\Notifications\Notification;
use Illuminate\Support\ServiceProvider;
use SendGrid;
use Illuminate\Support\ServiceProvider;

class SendGridServiceProvider extends ServiceProvider
{
Expand Down
Loading

0 comments on commit 97bc67e

Please sign in to comment.