Skip to content

Commit e327a73

Browse files
authored
Merge pull request #10 from laravel-notification-channels/dev
Add PHP 8.0, 8.1 support; Improve error logging with additional metadata
2 parents 42e0bac + 395f266 commit e327a73

File tree

11 files changed

+133
-33
lines changed

11 files changed

+133
-33
lines changed

.github/workflows/coverage.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Unit test coverage
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
tests:
9+
runs-on: ubuntu-latest
10+
name: Unit test coverage
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: 7.4
20+
tools: composer:v2
21+
coverage: pcov
22+
23+
- name: Install dependencies
24+
run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
25+
26+
- name: Execute tests
27+
run: vendor/bin/phpunit --verbose --coverage-text --coverage-clover=coverage.clover
28+
29+
- name: Send coverage to Scrutinizer
30+
run: |
31+
wget https://scrutinizer-ci.com/ocular.phar
32+
php ocular.phar code-coverage:upload --format=php-clover coverage.clover

.github/workflows/tests.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: PHPUnit tests
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
tests:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: true
12+
matrix:
13+
php: [7.2, 7.3, 7.4, 8.0, 8.1]
14+
15+
name: Tests on PHP ${{ matrix.php }} - ${{ matrix.stability }}
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
- name: Setup PHP
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: ${{ matrix.php }}
25+
tools: composer:v2
26+
coverage: none
27+
28+
- name: Install dependencies
29+
run: composer update --prefer-source --no-interaction --no-progress
30+
31+
- name: Execute tests
32+
run: vendor/bin/phpunit --verbose

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Changelog
22

3-
All notable changes to the `InterFAX notification channel` will be documented in this file
3+
All notable changes to the `InterFAX notification channel` will be documented in this file.
4+
5+
## 2.1.1 - 2021-05-12
6+
7+
- Prevent API limit requests with updates to status polling
8+
- Update exception handling for better error messages from InterFAX client
9+
10+
## 2.1.0 - 2020-11-10
11+
12+
- Add Laravel 8 support
413

514
## 2.0.0 - 2020-07-15
615

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function routeNotificationForInterfax($notification)
110110
`file(string $file)` : Accepts the full path to a single file (full list of supported file types [found here](https://www.interfax.net/en/help/supported_file_types)).
111111
`files(array $array)` : Accepts an array of file paths.
112112
`stream(Filestream $stream, string $name)` : Accepts a file stream.
113+
`addMetadata(array $data)`: Add metadata for logging purposes in case of an error.
113114

114115
## Changelog
115116

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^7.2",
15+
"php": "^7.2|^8.0",
1616
"illuminate/notifications": "^6.0|^7.0|^8.0",
1717
"illuminate/support": "^6.0|^7.0|^8.0",
1818
"interfax/interfax": "^1.1"

src/Exceptions/CouldNotSendNotification.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public function getUser()
2828
return $this->interfaxMessage->user;
2929
}
3030

31+
public function getMetadata()
32+
{
33+
return $this->interfaxMessage->metadata;
34+
}
35+
3136
public function getAttributes()
3237
{
3338
return $this->responseAttributes;

src/InterfaxChannel.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class InterfaxChannel
1010
{
1111
protected $client;
12+
protected $fax;
1213

1314
public function __construct(Client $client)
1415
{
@@ -18,8 +19,8 @@ public function __construct(Client $client)
1819
/**
1920
* Send the given notification.
2021
*
21-
* @param mixed $notifiable
22-
* @param \Illuminate\Notifications\Notification $notification
22+
* @param mixed $notifiable
23+
* @param \Illuminate\Notifications\Notification $notification
2324
*
2425
* @throws \NotificationChannels\Interfax\Exceptions\CouldNotSendNotification
2526
*/
@@ -32,25 +33,27 @@ public function send($notifiable, Notification $notification)
3233
$message = $notification->toInterfax($notifiable);
3334

3435
try {
35-
$fax = $this->client->deliver([
36+
$this->fax = $this->client->deliver([
3637
'faxNumber' => $faxNumber,
3738
'files' => $message->makeFiles(),
3839
]);
3940

4041
if ($message->shouldCheckStatus()) {
4142
$message->sleep();
4243

43-
while ($fax->refresh()->status < 0) {
44+
while ($this->fax->refresh()->status < 0) {
4445
$message->sleep();
4546
}
4647

47-
if ($fax->refresh()->status > 0) {
48-
throw CouldNotSendNotification::serviceRespondedWithAnError($message, $fax->refresh()->attributes());
48+
if ($this->fax->refresh()->status > 0) {
49+
throw CouldNotSendNotification::serviceRespondedWithAnError($message, $this->fax->attributes());
4950
}
5051
}
5152
} catch (\Interfax\Exception\RequestException $e) {
5253
$exceptionMessage = $e->getMessage().': '.($e->getWrappedException())->getMessage();
53-
throw CouldNotSendNotification::serviceRespondedWithAnError($message, $fax->refresh()->attributes(), $exceptionMessage);
54+
$attributes = $this->fax ? $this->fax->attributes() : ['status' => $e->getStatusCode()];
55+
56+
throw CouldNotSendNotification::serviceRespondedWithAnError($message, $attributes, $exceptionMessage);
5457
}
5558
}
5659
}

src/InterfaxMessage.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class InterfaxMessage
1212
protected $method;
1313
protected $statusCheck = false;
1414
public $user;
15+
public $metadata = [];
1516

1617
const FILES = 'files';
1718
const STREAM = 'stream';
@@ -58,7 +59,8 @@ public function shouldCheckStatus(): bool
5859

5960
/**
6061
* Set a user who can be notified in case the fax fails to send.
61-
* @param mixed $notifiable [description]
62+
*
63+
* @param mixed $notifiable The user to notify
6264
* @return InterfaxMessage
6365
*/
6466
public function user($notifiable)
@@ -68,6 +70,21 @@ public function user($notifiable)
6870
return $this;
6971
}
7072

73+
/**
74+
* Add metadata to the message for logging purposes.
75+
*
76+
* @param array $data The data to add to the metadata array
77+
* @return InterfaxMessage
78+
*/
79+
public function addMetadata(array $data)
80+
{
81+
foreach ($data as $key => $value) {
82+
$this->metadata[$key] = $value;
83+
}
84+
85+
return $this;
86+
}
87+
7188
public function makeFiles(): array
7289
{
7390
if ($this->method === static::STREAM) {

tests/CouldNotSendNotificationExceptionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function setUp(): void
1313
{
1414
parent::setUp();
1515
$this->message = (new InterfaxMessage)
16+
->addMetadata(['key' => 'Some sample metadata.'])
1617
->checkStatus()
1718
->user(new TestNotifiable)
1819
->file('test-file.pdf');
@@ -29,6 +30,17 @@ public function it_can_get_the_exception_user()
2930
$this->assertInstanceOf(TestNotifiable::class, $exception->getUser());
3031
}
3132

33+
/** @test */
34+
public function it_can_get_the_exception_metadata()
35+
{
36+
$exception = CouldNotSendNotification::serviceRespondedWithAnError($this->message, [
37+
'status' => 500,
38+
'message' => 'Failed to send.',
39+
]);
40+
41+
$this->assertSame('Some sample metadata.', $exception->getMetadata()['key']);
42+
}
43+
3244
/** @test */
3345
public function it_can_get_the_default_exception_message()
3446
{

0 commit comments

Comments
 (0)